private void CheckForPaymentNameLimitIssues(CustomContext context, SchemaJsonFundingLine fundingLine, string fundingLineName) { if (fundingLine.Type == FundingLineType.Payment) { if (fundingLineName.Length >= MaxAllowedPaymentFundingLineNameCharacterLimit) { AddFailure(context, "FundingLine", $"Funding Line '{fundingLine.Name}' with id '{fundingLine.TemplateLineId}' - Funding line name may not exceed 100 characters in length for payment type lines"); } } }
public static FundingLine ToFundingLine(this SchemaJsonFundingLine source) { return(new FundingLine { Name = source.Name, TemplateLineId = source.TemplateLineId, FundingLineCode = source.FundingLineCode, Type = source.Type.AsMatchingEnum <FundingLineType>(), Calculations = source.Calculations?.Select(ToCalculation), FundingLines = source.FundingLines?.Select(ToFundingLine) }); }
private void CheckForDuplicateNames(CustomContext context, SchemaJsonFundingLine fundingLine, string fundingLineName) { int nameUsages = _flattenedLines.Count(x => x.Name.Equals(fundingLineName, StringComparison.OrdinalIgnoreCase) && x.TemplateLineId != fundingLine.TemplateLineId); if (nameUsages > 1) { AddFailure(context, "FundingLine", $"Funding Line '{fundingLine.Name}' with id : '{fundingLine.TemplateLineId}' " + "has a duplicate funding line name in the template with a different templateLineIds."); } }
private void ValidateFundingLine(CustomContext context, SchemaJsonFundingLine fundingLine) { string fundingLineName = fundingLine.Name.Trim().ToLower(); CheckForDuplicateNames(context, fundingLine, fundingLineName); CheckForPaymentNameLimitIssues(context, fundingLine, fundingLineName); var fundingLineClones = _flattenedLines .Where(x => x.TemplateLineId == fundingLine.TemplateLineId && x.Id != fundingLine.Id); foreach (var clone in fundingLineClones) { if (!clone.FundingLines.IsNullOrEmpty() && !clone.FundingLines.All(cloneChild => fundingLine.FundingLines.Any(child => child.TemplateLineId == cloneChild.TemplateLineId))) { AddFailure(context, "FundingLine", $"Funding Line '{fundingLine.Name}' with id '{fundingLine.TemplateLineId}' has clone(s) with child funding lines which don't match."); } if (!clone.Calculations.IsNullOrEmpty() && !clone.Calculations.All(cloneChild => fundingLine.Calculations.Any(child => child.TemplateCalculationId == cloneChild.TemplateCalculationId))) { AddFailure(context, "FundingLine", $"Funding Line '{fundingLine.Name}' with id '{fundingLine.TemplateLineId}' has clone(s) with child calculations which don't match."); } if (clone.Name.Trim().ToLower() != fundingLineName || clone.Type != fundingLine.Type || clone.FundingLineCode != fundingLine.FundingLineCode) { AddFailure(context, "FundingLine", $"Funding Line '{fundingLine.Name}' with id '{fundingLine.TemplateLineId}' " + "has clone(s) with different values."); } } fundingLine.FundingLines?.ToList().ForEach(x => ValidateFundingLine(context, x)); fundingLine.Calculations?.ToList().ForEach(x => ValidateCalculation(context, x)); }