public string GenerateContents(PublishedFundingVersion publishedFundingVersion, TemplateMetadataContents templateMetadataContents) { Guard.ArgumentNotNull(publishedFundingVersion, nameof(publishedFundingVersion)); Guard.ArgumentNotNull(templateMetadataContents, nameof(templateMetadataContents)); SchemaJson contents = new SchemaJson { Schema = "https://fundingschemas.blob.core.windows.net/schemas/logicalmodel-1.0.json#schema", SchemaVersion = publishedFundingVersion.SchemaVersion, Funding = new { publishedFundingVersion.TemplateVersion, Id = publishedFundingVersion.FundingId, FundingVersion = $"{publishedFundingVersion.MajorVersion}_{publishedFundingVersion.MinorVersion}", Status = publishedFundingVersion.Status.ToString(), FundingStream = new { Code = publishedFundingVersion.FundingStreamId, Name = publishedFundingVersion.FundingStreamName }, FundingPeriod = new { publishedFundingVersion.FundingPeriod.Id, publishedFundingVersion.FundingPeriod.Period, publishedFundingVersion.FundingPeriod.Name, Type = publishedFundingVersion.FundingPeriod.Type.ToString(), publishedFundingVersion.FundingPeriod.StartDate, publishedFundingVersion.FundingPeriod.EndDate }, OrganisationGroup = new { GroupTypeCode = publishedFundingVersion.OrganisationGroupTypeCode, GroupTypeIdentifier = publishedFundingVersion.OrganisationGroupTypeIdentifier, IdentifierValue = publishedFundingVersion.OrganisationGroupIdentifierValue, GroupTypeClassification = publishedFundingVersion.OrganisationGroupTypeClassification, Name = publishedFundingVersion.OrganisationGroupName, SearchableName = publishedFundingVersion.OrganisationGroupSearchableName, Identifiers = publishedFundingVersion.OrganisationGroupIdentifiers?.Select(groupTypeIdentifier => new { groupTypeIdentifier.Type, groupTypeIdentifier.Value }).ToArray() }, FundingValue = new { TotalValue = publishedFundingVersion.TotalFunding, FundingLines = templateMetadataContents.RootFundingLines?.Select(_ => BuildSchemaJsonFundingLines(publishedFundingVersion.ReferenceData, publishedFundingVersion.Calculations, publishedFundingVersion.FundingLines, _, publishedFundingVersion.OrganisationGroupTypeIdentifier, publishedFundingVersion.OrganisationGroupIdentifierValue)) }, ProviderFundings = publishedFundingVersion.ProviderFundings?.ToArray(), publishedFundingVersion.GroupingReason, publishedFundingVersion.StatusChangedDate, publishedFundingVersion.ExternalPublicationDate, publishedFundingVersion.EarliestPaymentAvailableDate, VariationReasons = publishedFundingVersion.VariationReasons?.ToArray() } }; return(contents.AsJson()); }
public string GenerateContents(PublishedFundingVersion publishedFundingVersion, TemplateMetadataContents templateMetadataContents) { Guard.ArgumentNotNull(publishedFundingVersion, nameof(publishedFundingVersion)); Guard.ArgumentNotNull(templateMetadataContents, nameof(templateMetadataContents)); IEnumerable <TemplateFundingLine> fundingLines = templateMetadataContents.RootFundingLines?.Flatten(x => x.FundingLines); IEnumerable <Calculation> calculations = fundingLines?.SelectMany(fl => fl.Calculations.Flatten(cal => cal.Calculations)); SchemaJson contents = new SchemaJson { Schema = "https://fundingschemas.blob.core.windows.net/schemas/logicalmodel-1.1.json#schema", SchemaVersion = publishedFundingVersion.SchemaVersion, Funding = new { publishedFundingVersion.TemplateVersion, Id = publishedFundingVersion.FundingId, FundingVersion = $"{publishedFundingVersion.MajorVersion}_{publishedFundingVersion.MinorVersion}", Status = publishedFundingVersion.Status.ToString(), FundingStream = new { Code = publishedFundingVersion.FundingStreamId, Name = publishedFundingVersion.FundingStreamName }, FundingPeriod = new { publishedFundingVersion.FundingPeriod.Id, publishedFundingVersion.FundingPeriod.Period, publishedFundingVersion.FundingPeriod.Name, Type = publishedFundingVersion.FundingPeriod.Type.ToString(), publishedFundingVersion.FundingPeriod.StartDate, publishedFundingVersion.FundingPeriod.EndDate }, OrganisationGroup = new { GroupTypeCode = publishedFundingVersion.OrganisationGroupTypeCode, GroupTypeClassification = publishedFundingVersion.OrganisationGroupTypeClassification, Name = publishedFundingVersion.OrganisationGroupName, SearchableName = publishedFundingVersion.OrganisationGroupSearchableName, GroupTypeIdentifier = new { Type = publishedFundingVersion.OrganisationGroupTypeIdentifier, Value = publishedFundingVersion.OrganisationGroupIdentifierValue }, Identifiers = publishedFundingVersion.OrganisationGroupIdentifiers?.Select(groupIdentifier => new { groupIdentifier.Type, groupIdentifier.Value }).ToArray() }, FundingValue = new { TotalValue = publishedFundingVersion.TotalFunding, FundingLines = fundingLines?.DistinctBy(x => x.TemplateLineId).Select(rootFundingLine => BuildSchemaJsonFundingLines(publishedFundingVersion.FundingLines, rootFundingLine)).ToDictionary(_ => _.TemplateLineId), Calculations = calculations?.DistinctBy(x => x.TemplateCalculationId).Where(IsAggregationOrHasChildCalculations).Select(calculation => BuildSchemaJsonCalculations(publishedFundingVersion.Calculations, calculation, publishedFundingVersion.OrganisationGroupTypeIdentifier, publishedFundingVersion.OrganisationGroupIdentifierValue)).Where(_ => _ != null).ToDictionary(_ => _.TemplateCalculationId) }, ProviderFundings = publishedFundingVersion.ProviderFundings.ToArray(), publishedFundingVersion.GroupingReason, publishedFundingVersion.StatusChangedDate, publishedFundingVersion.ExternalPublicationDate, publishedFundingVersion.EarliestPaymentAvailableDate } }; return(contents.AsJson()); }