first commit
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
using System.Xml.Linq;
|
||||
using CRIF.ACTion.Common.Builders;
|
||||
using CRIF.ACTion.Common;
|
||||
using CRIF.ACTion.Configuration;
|
||||
using Landmark.OLA.Models.Loan;
|
||||
|
||||
namespace CRIF.ACTion.Files
|
||||
{
|
||||
public class AddAppFilesSection : CrifRequestSection
|
||||
{
|
||||
public AddAppFilesSection(CrifSettings settings) : base(CrifNamespaces.Empty, "addAppFiles", settings)
|
||||
{}
|
||||
|
||||
public virtual void SetLoanId(string loanId)
|
||||
{
|
||||
AddAttribute(new XAttribute("applicationID", loanId));
|
||||
}
|
||||
|
||||
public virtual void SetFile(LoanApplicationFile file, string fileBase64Value)
|
||||
{
|
||||
XAttribute description;
|
||||
|
||||
if (file.Section?.Length > 0) {
|
||||
description = new XAttribute(CrifNamespaces.Common + "description", $"{file.Section} - {file.SectionId}: {file.Description}");
|
||||
} else {
|
||||
description = new XAttribute(CrifNamespaces.Common + "description", $"{file.SectionId}: {file.Description}");
|
||||
}
|
||||
|
||||
var addAppFilesElement = new XElement(CrifNamespaces.Common + "file",
|
||||
new XAttribute(CrifNamespaces.Common + "id", file.FileId),
|
||||
new XAttribute(CrifNamespaces.Common + "name", file.Name),
|
||||
description,
|
||||
new XAttribute(CrifNamespaces.Common + "size", CalculateFileSize(fileBase64Value)));
|
||||
|
||||
addAppFilesElement.Add(new XElement(CrifNamespaces.Common + "formatType", new XAttribute(CrifNamespaces.Common + "CD", GetFormatType())));
|
||||
|
||||
addAppFilesElement.Add(new XElement(CrifNamespaces.Common + "formatCategory", new XAttribute(CrifNamespaces.Common + "CD", GetFormatCategory(file.Description))));
|
||||
|
||||
var fileElement = new XElement(CrifNamespaces.Common + "file");
|
||||
fileElement.SetValue(fileBase64Value);
|
||||
|
||||
addAppFilesElement.Add(fileElement);
|
||||
|
||||
AddContent(addAppFilesElement);
|
||||
}
|
||||
|
||||
public static string CalculateFileSize(string fileBase64Value)
|
||||
{
|
||||
int size = fileBase64Value.Length / 4 * 3;
|
||||
|
||||
if (fileBase64Value.EndsWith("=="))
|
||||
{
|
||||
size -= 2;
|
||||
}
|
||||
else if (fileBase64Value.EndsWith("="))
|
||||
{
|
||||
size -= 1;
|
||||
}
|
||||
|
||||
return size.ToString();
|
||||
}
|
||||
|
||||
public int GetFormatType()
|
||||
{
|
||||
// Always return 1 since it seems that there are no other types used. Creating this in case that ever changes.
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Configurable in appsettings.json, defaults to 1
|
||||
public int GetFormatCategory(string description)
|
||||
{
|
||||
try
|
||||
{
|
||||
var category = _settings.FormatCategoryMappings.DocumentToCategory.GetValueOrDefault(description, "Attachment");
|
||||
return _settings.FormatCategoryMappings.Categories.GetValueOrDefault(category, 1);
|
||||
} catch (Exception)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user