public async Task SavePublishedFundingContents(IEnumerable <PublishedFundingVersion> publishedFundingToSave, TemplateMetadataContents templateMetadataContents)
        {
            IPublishedFundingContentsGenerator generator = _publishedFundingContentsGeneratorResolver.GetService(templateMetadataContents.SchemaVersion);

            List <Task>   allTasks  = new List <Task>();
            SemaphoreSlim throttler = new SemaphoreSlim(initialCount: _publishingEngineOptions.SavePublishedFundingContentsConcurrencyCount);

            foreach (PublishedFundingVersion publishedFundingVersion in publishedFundingToSave)
            {
                await throttler.WaitAsync();

                allTasks.Add(
                    Task.Run(async() =>
                {
                    try
                    {
                        string contents = generator.GenerateContents(publishedFundingVersion, templateMetadataContents);

                        if (string.IsNullOrWhiteSpace(contents))
                        {
                            throw new RetriableException($"Generator failed to generate content for published provider version with id: '{publishedFundingVersion.Id}'");
                        }

                        string blobName = GetBlobName(publishedFundingVersion);
                        await _publishedFundingRepositoryPolicy.ExecuteAsync(() =>
                                                                             UploadBlob(GetBlobName(publishedFundingVersion), contents, GetMetadata(publishedFundingVersion)));
                    }
                    finally
                    {
                        throttler.Release();
                    }
                }));
            }
            await TaskHelper.WhenAllAndThrow(allTasks.ToArray());
        }
Example #2
0
        public async Task <int> Generate(FeedOptions options)
        {
            IEnumerable <Provider> records = GetRecords(options.InputFilePath);

            foreach (Provider provider in records)
            {
                PublishedProviderVersion publishedProviderVersion = GetPublishedProviderVersion(provider);
                Common.TemplateMetadata.Models.TemplateMetadataContents templateMetadataContents = GetProviderTemplateMetadataContents();
                TemplateMapping         templateMapping         = GetTemplateMapping();
                GeneratedProviderResult generatedProviderResult = GetGeneratedProviderResult(provider);

                string generatedProviderDocumentContent = _publishedProviderContentsGenerator.GenerateContents(publishedProviderVersion, templateMetadataContents, templateMapping);
                PublishProviderDocument(options, publishedProviderVersion, generatedProviderDocumentContent);
            }

            int fundingIndex = 0;

            foreach (IGrouping <(string, string, string), Provider> groupingKey in records.GroupBy(provider => (provider.LACode, provider.MajorVersionNo, provider.AllocationID)))
            {
                OrganisationGroupLookupParameters organisationGroupLookupParameters = new OrganisationGroupLookupParameters
                {
                    OrganisationGroupTypeCode = GetOrganisationGroupTypeCode(groupingKey.Key.Item3),
                    IdentifierValue           = groupingKey.Key.Item1,
                    GroupTypeIdentifier       = CalculateFunding.Common.ApiClient.Policies.Models.OrganisationGroupTypeIdentifier.LACode,
                    ProviderVersionId         = options.ProviderVersion
                };
                IEnumerable <ProviderApiClient> apiClientProviders      = GetApiClientProviders(groupingKey);
                TargetOrganisationGroup         targetOrganisationGroup = null;

                try
                {
                    targetOrganisationGroup = await organisationGroupTargetProviderLookup.GetTargetProviderDetails(organisationGroupLookupParameters, Common.ApiClient.Policies.Models.GroupingReason.Payment, apiClientProviders);
                }
                catch (Exception ex)
                {
                    string message = $"Could not find provider with ID:{organisationGroupLookupParameters.IdentifierValue} with error message {ex}";
                    _logger.Error(message);
                    Console.WriteLine(message);

                    continue;
                }

                PublishedFundingVersion publishedFundingVersion = GetPublishedFundingVersion(groupingKey, targetOrganisationGroup, fundingIndex);
                Common.TemplateMetadata.Models.TemplateMetadataContents templateMetadataContents = GetFundingTemplateMetadataContents();
                string generatedFundingDocumentContent = _publishedFundingContentsGenerator.GenerateContents(publishedFundingVersion, templateMetadataContents);

                PublishFundingDocument(options, publishedFundingVersion, generatedFundingDocumentContent);

                fundingIndex++;
            }

            _logger.Information("NAV Data generation completed.");

            return(1);
        }
Example #3
0
        public async Task <int> Generate(FeedOptions options)
        {
            IEnumerable <Provider> records = GetRecords(options.InputFilePath);

            foreach (Provider provider in records)
            {
                PublishedProviderVersion publishedProviderVersion = GetPublishedProviderVersion(provider);
                Common.TemplateMetadata.Models.TemplateMetadataContents templateMetadataContents = GetProviderTemplateMetadataContents();
                TemplateMapping         templateMapping         = GetTemplateMapping();
                GeneratedProviderResult generatedProviderResult = GetGeneratedProviderResult(provider);

                string generatedProviderDocumentContent = _publishedProviderContentsGenerator.GenerateContents(publishedProviderVersion, templateMetadataContents, templateMapping);
                PublishProviderDocument(options, publishedProviderVersion, generatedProviderDocumentContent);
            }

            int fundingIndex = 0;

            foreach (IGrouping <string, Provider> laGroup in records.GroupBy(x => x.ProviderLaCode))
            {
                OrganisationGroupLookupParameters organisationGroupLookupParameters = new OrganisationGroupLookupParameters
                {
                    OrganisationGroupTypeCode = Common.ApiClient.Policies.Models.OrganisationGroupTypeCode.LocalAuthority,
                    IdentifierValue           = laGroup.Key,
                    GroupTypeIdentifier       = Common.ApiClient.Policies.Models.OrganisationGroupTypeIdentifier.LACode,
                    ProviderVersionId         = options.ProviderVersion
                };
                IEnumerable <ProviderApiClient> apiClientProviders      = GetApiClientProviders(laGroup);
                TargetOrganisationGroup         targetOrganisationGroup = await organisationGroupTargetProviderLookup.GetTargetProviderDetails(organisationGroupLookupParameters, Common.ApiClient.Policies.Models.GroupingReason.Payment, apiClientProviders);

                PublishedFundingVersion publishedFundingVersion = GetPublishedFundingVersion(laGroup, targetOrganisationGroup, fundingIndex);
                Common.TemplateMetadata.Models.TemplateMetadataContents templateMetadataContents = GetFundingTemplateMetadataContents();
                string generatedFundingDocumentContent = _publishedFundingContentsGenerator.GenerateContents(publishedFundingVersion, templateMetadataContents);

                PublishFundingDocument(options, publishedFundingVersion, generatedFundingDocumentContent);

                fundingIndex++;
            }

            _logger.Information("NAV Data generation completed.");

            return(1);
        }
Example #4
0
 private void GivenTheGeneratedContentsIsReturned()
 {
     _publishedFundingContentsGenerator.GenerateContents(_publishedFundingVersion, _templateMetadataContents)
     .Returns("template1");
 }