Beispiel #1
0
        public async Task <ContractExecutionResult> GetDesignBoundaries([FromQuery] Guid projectUid, [FromQuery] double?tolerance)
        {
            Log.LogInformation($"{nameof(GetDesignBoundaries)}: " + Request.QueryString);

            var projectId = await((RaptorPrincipal)User).GetLegacyProjectId(projectUid);

            tolerance ??= DesignBoundariesRequest.BOUNDARY_POINTS_INTERVAL;

            var request = new DesignBoundariesRequest(projectId, projectUid, tolerance.Value);

            request.Validate();

            var fileList = await FileImportProxy.GetFiles(projectUid.ToString(), GetUserId(), Request.Headers.GetCustomHeaders());

            fileList = fileList?.Where(f => f.ImportedFileType == ImportedFileType.DesignSurface && f.IsActivated).ToList();

            return(await RequestExecutorContainerFactory.Build <DesignExecutor>(
                       LoggerFactory,
                       configStore : ConfigStore,
                       fileList : fileList,
                       trexCompactionDataProxy : TRexCompactionDataProxy,
                       userId : GetUserId(),
                       fileImportProxy : FileImportProxy)
                   .ProcessAsync(request));
        }
Beispiel #2
0
        public void DesignExecutor_DesignBoundariesRequest_ProjectIDFailure()
        {
            var request = new DesignBoundariesRequest(0, Guid.NewGuid(), TOLERANCE);
            var ex      = Assert.ThrowsException <ServiceException>(() => request.Validate());

            ex.Should().NotBeNull();
            ex.Code.Should().Be(HttpStatusCode.BadRequest);
            ex.GetResult.Code.Should().Be(ContractExecutionStatesEnum.ValidationError);
            ex.GetResult.Message.Should().Be("Invalid project ID");
        }
Beispiel #3
0
        public void CanCreateDesignBoundariesRequestTest()
        {
            var validator = new DataAnnotationsValidator();
            DesignBoundariesRequest        request = new DesignBoundariesRequest(projectId, null, tolerance);
            ICollection <ValidationResult> results;

            Assert.IsTrue(validator.TryValidate(request, out results));

            // Missing project id
            request = new DesignBoundariesRequest(-1, null, tolerance);
            Assert.IsFalse(validator.TryValidate(request, out results));
        }
Beispiel #4
0
        public void DesignExecutor_TRex_Success()
        {
            var request = new DesignBoundariesRequest(PROJECT_ID, Guid.NewGuid(), TOLERANCE);

            var expectedResult = new DesignBoundaryResult(JsonConvert.DeserializeObject <GeoJson>(joString));

            var tRexProxy = new Mock <ITRexCompactionDataProxy>();

            tRexProxy.Setup(x => x.SendDataGetRequest <DesignBoundaryResult>(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <IHeaderDictionary>(), It.IsAny <List <KeyValuePair <string, string> > >()))
            .ReturnsAsync(expectedResult);

            var configStore = new Mock <IConfigurationStore>();

            configStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_DESIGN_BOUNDARY")).Returns(true);

            var executor = RequestExecutorContainerFactory
                           .Build <DesignExecutor>(logger, configStore: configStore.Object, fileList: new List <FileData> {
                new FileData()
            },
                                                   trexCompactionDataProxy: tRexProxy.Object, customHeaders: _customHeaders);

            var result = executor.ProcessAsync(request).Result as DesignResult;

            result.Should().NotBeNull();
            result.DesignBoundaries.Should().NotBeNull();
            result.DesignBoundaries.Count.Should().Be(1);

            var geoJSon = result.DesignBoundaries[0];

            geoJSon.Features.Count.Should().Be(1);
            geoJSon.Features.Count.Should().Be(expectedResult.GeoJSON.Features.Count);

            geoJSon.Features[0].Geometry.Coordinates.Count.Should().Be(1);
            geoJSon.Features[0].Geometry.Coordinates.Count.Should().Be(expectedResult.GeoJSON.Features[0].Geometry.Coordinates.Count);

            geoJSon.Features[0].Geometry.Coordinates[0].Count.Should().Be(NUMBER_OF_COORDINATES);
            geoJSon.Features[0].Geometry.Coordinates[0].Count.Should().Be(expectedResult.GeoJSON.Features[0].Geometry.Coordinates[0].Count);

            for (var i = 0; i < geoJSon.Features[0].Geometry.Coordinates[0].Count; i++)
            {
                var coordinate       = geoJSon.Features[0].Geometry.Coordinates[0][i];
                var resultCoordinate = expectedResult.GeoJSON.Features[0].Geometry.Coordinates[0][i];

                coordinate[0].Should().Be(resultCoordinate[0]);
                coordinate[1].Should().Be(resultCoordinate[1]);
            }
        }
