Example #1
0
        public Task <ContractExecutionResult> UpdateDesign([FromBody] DesignRequest designRequest)
        {
            Log.LogInformation($"{nameof(UpdateDesign)}: {JsonConvert.SerializeObject(designRequest)}");
            designRequest.Validate();
            GatewayHelper.ValidateAndGetSiteModel(nameof(UpdateDesign), designRequest.ProjectUid, true);

            if (!DesignExists(designRequest.ProjectUid, designRequest.FileType, designRequest.DesignUid))
            {
                return(Task.FromResult(new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError, "Design doesn't exist. Cannot update.")));
            }

            if (designRequest.FileType == ImportedFileType.DesignSurface || designRequest.FileType == ImportedFileType.SurveyedSurface)
            {
                return(WithServiceExceptionTryExecuteAsync(() => RequestExecutorContainer
                                                           .Build <UpdateTTMDesignExecutor>(ConfigStore, LoggerFactory, ServiceExceptionHandler)
                                                           .ProcessAsync(designRequest)));
            }

            if (designRequest.FileType == ImportedFileType.Alignment)
            {
                return(WithServiceExceptionTryExecuteAsync(() =>
                                                           RequestExecutorContainer
                                                           .Build <UpdateSVLDesignExecutor>(ConfigStore, LoggerFactory, ServiceExceptionHandler)
                                                           .ProcessAsync(designRequest)));
            }
            throw new ServiceException(HttpStatusCode.BadRequest, new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError, "File type must be DesignSurface, SurveyedSurface or Alignment"));
        }
Example #2
0
        public async Task <MachineExecutionResult> GetMachines(string siteModelID,
                                                               [FromServices] ICoordinateServiceUtility coordinateServiceUtility)
        {
            Log.LogInformation($"{nameof(GetMachines)}: siteModelID: {siteModelID}");

            var siteModel = GatewayHelper.ValidateAndGetSiteModel(nameof(GetMachines), siteModelID);
            var CSIB      = siteModel.CSIB();

            if (string.IsNullOrEmpty(CSIB))
            {
                Log.LogError($"{nameof(GetMachines)}: siteModel has no CSIB");
                throw new ServiceException(System.Net.HttpStatusCode.InternalServerError, new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError, "The SiteModel has no CSIB."));
            }

            var machines = siteModel.Machines.ToList();
            var result   = new MachineExecutionResult(new List <MachineStatus>(machines.Count));

            if (machines.Any())
            {
                var resultMachines = machines.Select(machine => AutoMapperUtility.Automapper.Map <MachineStatus>(machine)).ToList();
                var response       = await coordinateServiceUtility.PatchLLH(siteModel.CSIB(), resultMachines);

                result.MachineStatuses = resultMachines;

                // todo once corex is implemented, we will have a better idea why patching fails
                //if (response == ContractExecutionStatesEnum.ExecutedSuccessfully)
                //  result.MachineStatuses = resultMachines;
                //else
                //  return (MachineExecutionResult) new ContractExecutionResult(response);
            }

            Log.LogInformation($"{nameof(GetMachines)}: result: {JsonConvert.SerializeObject(result)}");
            return(result);
        }
Example #3
0
        /// <summary>
        /// Filter validation common to APIs passing 3dp Filter/s
        /// </summary>
        /// <param name="method"></param>
        /// <param name="projectUid"></param>
        /// <param name="filterResult"></param>
        /// <exception cref="ServiceException"></exception>
        protected void ValidateFilterMachines(string method, Guid?projectUid, FilterResult filterResult)
        {
            if (projectUid == null || projectUid == Guid.Empty)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError,
                                                                       $"Invalid project UID {projectUid}"));
            }
            var siteModel = GatewayHelper.ValidateAndGetSiteModel(method, projectUid.Value);

            if (filterResult?.ContributingMachines != null)
            {
                GatewayHelper.ValidateMachines(filterResult.ContributingMachines.Select(m => m.AssetUid).ToList(), siteModel);
            }

            if (filterResult != null && !string.IsNullOrEmpty(filterResult.OnMachineDesignName))
            {
                var machineDesign = siteModel.SiteModelMachineDesigns.Locate(filterResult.OnMachineDesignName);
                if (machineDesign == null)
                {
                    throw new ServiceException(HttpStatusCode.BadRequest,
                                               new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError,
                                                                           $"Unknown DesignName: {filterResult.OnMachineDesignName}."));
                }

                filterResult.OnMachineDesignId = machineDesign.Id;
            }
        }
