public async Task <IActionResult> CreateRefreshFundingJob(string specificationId,
                                                                  Reference user,
                                                                  string correlationId)
        {
            ValidationResult validationResult = SpecificationIdValidator.Validate(specificationId);

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

            ApiResponse <ApiSpecificationSummary> specificationIdResponse =
                await ResiliencePolicy.ExecuteAsync(() => Specifications.GetSpecificationSummaryById(specificationId));

            ApiSpecificationSummary specificationSummary = specificationIdResponse.Content;

            if (specificationSummary == null)
            {
                return(new NotFoundResult());
            }

            SpecificationFundingStatus chooseCheck = await _specificationFundingStatusService.CheckChooseForFundingStatus(specificationSummary);

            if (chooseCheck == SpecificationFundingStatus.SharesAlreadyChosenFundingStream)
            {
                return(new ConflictResult());
            }

            IDictionary <string, Provider> scopedProviders = await _providerService.GetScopedProvidersForSpecification(specificationSummary.Id, specificationSummary.ProviderVersionId);

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

            try
            {
                await prerequisiteChecker.PerformChecks(
                    specificationSummary,
                    null,
                    Array.Empty <PublishedProvider>(),
                    scopedProviders?.Values);
            }
            catch (JobPrereqFailedException ex)
            {
                return(new BadRequestObjectResult(new [] { $"Prerequisite check for refresh failed {ex.Message}" }.ToModelStateDictionary()));
            }

            ApiJob refreshFundingJob = await _refreshFundingJobs.CreateJob(specificationId, user, correlationId);

            Guard.ArgumentNotNull(refreshFundingJob, nameof(refreshFundingJob), "Failed to create RefreshFundingJob");

            JobCreationResponse jobCreationResponse = new JobCreationResponse()
            {
                JobId = refreshFundingJob.Id,
            };

            return(new OkObjectResult(jobCreationResponse));
        }
Beispiel #2
0
        public async Task <IActionResult> GetPublishedProviderErrorSummaries(string specificationId)
        {
            Guard.IsNullOrWhiteSpace(specificationId, nameof(specificationId));

            IEnumerable <string> errorSummaries = await ResiliencePolicy.ExecuteAsync(() =>
                                                                                      _publishedFundingRepository.GetPublishedProviderErrorSummaries(specificationId));

            return(new OkObjectResult(errorSummaries));
        }
Beispiel #3
0
        public Neo4JConnection(IOptions <Neo4JConfiguration> config, ResiliencePolicy resiliencePolicy)
        {
            this.resiliencePolicy = resiliencePolicy;
            var auth = Basic(config.Value.Username, config.Value.Password);

            try
            {
                this.driver = new Lazy <IDriver>(Driver(config.Value.Uri, auth));
            }
            catch (Exception exception)
            {
                LogError("Unable to connect to Neo4j.", new { config.Value.Uri }, HandleException(exception));
            }
        }
Beispiel #4
0
        public async Task <IActionResult> GetCurrentPublishedProviderVersion(string fundingStreamId,
                                                                             string providerId,
                                                                             string specificationId)
        {
            Guard.IsNullOrWhiteSpace(fundingStreamId, nameof(fundingStreamId));
            Guard.IsNullOrWhiteSpace(providerId, nameof(providerId));
            Guard.IsNullOrWhiteSpace(specificationId, nameof(specificationId));

            PublishedProviderVersion providerVersion = await ResiliencePolicy.ExecuteAsync(() =>
                                                                                           _publishedFundingRepository.GetLatestPublishedProviderVersionBySpecificationId(specificationId,
                                                                                                                                                                          fundingStreamId,
                                                                                                                                                                          providerId));

            if (providerVersion == null)
            {
                return(new NotFoundResult());
            }

            return(new OkObjectResult(providerVersion));
        }