Beispiel #5
0
        public Task <ContractExecutionResult> GetDesignBoundaries(
            [FromQuery] Guid projectUid,
            [FromQuery] Guid designUid,
            [FromQuery] string fileName,
            [FromQuery] double?tolerance)
        {
            Log.LogInformation($"{nameof(GetDesignsForProject)}: projectUid:{projectUid}, designUid:{designUid}, fileName:{fileName}, tolerance: {tolerance}");

            const double BOUNDARY_POINTS_INTERVAL = 0.0;

            var designBoundariesRequest = new DesignBoundariesRequest(projectUid, designUid, fileName, tolerance ?? BOUNDARY_POINTS_INTERVAL);

            designBoundariesRequest.Validate();

            return(WithServiceExceptionTryExecuteAsync(() =>
                                                       RequestExecutorContainer
                                                       .Build <DesignBoundariesExecutor>(ConfigStore, LoggerFactory, ServiceExceptionHandler)
                                                       .ProcessAsync(designBoundariesRequest)));
        }
Beispiel #6
0
        public async Task DesignBoundariesExecutor_SiteModelNotFound()
        {
            const double TOLERANCE = 1.2;
            const string FILE_NAME = "Test.ttm";

            var projectUid = Guid.NewGuid();

            var request = new DesignBoundariesRequest(projectUid, Guid.NewGuid(), FILE_NAME, TOLERANCE);

            request.Validate();

            var executor = RequestExecutorContainer
                           .Build <DesignBoundariesExecutor>(
                DIContext.Obtain <IConfigurationStore>(),
                DIContext.Obtain <ILoggerFactory>(),
                DIContext.Obtain <IServiceExceptionHandler>());

            var result = await Assert.ThrowsAsync <ServiceException>(() => executor.ProcessAsync(request));

            Assert.Equal(HttpStatusCode.BadRequest, result.Code);
            Assert.Equal(ContractExecutionStatesEnum.InternalProcessingError, result.GetResult.Code);
            Assert.Equal($"Site model {projectUid} is unavailable", result.GetResult.Message);
        }
Beispiel #7
0
        private async Task <GeoJson> GetDesignBoundary(DesignBoundariesRequest request, string designUid, string fileName)
        {
            var siteModelId = request.ProjectUid.ToString();

            var queryParams = new List <KeyValuePair <string, string> >
            {
                new KeyValuePair <string, string>("projectUid", siteModelId),
                new KeyValuePair <string, string>("designUid", designUid),
                new KeyValuePair <string, string>("fileName", fileName),
                new KeyValuePair <string, string>("tolerance", request.Tolerance.ToString(CultureInfo.CurrentCulture))
            };

            var returnedResult = await trexCompactionDataProxy.SendDataGetRequest <DesignBoundaryResult>(siteModelId, "/design/boundaries", customHeaders, queryParams);

            if (returnedResult?.GeoJSON != null)
            {
                return(returnedResult.GeoJSON);
            }

            throw new ServiceException(HttpStatusCode.InternalServerError,
                                       new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError,
                                                                   $"Failed to get design boundary for file: {fileName}"));
        }
Beispiel #8
0
        public void DesignExecutor_DesignBoundariesRequest_Success()
        {
            var request = new DesignBoundariesRequest(PROJECT_ID, Guid.NewGuid(), TOLERANCE);

            request.Validate();
        }