private void GivenGetCalculationCircularDependencies(
     HttpStatusCode httpStatusCode,
     IEnumerable <Entity <Calculation> > actualValue = null)
 {
     _graphApiClient
     .GetCircularDependencies(SpecificationId)
     .Returns(new ApiResponse <IEnumerable <Entity <Calculation> > >(httpStatusCode, actualValue));
 }
        public async Task GetCircularDependencies_WhenFeatureEnabledAndSpecificationSuppliedWithCalculationWithNoCircularDependencies_NoCircularDependenciesReturned()
        {
            SpecificationSummary specificationSummary = NewSpecification();

            _graphApiClient
            .GetCircularDependencies(specificationSummary.Id)
            .Returns(new ApiResponse <IEnumerable <GraphEntity> >(HttpStatusCode.OK));

            _calculationsFeatureFlag
            .IsGraphEnabled()
            .Returns(false);

            IEnumerable <CalculationEntity> circularDependencies = await _graphRepository.GetCircularDependencies(specificationSummary.Id);

            circularDependencies
            .IsNullOrEmpty()
            .Should()
            .Be(true);
        }
        public async Task <IActionResult> GetCalculationCircularDependencies(string specificationId)
        {
            ApiResponse <IEnumerable <Entity <Calculation> > > getCircularDependenciesApiResponse
                = await _graphApiClient.GetCircularDependencies(specificationId);

            IActionResult errorResult = getCircularDependenciesApiResponse.IsSuccessOrReturnFailureResult(
                $"Get Circular Dependencies by specification ID:{specificationId}");

            if (errorResult != null)
            {
                return(errorResult);
            }

            IEnumerable <GraphCalculationEntityViewModel <GraphCalculationViewModel> > graphCalculationEntities =
                _mapper.Map <IEnumerable <GraphCalculationEntityViewModel <GraphCalculationViewModel> > >(
                    getCircularDependenciesApiResponse.Content);

            return(new OkObjectResult(graphCalculationEntities));
        }