Beispiel #5
0
        public async Task <IActionResult> GetPublishedProviderTransactions(string specificationId,
                                                                           string providerId)
        {
            Guard.IsNullOrWhiteSpace(specificationId, nameof(specificationId));
            Guard.IsNullOrWhiteSpace(providerId, nameof(providerId));

            IEnumerable <PublishedProviderVersion> providerVersions = await ResiliencePolicy.ExecuteAsync(() =>
                                                                                                          _publishedFundingRepository.GetPublishedProviderVersions(specificationId,
                                                                                                                                                                   providerId));

            return(new OkObjectResult(providerVersions?.Select(_ => new PublishedProviderTransaction
            {
                PublishedProviderId = _.PublishedProviderId,
                Author = _.Author,
                Date = _.Date,
                Status = _.Status,
                TotalFunding = _.TotalFunding,
                FundingLines = _.FundingLines
            })));
        }
        public async Task <IActionResult> CanChooseForFunding(string specificationId)
        {
            Guard.IsNullOrWhiteSpace(specificationId, nameof(specificationId));

            ApiResponse <ApiSpecificationSummary> specificationResponse =
                await ResiliencePolicy.ExecuteAsync(() => Specifications.GetSpecificationSummaryById(specificationId));

            ApiSpecificationSummary specificationSummary = specificationResponse?.Content;

            if (specificationSummary == null)
            {
                return(new NotFoundResult());
            }

            SpecificationFundingStatus specificationFundingStatus = await _specificationFundingStatusService.CheckChooseForFundingStatus(specificationSummary);

            return(new OkObjectResult(new SpecificationCheckChooseForFundingResult {
                Status = specificationFundingStatus
            }));
        }
        public async Task <IActionResult> ValidateSpecificationForRefresh(string specificationId)
        {
            List <string> prereqErrors = new List <string>();

            ValidationResult validationResult = SpecificationIdValidator.Validate(specificationId);

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

            ApiResponse <ApiSpecificationSummary> specificationIdResponse =
                await ResiliencePolicy.ExecuteAsync(() => Specifications.GetSpecificationSummaryById(specificationId));

            ApiSpecificationSummary specificationSummary = specificationIdResponse.Content;

            if (specificationSummary == null)
            {
                return(new NotFoundResult());
            }

            IDictionary <string, Provider> scopedProviders = await _providerService.GetScopedProvidersForSpecification(specificationSummary.Id, specificationSummary.ProviderVersionId);

            IPrerequisiteChecker prerequisiteChecker = _prerequisiteCheckerLocator.GetPreReqChecker(PrerequisiteCheckerType.Refresh);

            try
            {
                await prerequisiteChecker.PerformChecks(
                    specificationSummary,
                    null,
                    Array.Empty <PublishedProvider>(),
                    scopedProviders?.Values);
            }
            catch (JobPrereqFailedException ex)
            {
                return(new BadRequestObjectResult(ex.Errors.ToArray().ToModelStateDictionary()));
            }

            return(new NoContentResult());
        }
Beispiel #8
0
        public async Task <IActionResult> GetPublishedProviderVersion(string fundingStreamId,
                                                                      string fundingPeriodId,
                                                                      string providerId,
                                                                      string version)
        {
            Guard.IsNullOrWhiteSpace(fundingStreamId, nameof(fundingStreamId));
            Guard.IsNullOrWhiteSpace(fundingPeriodId, nameof(fundingPeriodId));
            Guard.IsNullOrWhiteSpace(providerId, nameof(providerId));
            Guard.IsNullOrWhiteSpace(version, nameof(version));

            PublishedProviderVersion providerVersion = await ResiliencePolicy.ExecuteAsync(() =>
                                                                                           _publishedFundingRepository.GetPublishedProviderVersion(fundingStreamId,
                                                                                                                                                   fundingPeriodId,
                                                                                                                                                   providerId,
                                                                                                                                                   version));

            if (providerVersion == null)
            {
                return(new NotFoundResult());
            }

            return(new OkObjectResult(providerVersion));
        }
Beispiel #9
0
 private async Task FilterOutPublishedProvidersInError(PublishedProviderIdsRequest providerIdsRequest)
 {
     providerIdsRequest.PublishedProviderIds = await ResiliencePolicy.ExecuteAsync(() =>
                                                                                   _publishedFundingRepository.RemoveIdsInError(providerIdsRequest.PublishedProviderIds));
 }