Example #4
0
        public AssetOnDesignLayerPeriodsExecutionResult GetMachineLayers(string siteModelID)
        {
            Log.LogInformation($"{nameof(GetMachineLayers)}: siteModelID: {siteModelID}");

            var siteModel = GatewayHelper.ValidateAndGetSiteModel(nameof(GetMachineLayers), siteModelID);
            var result    = new AssetOnDesignLayerPeriodsExecutionResult(siteModel.GetAssetOnDesignLayerPeriods());

            Log.LogInformation($"{nameof(GetMachineLayers)}: result: {JsonConvert.SerializeObject(result)}");
            return(result);
        }
Example #5
0
        public ContractExecutionResult RebuildProject([FromBody] ProjectRebuildRequest rebuildRequest)
        {
            Log.LogInformation($"{nameof(RebuildProject)}: {JsonConvert.SerializeObject(rebuildRequest)}");
            rebuildRequest.Validate();
            GatewayHelper.ValidateAndGetSiteModel(nameof(RebuildProject), rebuildRequest.ProjectUid, true);

            if (rebuildRequest.DataOrigin == TransferProxyType.TAGFiles)
            {
                return(WithServiceExceptionTryExecute(() =>
                                                      RequestExecutorContainer
                                                      .Build <ProjectRebuildExecutor>(ConfigStore, LoggerFactory, ServiceExceptionHandler)
                                                      .Process(rebuildRequest)));
            }

            throw new ServiceException(HttpStatusCode.BadRequest, new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError, "Data origin must be ''TAGFiles'' (enum TransferProxyType.TAGFiles)"));
        }
Example #6
0
        public void GatewayHelper_NoSiteModel_Fail(Guid projectUid)
        {
            var mockSiteModels = new Mock <ISiteModels>();

            mockSiteModels.Setup(x => x.GetSiteModel(It.IsAny <Guid>(), It.IsAny <bool>())).Returns((ISiteModel)null);

            DIBuilder
            .New()
            .AddLogging()
            .Add(x => x.AddSingleton <ISiteModels>(mockSiteModels.Object))
            .Complete();

            var ex = Assert.Throws <ServiceException>(() => GatewayHelper.ValidateAndGetSiteModel("ValidateReportData_GriddedNoSiteModel_Fail", projectUid));

            ex.Code.Should().Be(HttpStatusCode.BadRequest);
            ex.GetResult.Code.Should().Be(ContractExecutionStatesEnum.ValidationError);
            ex.GetResult.Message.Should().Be($"ValidateReportData_GriddedNoSiteModel_Fail: SiteModel: {projectUid} not found ");
        }
Example #7
0
        public ProjectStatisticsResult GetStatistics([FromBody] ProjectStatisticsTRexRequest projectStatisticsTRexRequest)
        {
            Log.LogInformation($"#In# {nameof(GetStatistics)}: projectStatisticsTRexRequest: {JsonConvert.SerializeObject(projectStatisticsTRexRequest)}");

            try
            {
                projectStatisticsTRexRequest.Validate();
                GatewayHelper.ValidateAndGetSiteModel(nameof(GetStatistics), projectStatisticsTRexRequest.ProjectUid);

                return(WithServiceExceptionTryExecute(() =>
                                                      RequestExecutorContainer
                                                      .Build <SiteModelStatisticsExecutor>(ConfigStore, LoggerFactory, ServiceExceptionHandler)
                                                      .Process(projectStatisticsTRexRequest) as ProjectStatisticsResult));
            }
            finally
            {
                Log.LogInformation($"#Out# {nameof(GetStatistics)}: projectStatisticsTRexRequest: {JsonConvert.SerializeObject(projectStatisticsTRexRequest)}");
            }
        }
