public void ValidateFailMissingDesignTest() { //missing design (for volumes display mode) PatchRequest request = new PatchRequest( projectId, null, callId, DisplayMode.CutFill, palettes, liftSettings, false, VolumesType.None, 0.0, null, null, null, FilterLayerMethod.None, 5, 50); Assert.ThrowsException <ServiceException>(() => request.Validate()); }
public void ValidateFailMissingFilterTest() { //missing filter (for volumes display mode) PatchRequest request = new PatchRequest( projectId, null, callId, DisplayMode.VolumeCoverage, palettes, liftSettings, false, VolumesType.Between2Filters, 0.0, null, null, null, FilterLayerMethod.None, 5, 50); Assert.ThrowsException <TwoFiltersRequiredException>(() => request.Validate()); }
public void ValidateFailInvalidPaletteOrderTest() { //palettes out of order PatchRequest request = new PatchRequest( projectId, null, callId, DisplayMode.Height, invalidPalettes, liftSettings, false, VolumesType.None, 0.0, null, null, null, FilterLayerMethod.None, 5, 50); Assert.ThrowsException <ServiceException>(() => request.Validate()); }
public void ValidateFailInvalidPaletteNumberTest() { //wrong number of palettes for display mode PatchRequest request = new PatchRequest( projectId, null, callId, DisplayMode.CCVPercent, palettes, liftSettings, false, VolumesType.None, 0.0, null, null, null, FilterLayerMethod.None, 5, 50); Assert.ThrowsException <ServiceException>(() => request.Validate()); }
public void ValidateFailInvalidVolumeTypeTest() { //Unsupported volume type (for volumes display mode) PatchRequest request = new PatchRequest( projectId, null, callId, DisplayMode.VolumeCoverage, palettes, liftSettings, false, VolumesType.AboveLevel, 0.0, null, null, null, FilterLayerMethod.None, 5, 50); Assert.ThrowsException <ServiceException>(() => request.Validate()); }
public async Task <ContractExecutionResult> PostProductionDataPatchesTbc([FromBody] PatchRequest request) { request.Validate(); return(await RequestExecutorContainerFactory .Build <PatchExecutor>(LoggerFactory, ConfigStore, trexCompactionDataProxy : TRexCompactionDataProxy, customHeaders : CustomHeaders, userId : GetUserId(), fileImportProxy : FileImportProxy) .ProcessAsync(request)); }
public async Task SinglePatchRequest_Invalid_TRex_NoResult() { var projectId = 999; var projectUid = Guid.NewGuid(); var request = new PatchesRequest("ec520SerialNumber", 90, 180, new BoundingBox2DGrid(1, 200, 10, 210)); var mockConfigStore = new Mock <IConfigurationStore>(); mockConfigStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_PATCHES")).Returns(true); var filterResult = new FilterResult(); filterResult.SetBoundary(new List <Point>() { new Point(request.BoundingBox.BottomleftY, request.BoundingBox.BottomLeftX), new Point(request.BoundingBox.BottomleftY, request.BoundingBox.TopRightX), new Point(request.BoundingBox.TopRightY, request.BoundingBox.TopRightX), new Point(request.BoundingBox.TopRightY, request.BoundingBox.BottomLeftX) }); var patchRequest = new PatchRequest( projectId, projectUid, new Guid(), DisplayMode.Height, null, new LiftBuildSettings(), false, VolumesType.None, VelociraptorConstants.VOLUME_CHANGE_TOLERANCE, null, filterResult, null, FilterLayerMethod.AutoMapReset, 0, 1000, true); patchRequest.Validate(); var exception = new ServiceException(HttpStatusCode.InternalServerError, new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError, $"SinglePatch request failed somehow. ProjectUid: {projectUid}")); var tRexProxy = new Mock <ITRexCompactionDataProxy>(); tRexProxy.Setup(x => x.SendDataPostRequestWithStreamResponse(It.IsAny <PatchDataRequest>(), "/patches", It.IsAny <IHeaderDictionary>())) .Throws(exception); var executor = RequestExecutorContainerFactory .Build <CompactionSinglePatchExecutor>(_logger, configStore: mockConfigStore.Object, trexCompactionDataProxy: tRexProxy.Object); var result = await Assert.ThrowsExceptionAsync <ServiceException>(async() => await executor.ProcessAsync(patchRequest)); result.Code.Should().Be(HttpStatusCode.InternalServerError); result.GetResult.Code.Should().Be(ContractExecutionStatesEnum.InternalProcessingError); result.GetResult.Message.Should().Be(exception.GetResult.Message); }
public async Task <IActionResult> GetSubGridPatches(string ecSerial, double machineLatitude, double machineLongitude, double bottomLeftX, double bottomLeftY, double topRightX, double topRightY) { var patchesRequest = new PatchesRequest(ecSerial, machineLatitude, machineLongitude, new BoundingBox2DGrid(bottomLeftX, bottomLeftY, topRightX, topRightY)); Log.LogInformation($"{nameof(GetSubGridPatches)}: {JsonConvert.SerializeObject(patchesRequest)}"); // todoJeannie temporary to look into the DID info available. Log.LogDebug($"{nameof(GetSubGridPatches)}: customHeaders {CustomHeaders.LogHeaders()}"); try { patchesRequest.Validate(); // identify VSS projectUid and CustomerUid var tfaHelper = new TagFileAuthHelper(LoggerFactory, ConfigStore, TagFileAuthProjectV5Proxy); var tfaResult = await tfaHelper.GetProjectUid(patchesRequest.ECSerial, patchesRequest.MachineLatitude, patchesRequest.MachineLongitude); if (tfaResult.Code != 0 || string.IsNullOrEmpty(tfaResult.ProjectUid) || string.IsNullOrEmpty(tfaResult.CustomerUid)) { var errorMessage = $"Unable to identify a unique project or customer. Result: {JsonConvert.SerializeObject(tfaResult)}"; Log.LogInformation(errorMessage); return(BadRequest(new PatchSubgridsProtobufResult(tfaResult.Code, tfaResult.Message))); } Log.LogInformation($"{nameof(GetSubGridPatches)}: tfaResult {JsonConvert.SerializeObject(tfaResult)}"); // Set customerUid for downstream service calls e.g. ProjectSvc Log.LogInformation($"{nameof(GetSubGridPatches)}: requestHeaders {JsonConvert.SerializeObject(Request.Headers)} PrincipalCustomerUID {((RaptorPrincipal) User).CustomerUid} authNContext {JsonConvert.SerializeObject(((RaptorPrincipal) User).GetAuthNContext())}"); if (((RaptorPrincipal)User).SetCustomerUid(tfaResult.CustomerUid)) { Request.Headers[HeaderConstants.X_VISION_LINK_CUSTOMER_UID] = tfaResult.CustomerUid; } // this endpoint has no UserId so excludedSSs and targets are not relevant var filter = SetupCompactionFilter(Guid.Parse(tfaResult.ProjectUid), patchesRequest.BoundingBox); var liftSettings = SettingsManager.CompactionLiftBuildSettings(CompactionProjectSettings.DefaultSettings); Log.LogDebug($"{nameof(GetSubGridPatches)}: filter: {JsonConvert.SerializeObject(filter)} liftSettings: {JsonConvert.SerializeObject(liftSettings)}"); var requestPatchId = 0; var requestPatchSize = 1000; // max # sub-grids to scan var requestIncludeTimeOffsets = true; var patchRequest = new PatchRequest( null, // obsolete Guid.Parse(tfaResult.ProjectUid), new Guid(), DisplayMode.Height, null, liftSettings, false, VolumesType.None, VelociraptorConstants.VOLUME_CHANGE_TOLERANCE, null, filter, null, FilterLayerMethod.AutoMapReset, requestPatchId, requestPatchSize, requestIncludeTimeOffsets); patchRequest.Validate(); var v2PatchRequestResponse = await WithServiceExceptionTryExecuteAsync(() => RequestExecutorContainerFactory .Build <CompactionSinglePatchExecutor>(LoggerFactory, ConfigStore, trexCompactionDataProxy : TRexCompactionDataProxy, customHeaders : CustomHeaders, userId : GetUserId(), fileImportProxy : FileImportProxy) .ProcessAsync(patchRequest)); var v2PatchRequestFinalResponse = AutoMapperUtility.Automapper.Map <PatchSubgridsProtobufResult>(v2PatchRequestResponse); return(Ok(v2PatchRequestFinalResponse)); } catch (ServiceException se) { Log.LogError(se, $"{nameof(GetSubGridPatches)} Exception thrown: "); var actionResult = StatusCode((int)se.Code, new PatchSubgridsProtobufResult(se.GetResult.Code, se.GetResult.Message)); return(actionResult); } }
public async Task PatchRequest_TRex_WithResult() { var projectId = 999; var projectUid = Guid.NewGuid(); var request = new PatchesRequest("ec520SerialNumber", 90, 180, new BoundingBox2DGrid(1, 200, 10, 210)); var mockConfigStore = new Mock <IConfigurationStore>(); mockConfigStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_PATCHES")).Returns(true); var filterResult = new FilterResult(); filterResult.SetBoundary(new List <Point> { new Point(request.BoundingBox.BottomleftY, request.BoundingBox.BottomLeftX), new Point(request.BoundingBox.BottomleftY, request.BoundingBox.TopRightX), new Point(request.BoundingBox.TopRightY, request.BoundingBox.TopRightX), new Point(request.BoundingBox.TopRightY, request.BoundingBox.BottomLeftX) }); var tRexProxy = new Mock <ITRexCompactionDataProxy>(); var subGridOriginX = 150.45; var subGridOriginY = 1400.677; var palette = new List <ColorPalette>(); uint paletteColor = 44444; var elevationOrigin = (float)100.450; var nowTimeOrigin = new DateTimeOffset(DateTime.UtcNow.AddDays(-5).AddMinutes(100)); var timeOrigin = (uint)(nowTimeOrigin).ToUnixTimeSeconds(); var delta = (uint)0; // elevation offsets are in mm var elevationOffsets = new ushort[cellSize * cellSize]; var timeOffsets = new uint[cellSize * cellSize]; for (var c = delta; c < (cellSize * cellSize); c++) { elevationOffsets[c] = (ushort)(c + 6); timeOffsets[c] = c + 3; if (((int)c % 10) == 0) { palette.Add(new ColorPalette(paletteColor++, elevationOrigin + (elevationOffsets[c] / 1000.0))); } } var patchRequest = new PatchRequest( projectId, projectUid, new Guid(), DisplayMode.Height, palette, new LiftBuildSettings(), true, VolumesType.None, VelociraptorConstants.VOLUME_CHANGE_TOLERANCE, null, filterResult, null, FilterLayerMethod.AutoMapReset, 0, 1000, false); patchRequest.Validate(); var resultStream = WriteAsPerTRex(1, 1, subGridOriginX, subGridOriginY, elevationOrigin, timeOrigin, elevationOffsets, timeOffsets); tRexProxy.Setup(x => x.SendDataPostRequestWithStreamResponse(It.IsAny <PatchDataRequest>(), "/patches", It.IsAny <IHeaderDictionary>())) .Returns(Task.FromResult <Stream>(resultStream)); var executor = RequestExecutorContainerFactory .Build <PatchExecutor>(_logger, mockConfigStore.Object, trexCompactionDataProxy: tRexProxy.Object); var result = await executor.ProcessAsync(patchRequest) as PatchResultRenderedColors; result.Should().NotBeNull(); result.Subgrids.Should().NotBeNull(); result.Subgrids.Length.Should().Be(1); var subGrid = (PatchSubgridResult)result.Subgrids[0]; subGrid.CellOriginX.Should().Be((int)subGridOriginX); subGrid.CellOriginY.Should().Be((int)subGridOriginY); subGrid.ElevationOrigin.Should().Be(elevationOrigin); subGrid.Cells[0, 0].Elevation.Should().Be((float)(elevationOrigin + ((delta + 6.0) / 1000.0))); subGrid.Cells[0, 0].Color.Should().Be(0); subGrid.Cells[0, 1].Elevation.Should().Be((float)(elevationOrigin + ((delta + 7.0) / 1000.0))); subGrid.Cells[0, 1].Color.Should().Be(44444); subGrid.Cells[1, 0].Elevation.Should().Be((float)(elevationOrigin + ((delta + 32.0 + 6.0) / 1000.0))); subGrid.Cells[1, 0].Color.Should().Be(44447); }
public async Task SinglePatchRequest_TRex_WithResult() { var projectId = 999; var projectUid = Guid.NewGuid(); var request = new PatchesRequest("ec520SerialNumber", 90, 180, new BoundingBox2DGrid(1, 200, 10, 210)); var mockConfigStore = new Mock <IConfigurationStore>(); mockConfigStore.Setup(x => x.GetValueBool("ENABLE_TREX_GATEWAY_PATCHES")).Returns(true); var filterResult = new FilterResult(); filterResult.SetBoundary(new List <Point> { new Point(request.BoundingBox.BottomleftY, request.BoundingBox.BottomLeftX), new Point(request.BoundingBox.BottomleftY, request.BoundingBox.TopRightX), new Point(request.BoundingBox.TopRightY, request.BoundingBox.TopRightX), new Point(request.BoundingBox.TopRightY, request.BoundingBox.BottomLeftX) }); var patchRequest = new PatchRequest( projectId, projectUid, new Guid(), DisplayMode.Height, null, new LiftBuildSettings(), false, VolumesType.None, VelociraptorConstants.VOLUME_CHANGE_TOLERANCE, null, filterResult, null, FilterLayerMethod.AutoMapReset, 0, 1000, true); patchRequest.Validate(); var tRexProxy = new Mock <ITRexCompactionDataProxy>(); var subgridOriginX = 150.45; var subgridOriginY = 1400.677; var elevationOrigin = (float)100.45; var nowTimeOrigin = new DateTimeOffset(DateTime.UtcNow.AddDays(-5).AddMinutes(100)); var timeOrigin = (uint)(nowTimeOrigin).ToUnixTimeSeconds(); var delta = (uint)0; // elevation offsets are in mm var elevationOffsets = new ushort[cellSize * cellSize]; var timeOffsets = new uint[cellSize * cellSize]; for (var c = delta; c < (cellSize * cellSize); c++) { elevationOffsets[c] = (ushort)(c + 6); timeOffsets[c] = c + 3; } var resultStream = WriteAsPerTRex(1, 1, subgridOriginX, subgridOriginY, elevationOrigin, timeOrigin, elevationOffsets, timeOffsets); tRexProxy.Setup(x => x.SendDataPostRequestWithStreamResponse(It.IsAny <PatchDataRequest>(), "/patches", It.IsAny <IHeaderDictionary>())) .Returns(Task.FromResult <Stream>(resultStream)); var executor = RequestExecutorContainerFactory .Build <CompactionSinglePatchExecutor>(_logger, configStore: mockConfigStore.Object, trexCompactionDataProxy: tRexProxy.Object); var result = await executor.ProcessAsync(patchRequest) as PatchSubgridsRawResult; result.Should().NotBeNull(); result.Subgrids.Should().NotBeNull(); result.Subgrids.Length.Should().Be(1); result.Subgrids[0].ElevationOffsets.Length.Should().Be(cellSize * cellSize); result.Subgrids[0].ElevationOrigin.Should().Be(elevationOrigin); result.Subgrids[0].TimeOffsets.Length.Should().Be(cellSize * cellSize); result.Subgrids[0].TimeOrigin.Should().Be(timeOrigin); result.Subgrids[0].ElevationOffsets[0].Should().Be((ushort)(delta + 6 + 1)); // zero means no offset available result.Subgrids[0].TimeOffsets[0].Should().Be(delta + 3); var doubleArrayResult = (new CompactionSinglePatchResult()).UnpackSubgrid(cellSize, result.Subgrids[0]); doubleArrayResult[0, 0].easting.Should().Be(subgridOriginX + (cellSize / 2)); doubleArrayResult[0, 0].northing.Should().Be(subgridOriginY + (cellSize / 2)); doubleArrayResult[0, 0].elevation.Should().Be(Math.Round(elevationOrigin + (ushort)(delta + 6) / 1000.0, 5)); var actualDateTime = nowTimeOrigin.AddSeconds(delta + 3).DateTime; doubleArrayResult[0, 0].dateTime.Should().Be(new DateTime(actualDateTime.Year, actualDateTime.Month, actualDateTime.Day, actualDateTime.Hour, actualDateTime.Minute, actualDateTime.Second)); }