Пример #4
0
        private void ValidScenarioSetup(string fundingStreamId)
        {
            SpecificationSummary specificationSummary = new SpecificationSummary
            {
                Id          = SpecificationId,
                TemplateIds = new Dictionary <string, string>
                {
                    [fundingStreamId] = TemplateVersion
                }
            };

            TemplateMetadataContents templateMetadataContents = new TemplateMetadataContents
            {
                RootFundingLines = new List <FundingLine>
                {
                    new FundingLine
                    {
                        TemplateLineId = 123,
                        Name           = "FundingLine-1"
                    },
                    new FundingLine
                    {
                        TemplateLineId = 234,
                        Name           = "FundingLine-2-withFundingLines",
                        FundingLines   = new List <FundingLine>
                        {
                            new FundingLine
                            {
                                TemplateLineId = 345,
                                Name           = "FundingLine-2-fl-1"
                            },
                            new FundingLine
                            {
                                TemplateLineId = 456,
                                Name           = "FundingLine-2-fl-2",
                                FundingLines   = new List <FundingLine>
                                {
                                    new FundingLine
                                    {
                                        TemplateLineId = 890,
                                        Name           = "FundingLine-2-fl-2-fl-1"
                                    }
                                }
                            }
                        }
                    },
                    new FundingLine
                    {
                        TemplateLineId = 567,
                        Name           = "FundingLine-3-withCalculationsAndFundingLines",
                        FundingLines   = new List <FundingLine>
                        {
                            new FundingLine
                            {
                                TemplateLineId = 678,
                                Name           = "FundingLine-3-fl-1"
                            }
                        },
                        Calculations = new List <Calculation>
                        {
                            new Calculation
                            {
                                Name = "FundingLine-3-calc-1",
                                TemplateCalculationId = 7,
                                Type = Common.TemplateMetadata.Enums.CalculationType.Cash
                            },
                            new Calculation
                            {
                                Name = "FundingLine-3-calc-2",
                                TemplateCalculationId = 11,
                                Calculations          = new List <Calculation>
                                {
                                    new Calculation
                                    {
                                        Name = "FundingLine-3-calc-2-calc-1",
                                        TemplateCalculationId = 8,
                                        Type = Common.TemplateMetadata.Enums.CalculationType.Cash
                                    }
                                }
                            },
                            new Calculation
                            {
                                Name = "FundingLine-3-calc-3",
                                TemplateCalculationId = 10,
                                Type = Common.TemplateMetadata.Enums.CalculationType.Cash
                            }
                        }
                    },
                    new FundingLine
                    {
                        TemplateLineId = 789,
                        Name           = "FundingLine-4"
                    },
                }
            };

            _specificationsService.GetSpecificationSummaryById(SpecificationId)
            .Returns(new OkObjectResult(specificationSummary));

            _policiesApiClient.GetFundingTemplateContents(FundingStreamId, FundingPeriodId, TemplateVersion)
            .Returns(new ApiResponse <TemplateMetadataContents>(HttpStatusCode.OK, templateMetadataContents));

            _calculationsApiClient.GetTemplateMapping(SpecificationId, FundingStreamId)
            .Returns(new ApiResponse <TemplateMapping>(HttpStatusCode.OK,
                                                       new TemplateMapping
            {
                FundingStreamId      = FundingStreamId,
                SpecificationId      = SpecificationId,
                TemplateMappingItems = new List <TemplateMappingItem>
                {
                    new TemplateMappingItem
                    {
                        TemplateId    = 7,
                        CalculationId = aValidCalculationId1
                    },
                    new TemplateMappingItem
                    {
                        TemplateId    = 11,
                        CalculationId = aValidCalculationId2
                    },
                    new TemplateMappingItem
                    {
                        TemplateId    = 8,
                        CalculationId = "CalculationIdForTemplateCalculationId2"
                    },
                    new TemplateMappingItem
                    {
                        TemplateId    = 10,
                        CalculationId = aValidCalculationId3
                    }
                }
            }));

            _calculationsApiClient.GetCalculationMetadataForSpecification(SpecificationId)
            .Returns(new ApiResponse <IEnumerable <CalculationMetadata> >(HttpStatusCode.OK,
                                                                          new List <CalculationMetadata>
            {
                new CalculationMetadata
                {
                    SpecificationId = SpecificationId,
                    CalculationId   = aValidCalculationId1,
                    PublishStatus   = CalculationExpectedPublishStatus
                },
                new CalculationMetadata
                {
                    SpecificationId = SpecificationId,
                    CalculationId   = aValidCalculationId2,
                    PublishStatus   = CalculationExpectedPublishStatus
                },
                new CalculationMetadata
                {
                    SpecificationId = SpecificationId,
                    CalculationId   = aValidCalculationId3,
                    PublishStatus   = CalculationExpectedPublishStatus
                }
            }));

            _graphApiClient.GetCircularDependencies(SpecificationId)
            .Returns(new ApiResponse <IEnumerable <Entity <Common.ApiClient.Graph.Models.Calculation> > >(
                         HttpStatusCode.OK, new List <Entity <Common.ApiClient.Graph.Models.Calculation> >()
            {
                new Entity <Common.ApiClient.Graph.Models.Calculation>()
                {
                    Node = new Common.ApiClient.Graph.Models.Calculation()
                    {
                        SpecificationId = SpecificationId,
                        CalculationId   = "CalculationIdForTemplateCalculationId2"
                    }
                }
            }));
        }