Example #8
0
        public BoundingBox3DGrid GetExtents(string siteModelID)
        {
            Log.LogInformation($"{nameof(GetExtents)}: siteModelID: {siteModelID}");

            var extents = GatewayHelper.ValidateAndGetSiteModel(nameof(GetExtents), siteModelID).SiteModelExtent;

            if (extents != null)
            {
                return(new BoundingBox3DGrid(
                           extents.MinX,
                           extents.MinY,
                           extents.MinZ,
                           extents.MaxX,
                           extents.MaxY,
                           extents.MaxZ
                           ));
            }

            return(null);
        }
Example #9
0
        public void ValidateReportData_GriddedSuccess(Guid projectUid, Guid cutFillDesignUid, double?cutFillDesignOffset, Guid?alignmentDesignUid)
        {
            var mockSiteModel  = new Mock <ISiteModel>();
            var mockSiteModels = new Mock <ISiteModels>();

            mockSiteModels.Setup(x => x.GetSiteModel(It.IsAny <Guid>(), It.IsAny <bool>())).Returns(mockSiteModel.Object);

            var mockDesign        = new Mock <IDesign>();
            var mockDesigns       = new Mock <IDesigns>();
            var mockDesignManager = new Mock <IDesignManager>();

            mockDesignManager.Setup(x => x.List(It.IsAny <Guid>())).Returns(mockDesigns.Object);
            mockDesigns.Setup(x => x.Locate(It.IsAny <Guid>())).Returns(mockDesign.Object);

            var mockAlignments       = new Mock <IAlignments>();
            var mockAlignmentManager = new Mock <IAlignmentManager>();

            mockAlignmentManager.Setup(x => x.List(It.IsAny <Guid>())).Returns(mockAlignments.Object);
            mockAlignments.Setup(x => x.Locate(It.IsAny <Guid>())).Returns((IAlignment)null);

            DIBuilder
            .New()
            .AddLogging()
            .Add(x => x.AddSingleton <ISiteModels>(mockSiteModels.Object))
            .Add(x => x.AddSingleton <IDesignManager>(mockDesignManager.Object))
            .Add(x => x.AddSingleton <IAlignmentManager>(mockAlignmentManager.Object))
            .Add(x => x.AddTransient <IReportDataValidationUtility, ReportDataValidationUtility>())
            .Complete();

            var request = new CompactionReportGridTRexRequest(
                projectUid, null,
                true, true, true, true, true, true,
                cutFillDesignUid, cutFillDesignOffset,
                null, GridReportOption.Automatic,
                800000, 400000, 800001, 400001, 2, null, null);

            var siteModel = GatewayHelper.ValidateAndGetSiteModel(nameof(ValidateReportData_GriddedSuccess), projectUid);
            var isOk      = DIContext.Obtain <IReportDataValidationUtility>().ValidateData(nameof(ValidateReportData_GriddedSuccess), projectUid, request);

            Assert.True(isOk);
        }
Example #10
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="requestObj"></param>
        /// <returns></returns>
        /// <exception cref="ServiceException"></exception>
        public bool ValidateData(string method, Guid?projectUid, object requestObj)
        {
            if (projectUid == null || projectUid == Guid.Empty)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError,
                                                                       "Invalid project UID."));
            }
            GatewayHelper.ValidateAndGetSiteModel(method, projectUid.Value);

            var request = requestObj as CompactionReportTRexRequest;

            if (request.CutFillDesignUid.HasValue &&
                !(request.CutFillDesignUid == Guid.Empty) &&
                DIContext.Obtain <IDesignManager>().List(request.ProjectUid).Locate(request.CutFillDesignUid.Value) == null)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError,
                                                                       $"CutFill design {request.CutFillDesignUid.Value} is not found."));
            }

            if (requestObj != null &&
                requestObj.GetType() == typeof(CompactionReportStationOffsetTRexRequest))
            {
                var alignmentUid = ((CompactionReportStationOffsetTRexRequest)requestObj).AlignmentDesignUid;
                if (!(alignmentUid == Guid.Empty) &&
                    DIContext.Obtain <IAlignmentManager>().List(request.ProjectUid).Locate(alignmentUid) == null)
                {
                    throw new ServiceException(HttpStatusCode.BadRequest,
                                               new ContractExecutionResult(ContractExecutionStatesEnum.ValidationError,
                                                                           $"Alignment design {alignmentUid} is not found."));
                }
            }

            return(true);
        }