first commit
This commit is contained in:
+222
@@ -0,0 +1,222 @@
|
||||
using System.Xml.Linq;
|
||||
using Serilog;
|
||||
using CRIF.ACTion.Common;
|
||||
using CRIF.ACTion.Common.Parsers;
|
||||
|
||||
namespace CRIF.ACTion.Configuration
|
||||
{
|
||||
public class CustomFieldRequestResponseParser : IResponseParser<CustomFieldConfigs>
|
||||
{
|
||||
private const string _customFieldsPath = "/actionAPI/getCustomFields/msg:maintExportResponse/msg:maintenanceEntities/maint:maintenanceEntity/maint:fields/common:customLookupField";
|
||||
|
||||
public CustomFieldRequestResponseParser()
|
||||
{
|
||||
}
|
||||
|
||||
public CustomFieldConfigs Parse(XElement xElement)
|
||||
{
|
||||
CustomFieldConfigs customFieldConfig = new();
|
||||
|
||||
try
|
||||
{
|
||||
var namespaceManager = CrifNamespaces.GetNamespaceManager(xElement);
|
||||
IEnumerable<XElement> customFieldNodeList = xElement.XElementXPathSelectElements(_customFieldsPath, namespaceManager);
|
||||
List<string> RenovationMatchCriteria = ["IS THE PROPERTY CURRENTLY BEING REMODELED OR IMPROVED?"];
|
||||
List<string> SaleMatchCriteria = ["IS THE PROPERTY CURRENTLY LISTED FOR SALE?"];
|
||||
List<string> JointMatchCriteria = ["INTENT FOR JOINT CREDIT"];
|
||||
|
||||
customFieldConfig.CustomPropertyRenovationFieldData = ParseCustomPropertyStatusData(customFieldNodeList, RenovationMatchCriteria);
|
||||
customFieldConfig.CustomPropertySaleFieldData = ParseCustomPropertyStatusData(customFieldNodeList, SaleMatchCriteria);
|
||||
customFieldConfig.CustomJointCreditFieldData = ParseCustomJointCreditData(customFieldNodeList, JointMatchCriteria);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("Error trying to parse CRIF Custom Field Configuration Response", ex.Message, ex.StackTrace);
|
||||
}
|
||||
return customFieldConfig;
|
||||
}
|
||||
|
||||
private List<CustomJointCreditData> ParseCustomJointCreditData(IEnumerable<XElement> customFieldNodeList, List<string> MatchCriteria)
|
||||
{
|
||||
List<CustomJointCreditData> customDataSet = [];
|
||||
|
||||
foreach (XElement node in customFieldNodeList)
|
||||
{
|
||||
try
|
||||
{
|
||||
string nodeAttributeValue = node.Attribute(CrifNamespaces.Common + "name").Value;
|
||||
if (CustomFieldIsActive(nodeAttributeValue, MatchCriteria))
|
||||
{
|
||||
string individuallyId = "";
|
||||
string jointlyId = "";
|
||||
string productCategoryId = "";
|
||||
|
||||
IEnumerable<XElement> childNodes = node.Descendants().Elements();
|
||||
|
||||
foreach (XElement option in childNodes)
|
||||
{
|
||||
if (option.Name.LocalName.Equals("FIELDSELECTION", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
var attributes = option.Attributes();
|
||||
|
||||
foreach (var attribute in attributes)
|
||||
{
|
||||
string idValue = "";
|
||||
string nameValue = "";
|
||||
|
||||
if (attribute.Name.LocalName.Equals("FIELDSELECTIONID", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
idValue = attribute.Value;
|
||||
nameValue = attribute.NextAttribute.Value.ToUpper();
|
||||
|
||||
switch (nameValue)
|
||||
{
|
||||
case "INDIVIDUALLY":
|
||||
individuallyId = idValue;
|
||||
break;
|
||||
case "JOINTLY":
|
||||
jointlyId = idValue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (option.Name.LocalName.ToUpper() == "PRODUCTCATEGORY")
|
||||
{
|
||||
productCategoryId = option.LastAttribute.Value;
|
||||
}
|
||||
}
|
||||
|
||||
CustomJointCreditData data = new()
|
||||
{
|
||||
CustomFieldId = node.Attribute(CrifNamespaces.Common + "ID").Value,
|
||||
ProductCategoryId = productCategoryId,
|
||||
SortOrder = node.Attribute(CrifNamespaces.Common + "sortOrder").Value,
|
||||
JointlyId = jointlyId,
|
||||
IndividuallyId = individuallyId
|
||||
};
|
||||
|
||||
customDataSet.Add(data);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("Error trying to parse CRIF Custom Field Configuration Response", ex.Message, ex.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
return customDataSet;
|
||||
}
|
||||
|
||||
private List<CustomPropertyStatusData> ParseCustomPropertyStatusData(IEnumerable<XElement> customFieldNodeList, List<string> MatchCriteria)
|
||||
{
|
||||
List<CustomPropertyStatusData> customDataSet = [];
|
||||
|
||||
foreach (XElement node in customFieldNodeList)
|
||||
{
|
||||
try
|
||||
{
|
||||
string nodeAttributeValue = node.Attribute(CrifNamespaces.Common + "name").Value;
|
||||
if (CustomFieldIsActive(nodeAttributeValue, MatchCriteria))
|
||||
{
|
||||
string yesId = "";
|
||||
string noId = "";
|
||||
string naId = "";
|
||||
string productCategoryId = "";
|
||||
|
||||
IEnumerable<XElement> childNodes = node.Descendants().Elements();
|
||||
|
||||
foreach (XElement option in childNodes)
|
||||
{
|
||||
if (option.Name.LocalName.Equals("FIELDSELECTION", StringComparison.CurrentCultureIgnoreCase))
|
||||
{
|
||||
var attributes = option.Attributes();
|
||||
|
||||
foreach (var attribute in attributes)
|
||||
{
|
||||
string idValue = "";
|
||||
string nameValue = "";
|
||||
|
||||
if (attribute.Name.LocalName.ToUpper() == "FIELDSELECTIONID")
|
||||
{
|
||||
idValue = attribute.Value;
|
||||
nameValue = attribute.NextAttribute.Value.ToUpper();
|
||||
|
||||
switch (nameValue)
|
||||
{
|
||||
case "YES":
|
||||
yesId = idValue;
|
||||
break;
|
||||
case "NO":
|
||||
noId = idValue;
|
||||
break;
|
||||
case "N/A (FLEX FIXED DRAWS ONLY)":
|
||||
naId = idValue;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (option.Name.LocalName.ToUpper() == "PRODUCTCATEGORY")
|
||||
{
|
||||
productCategoryId = option.LastAttribute.Value;
|
||||
}
|
||||
}
|
||||
|
||||
CustomPropertyStatusData data = new CustomPropertyStatusData
|
||||
{
|
||||
CustomFieldId = node.Attribute(CrifNamespaces.Common + "ID").Value,
|
||||
ProductCategoryId = productCategoryId,
|
||||
SortOrder = node.Attribute(CrifNamespaces.Common + "sortOrder").Value,
|
||||
NoId = noId,
|
||||
YesId = yesId,
|
||||
NaId = naId
|
||||
};
|
||||
|
||||
customDataSet.Add(data);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Log.Error("Error trying to parse CRIF Custom Field Configuration Response", ex.Message, ex.StackTrace);
|
||||
}
|
||||
}
|
||||
|
||||
return customDataSet;
|
||||
}
|
||||
|
||||
private bool CustomFieldIsActive(string NodeAttributeValue, List<string> ActiveMatchCriteria)
|
||||
{
|
||||
bool isActive = false;
|
||||
foreach (string compare in ActiveMatchCriteria)
|
||||
{
|
||||
string standardizedNodeString = StandardizedStringValue(NodeAttributeValue);
|
||||
string standardizedCompareString = StandardizedStringValue(compare);
|
||||
|
||||
bool validCompareInput = !string.IsNullOrWhiteSpace(standardizedNodeString) && !string.IsNullOrWhiteSpace(compare);
|
||||
if (validCompareInput && !isActive)
|
||||
{
|
||||
isActive =
|
||||
(
|
||||
standardizedNodeString.Equals(standardizedCompareString)
|
||||
);
|
||||
}
|
||||
}
|
||||
return isActive;
|
||||
}
|
||||
|
||||
private string StandardizedStringValue(string InputString)
|
||||
{
|
||||
string standardizedString = "";
|
||||
if (!string.IsNullOrWhiteSpace(InputString))
|
||||
{
|
||||
standardizedString = InputString.Trim().ToUpper();
|
||||
}
|
||||
return standardizedString;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user