Пример #1
0
        public void SinglePatchRequest_Valid(string ecSerial,
                                             double machineLatitude, double machineLongitude,
                                             double bottomLeftX, double bottomLeftY, double topRightX, double topRightY)
        {
            var request = new PatchesRequest(ecSerial,
                                             machineLatitude, machineLongitude,
                                             new BoundingBox2DGrid(bottomLeftX, bottomLeftY, topRightX, topRightY));

            request.Validate();
        }
Пример #2
0
        public void SinglePatchRequest_Invalid(string ecSerial,
                                               double machineLatitude, double machineLongitude,
                                               double bottomLeftX, double bottomLeftY, double topRightX, double topRightY,
                                               int errorResultCode, string expectedMessage)
        {
            var request = new PatchesRequest(ecSerial,
                                             machineLatitude, machineLongitude,
                                             new BoundingBox2DGrid(bottomLeftX, bottomLeftY, topRightX, topRightY));
            var ex = Assert.ThrowsException <ServiceException>(() => request.Validate());

            ex.Should().NotBeNull();
            ex.Code.Should().Be(HttpStatusCode.BadRequest);
            ex.GetResult.Code.Should().Be(errorResultCode);
            ex.GetResult.Message.Should().Be(expectedMessage);
        }
Пример #3
0
        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);
            }
        }