public async Task ValidateProjectExecutor_UpdateCoordSysFile_MissingCoordSysFileContents() { var project = CreateProjectDetailModel(_customerTrn, _projectTrn); var projectList = CreateProjectListModel(_customerTrn, _projectTrn); var cwsProjectClient = new Mock <ICwsProjectClient>(); cwsProjectClient.Setup(ps => ps.GetProjectsForCustomer(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <bool>(), It.IsAny <CwsProjectType?>(), It.IsAny <ProjectStatus?>(), It.IsAny <bool>(), It.IsAny <IHeaderDictionary>())).ReturnsAsync(projectList); cwsProjectClient.Setup(ps => ps.GetMyProject(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <IHeaderDictionary>())).ReturnsAsync(project); var coordSystemResult = new CoordinateSystemSettingsResult(); var coordProxy = new Mock <IProductivity3dV1ProxyCoord>(); coordProxy.Setup(cp => cp.CoordinateSystemValidate(It.IsAny <byte[]>(), It.IsAny <string>(), It.IsAny <IHeaderDictionary>())).ReturnsAsync(coordSystemResult); var request = new ProjectValidateDto { AccountTrn = _customerTrn, ProjectTrn = _projectTrn, UpdateType = CwsUpdateType.CalibrationUpdate, CoordinateSystemFileName = "some file name", CoordinateSystemFileContent = null }; var executor = CreateExecutor(productivity3dV1ProxyCoord: coordProxy.Object, cwsProjectClient: cwsProjectClient.Object); var result = await executor.ProcessAsync(MapProjectValidation(request)); result.ShouldBe(134, "Both coordinate system file name and contents must be provided."); }
public async Task ValidateProjectExecutor_UpdateCoordSysFile_Failed() { var project = CreateProjectDetailModel(_customerTrn, _projectTrn); var projectList = CreateProjectListModel(_customerTrn, _projectTrn); var cwsProjectClient = new Mock <ICwsProjectClient>(); cwsProjectClient.Setup(ps => ps.GetProjectsForCustomer(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <bool>(), It.IsAny <CwsProjectType?>(), It.IsAny <ProjectStatus?>(), It.IsAny <bool>(), It.IsAny <IHeaderDictionary>())).ReturnsAsync(projectList); cwsProjectClient.Setup(ps => ps.GetMyProject(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <IHeaderDictionary>())).ReturnsAsync(project); var coordSystemResult = new CoordinateSystemSettingsResult { Code = 99, Message = "Failed!" }; var coordProxy = new Mock <IProductivity3dV1ProxyCoord>(); coordProxy.Setup(cp => cp.CoordinateSystemValidate(It.IsAny <byte[]>(), It.IsAny <string>(), It.IsAny <IHeaderDictionary>())).ReturnsAsync(coordSystemResult); var request = new ProjectValidateDto { AccountTrn = _customerTrn, ProjectTrn = _projectTrn, UpdateType = CwsUpdateType.CalibrationUpdate, CoordinateSystemFileName = "some file name", CoordinateSystemFileContent = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 } }; var executor = CreateExecutor(productivity3dV1ProxyCoord: coordProxy.Object, cwsProjectClient: cwsProjectClient.Object); var result = await executor.ProcessAsync(MapProjectValidation(request)); result.ShouldBe(47, $"Unable to validate CoordinateSystem in 3dpm: {coordSystemResult.Code} {coordSystemResult.Message}."); }
public async Task ValidateProjectExecutor_Create_Valid() { var projectList = CreateProjectListModel(_customerTrn, _projectTrn); var cwsProjectClient = new Mock <ICwsProjectClient>(); cwsProjectClient.Setup(ps => ps.GetProjectsForCustomer(It.IsAny <Guid>(), It.IsAny <Guid>(), It.IsAny <bool>(), It.IsAny <CwsProjectType?>(), It.IsAny <ProjectStatus?>(), It.IsAny <bool>(), It.IsAny <IHeaderDictionary>())).ReturnsAsync(projectList); var coordSystemResult = new CoordinateSystemSettingsResult(); var coordProxy = new Mock <IProductivity3dV1ProxyCoord>(); coordProxy.Setup(cp => cp.CoordinateSystemValidate(It.IsAny <byte[]>(), It.IsAny <string>(), It.IsAny <IHeaderDictionary>())).ReturnsAsync(coordSystemResult); var request = new ProjectValidateDto { AccountTrn = _customerTrn, ProjectTrn = null, ProjectName = "some project", ProjectType = CwsProjectType.AcceptsTagFiles, Boundary = CreateNonOverlappingBoundary(), UpdateType = CwsUpdateType.CreateProject, CoordinateSystemFileName = "some file name", CoordinateSystemFileContent = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 } }; var result = await CreateExecutor(coordProxy.Object, cwsProjectClient.Object) .ProcessAsync(MapProjectValidation(request)); result.IsSuccessResponse(); }
/// <summary> /// Validates the coordinate system file in TRex. In CWS this is the project configuration file of type CALIBRATION. /// </summary> private async Task <object> ValidateCoordinateSystemFile(Guid?projectUid, string fullFileName, byte[] fileContents) { //Validate file in 3dpm (TRex) CoordinateSystemSettingsResult coordinateSystemSettingsResult = null; try { //TODO: Do CWS pass just the file name or the full file name with TRN etc. var fileName = fullFileName;//CwsFileNameHelper.ExtractFileName(fullFileName); coordinateSystemSettingsResult = await productivity3dV1ProxyCoord .CoordinateSystemValidate(fileContents, fileName, customHeaders); } catch (Exception e) { return(new { code = 57, message = $"A problem occurred at the validate CoordinateSystem endpoint in 3dpm. Exception: {e.Message}" }); } if (coordinateSystemSettingsResult == null) { return new { code = 46, message = "Invalid CoordinateSystem." } } ; if (coordinateSystemSettingsResult.Code != 0) //TASNodeErrorStatus.asneOK { return(new { code = 47, message = $"Unable to validate CoordinateSystem in 3dpm: {coordinateSystemSettingsResult.Code} {coordinateSystemSettingsResult.Message}." }); } return(new { code = ContractExecutionStatesEnum.ExecutedSuccessfully, message = ContractExecutionResult.DefaultMessage }); }
public CoordinateSystemSettingsResult DummyCoordsystemPost([FromBody] CoordinateSystemFile request) { var cs = CoordinateSystemSettingsResult.CreateCoordinateSystemSettings ( csName: "Mock generated by DummyCoordsystemPost", csGroup: "Projection from Data Collector", csib: new byte[] { 0, 1, 2, 3, 4, 5, 6, 7 }, datumName: "Datum Grid", siteCalibration: false, geoidFileName: "NZ2009.GGF", geoidName: "New Zealand Geoid 2009", isDatumGrid: true, latitudeDatumGridFileName: "NZNATlat.DGF", longitudeDatumGridFileName: "NZNATlon.DGF", heightDatumGridFileName: null, shiftGridName: null, snakeGridName: null, verticalDatumName: null, unsupportedProjection: false ); Logger.LogInformation("DummyCoordsystemPost: CoordinateSystemFile {0}. CoordinateSystemSettings {1}", JsonConvert.SerializeObject(request), JsonConvert.SerializeObject(cs)); return(cs); }
public async Task ProjectChangedExecutor_CoordSystemChanged_HappyPath(NotificationType notificationType) { var projectUid = Guid.NewGuid(); var projectTrn = TRNHelper.MakeTRN(projectUid, TRNHelper.TRN_ACCOUNT); var coordSystemResult = new CoordinateSystemSettingsResult(); var coordProxy = new Mock <IProductivity3dV1ProxyCoord>(); coordProxy.Setup(cp => cp.CoordinateSystemPost(projectUid, It.IsAny <byte[]>(), It.IsAny <string>(), It.IsAny <IHeaderDictionary>())).ReturnsAsync(coordSystemResult); var dataOceanClient = new Mock <IDataOceanClient>(); dataOceanClient.Setup(f => f.FolderExists(It.IsAny <string>(), It.IsAny <HeaderDictionary>())).ReturnsAsync(true); dataOceanClient.Setup(f => f.PutFile(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Stream>(), It.IsAny <HeaderDictionary>())).ReturnsAsync(true); var authn = new Mock <ITPaaSApplicationAuthentication>(); authn.Setup(a => a.GetApplicationBearerToken()).Returns("some token"); var request = new ProjectChangeNotificationDto { AccountTrn = _customerTrn, ProjectTrn = projectTrn, NotificationType = notificationType, CoordinateSystemFileName = "some file name", CoordinateSystemFileContent = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8 } }; var executor = RequestExecutorContainerFactory.Build <ProjectChangedExecutor> (_loggerFactory, _configStore, ServiceExceptionHandler, _customerUid.ToString(), _userUid.ToString(), null, _customHeaders, coordProxy.Object, dataOceanClient: dataOceanClient.Object, authn: authn.Object); var result = await executor.ProcessAsync(request); Assert.Equal(ContractExecutionStatesEnum.ExecutedSuccessfully, result.Code); Assert.Equal(ContractExecutionResult.DefaultMessage, result.Message); }
/// <summary> /// Pass Coordinate System to TRex and save a copy in DataOcean for DXF tile generation. /// </summary> private async Task SaveCoordinateSystem(Guid projectUid, string coordinateSystemFileName, byte[] coordinateSystemFileContent) { //Save to DataOcean for DXF tile generation var rootFolder = configStore.GetValueString("DATA_OCEAN_ROOT_FOLDER_ID"); if (string.IsNullOrEmpty(rootFolder)) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 115); } using (var ms = new MemoryStream(coordinateSystemFileContent)) { await DataOceanHelper.WriteFileToDataOcean( ms, rootFolder, customerUid, projectUid.ToString(), DataOceanFileUtil.DataOceanFileName(coordinateSystemFileName, false, projectUid, null), log, serviceExceptionHandler, dataOceanClient, authn, projectUid, configStore); } //Save in TRex CoordinateSystemSettingsResult coordinateSystemSettingsResult = await productivity3dV1ProxyCoord .CoordinateSystemPost(projectUid, coordinateSystemFileContent, coordinateSystemFileName, customHeaders); var message = string.Format($"Sending coordinate system to TRex returned code: {0} Message {1}.", coordinateSystemSettingsResult?.Code ?? -1, coordinateSystemSettingsResult?.Message ?? "coordinateSystemSettingsResult == null"); log.LogDebug(message); if (coordinateSystemSettingsResult == null || coordinateSystemSettingsResult.Code != 0 /* TASNodeErrorStatus.asneOK */) { log.LogCritical($"Failed to save coordinate system file in TRex for project {projectUid}"); } }