Пример #5
0
        public async Task <IActionResult> GetFundingStructure(string fundingStreamId, string fundingPeriodId, string specificationId)
        {
            IActionResult specificationSummaryResult = await _specificationsService.GetSpecificationSummaryById(specificationId);

            if (!(specificationSummaryResult is OkObjectResult))
            {
                return(specificationSummaryResult);
            }

            SpecificationSummary specificationSummary = (specificationSummaryResult as OkObjectResult).Value
                                                        as SpecificationSummary;

            string templateVersion = specificationSummary.TemplateIds.ContainsKey(fundingStreamId)
                ? specificationSummary.TemplateIds[fundingStreamId]
                : null;

            if (templateVersion == null)
            {
                return(new InternalServerErrorResult(
                           $"Specification contains no matching template version for funding stream '{fundingStreamId}'"));
            }

            ApiResponse <TemplateMetadataContents> templateMetadataContentsApiResponse =
                await _policiesResilience.ExecuteAsync(() => _policiesApiClient.GetFundingTemplateContents(fundingStreamId, fundingPeriodId, templateVersion));

            IActionResult templateMetadataContentsApiResponseErrorResult =
                templateMetadataContentsApiResponse.IsSuccessOrReturnFailureResult("GetFundingTemplateContents");

            if (templateMetadataContentsApiResponseErrorResult != null)
            {
                return(templateMetadataContentsApiResponseErrorResult);
            }

            ApiResponse <TemplateMapping> templateMappingResponse =
                await _calculationsResilience.ExecuteAsync(() => _calculationsApiClient.GetTemplateMapping(specificationId, fundingStreamId));

            IActionResult templateMappingResponseErrorResult =
                templateMappingResponse.IsSuccessOrReturnFailureResult("GetTemplateMapping");

            if (templateMappingResponseErrorResult != null)
            {
                return(templateMappingResponseErrorResult);
            }

            ApiResponse <IEnumerable <CalculationMetadata> > calculationMetadata =
                await _calculationsResilience.ExecuteAsync(() => _calculationsApiClient.GetCalculationMetadataForSpecification(specificationId));

            IActionResult calculationMetadataErrorResult =
                calculationMetadata.IsSuccessOrReturnFailureResult("calculationMetadata");

            if (calculationMetadataErrorResult != null)
            {
                return(calculationMetadataErrorResult);
            }

            List <string> calculationIdsWithError = new List <string>();

            ApiResponse <IEnumerable <Entity <Calculation> > > getCircularDependenciesApiResponse =
                await _graphApiClient.GetCircularDependencies(specificationId);

            IActionResult circularDependenciesApiErrorResult =
                getCircularDependenciesApiResponse.IsSuccessOrReturnFailureResult("GetCircularDependencies");

            if (circularDependenciesApiErrorResult == null)
            {
                calculationIdsWithError =
                    getCircularDependenciesApiResponse.Content.Select(calcs => calcs.Node.CalculationId).ToList();
            }

            List <FundingStructureItem> fundingStructures = new List <FundingStructureItem>();

            RecursivelyAddFundingLineToFundingStructure(
                fundingStructures,
                templateMetadataContentsApiResponse.Content.RootFundingLines,
                templateMappingResponse.Content.TemplateMappingItems.ToList(),
                calculationMetadata.Content.ToList(),
                calculationIdsWithError);

            FundingStructure fundingStructure = new FundingStructure
            {
                Items        = fundingStructures,
                LastModified = await GetFundingStructureTimeStamp(fundingStreamId,
                                                                  fundingPeriodId,
                                                                  specificationId)
            };

            return(new OkObjectResult(fundingStructure));
        }
Пример #6
0
        public async Task <IEnumerable <CalculationEntity> > GetCircularDependencies(string specificationId)
        {
            if (!(await GraphEnabled()))
            {
                return(null);
            }

            ApiResponse <IEnumerable <GraphEntity> > entities = await _resilience.ExecuteAsync(() => _graphApiClient.GetCircularDependencies(specificationId));

            return(entities?.Content?.Select(_ =>
                                             new CalculationEntity
            {
                Node = _.Node.AsJson().AsPoco <GraphCalculation>(),
                Relationships = _.Relationships
            }));
        }