Esempio n. 1
0
        private async Task <IDictionary <string, PublishedProvider> > GetPublishedProvidersForFundingStream(
            Reference fundingStream, SpecificationSummary specification)
        {
            _logger.Information($"Retrieving published provider results for {fundingStream.Id} in specification {specification.Id}");

            IEnumerable <PublishedProvider> publishedProvidersResult =
                await _publishedFundingDataService.GetCurrentPublishedProviders(fundingStream.Id, specification.FundingPeriod.Id);

            // Ensure linq query evaluates only once
            Dictionary <string, PublishedProvider> publishedProvidersForFundingStream = publishedProvidersResult.ToDictionary(_ => _.Current.ProviderId);

            _logger.Information($"Retrieved {publishedProvidersForFundingStream.Count} published provider results for {fundingStream.Id}");


            if (publishedProvidersForFundingStream.IsNullOrEmpty())
            {
                throw new RetriableException($"Null or empty published providers returned for specification id : '{specification.Id}' when setting status to released");
            }

            return(publishedProvidersForFundingStream);
        }
        public async Task <IActionResult> GetLatestPublishedProvidersForSpecificationId(string specificationId)
        {
            ValidationResult validationResults = _validator.Validate(specificationId);

            if (!validationResults.IsValid)
            {
                return(validationResults.AsBadRequest());
            }

            SpecificationSummary specificationSummary = await _specificationService.GetSpecificationSummaryById(specificationId);

            List <PublishedProviderVersion> results = new List <PublishedProviderVersion>();

            foreach (var fundingStream in specificationSummary.FundingStreams)
            {
                IEnumerable <PublishedProvider> publishedProviders = await _resiliencePolicy.ExecuteAsync(() =>
                                                                                                          _publishedFunding.GetCurrentPublishedProviders(fundingStream.Id, specificationSummary.FundingPeriod.Id));

                if (publishedProviders.AnyWithNullCheck())
                {
                    results.AddRange(publishedProviders.Select(_ => _.Current));
                }
            }

            return(new OkObjectResult(results));
        }
 private void GivenThePublishedProvidersForTheSpecificationId(params PublishedProvider[] publishedProviders)
 {
     _publishedFunding.GetCurrentPublishedProviders(_fundingStreamId, _fundingPeriodId)
     .Returns(publishedProviders);
 }
Esempio n. 4
0
        public override async Task Process(Message message)
        {
            Guard.ArgumentNotNull(message, nameof(message));

            Reference author = message.GetUserDetails();

            string specificationId = message.UserProperties["specification-id"] as string;

            SpecificationSummary specification = await _specificationService.GetSpecificationSummaryById(specificationId);

            if (specification == null)
            {
                throw new NonRetriableException($"Could not find specification with id '{specificationId}'");
            }

            // Get scoped providers for this specification
            IDictionary <string, Provider> scopedProviders = await _providerService.GetScopedProvidersForSpecification(specification.Id, specification.ProviderVersionId);

            if (!scopedProviders.IsNullOrEmpty())
            {
                _logger.Information($"Found {scopedProviders.Count} scoped providers for refresh");
            }
            else
            {
                _logger.Information("No scoped providers found for refresh");
            }

            // Get existing published providers for this specification
            _logger.Information("Looking up existing published providers from cosmos for refresh job");

            IDictionary <string, List <PublishedProvider> > existingPublishedProvidersByFundingStream = new Dictionary <string, List <PublishedProvider> >();

            foreach (Reference fundingStream in specification.FundingStreams)
            {
                List <PublishedProvider> publishedProviders = (await _publishingResiliencePolicy.ExecuteAsync(() =>
                                                                                                              _publishedFundingDataService.GetCurrentPublishedProviders(fundingStream.Id, specification.FundingPeriod.Id))).ToList();

                existingPublishedProvidersByFundingStream.Add(fundingStream.Id, publishedProviders);
                _logger.Information($"Found {publishedProviders.Count} existing published providers for funding stream {fundingStream.Id} from cosmos for refresh job");
            }

            _logger.Information("Verifying prerequisites for funding refresh");

            // Check prerequisites for this specification to be chosen/refreshed
            IPrerequisiteChecker prerequisiteChecker = _prerequisiteCheckerLocator.GetPreReqChecker(PrerequisiteCheckerType.Refresh);

            try
            {
                await prerequisiteChecker.PerformChecks(specification, Job.Id, existingPublishedProvidersByFundingStream.SelectMany(x => x.Value), scopedProviders?.Values);
            }
            catch (JobPrereqFailedException ex)
            {
                throw new NonRetriableException(ex.Message, ex);
            }
            _logger.Information("Prerequisites for refresh passed");

            // Get calculation results for specification
            _logger.Information("Looking up calculation results");

            IDictionary <string, ProviderCalculationResult> allCalculationResults;

            try
            {
                allCalculationResults = await _calculationResultsService.GetCalculationResultsBySpecificationId(specificationId, scopedProviders.Keys);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "Exception during calculation result lookup");
                throw;
            }

            _logger.Information($"Found calculation results for {allCalculationResults?.Count} providers from cosmos for refresh job");

            string correlationId = message.GetUserProperty <string>(SfaCorrelationId);

            try
            {
                foreach (Reference fundingStream in specification.FundingStreams)
                {
                    _logger.Information($"Starting to refresh funding for '{fundingStream.Id}'");

                    await RefreshFundingStream(fundingStream,
                                               specification,
                                               scopedProviders,
                                               allCalculationResults,
                                               Job.Id,
                                               author,
                                               correlationId,
                                               existingPublishedProvidersByFundingStream[fundingStream.Id],
                                               specification.FundingPeriod.Id);

                    _logger.Information($"Finished processing refresh funding for '{fundingStream.Id}'");
                }
            }
            finally
            {
                _logger.Information("Starting to clear variation snapshots");
                _variationService.ClearSnapshots();
                _logger.Information("Finished clearing variation snapshots");
            }
        }
 private void AndPublishedProvidersForFundingStreamAndFundingPeriod(IEnumerable <PublishedProvider> publishedProviders)
 {
     _publishedFundingDataService.GetCurrentPublishedProviders(FundingStreamId, FundingPeriodId)
     .Returns(publishedProviders);
 }