public void ValidateCreateProjectV5Request_CheckBusinessCentreFile() { var bcf = BusinessCenterFile.CreateBusinessCenterFile(_businessCenterFile.FileSpaceId, _businessCenterFile.Path, _businessCenterFile.Name, _businessCenterFile.CreatedUtc); bcf.Path = "BC Data/Sites/Chch Test Site/"; var resultantBusinessCenterFile = ProjectDataValidator.ValidateBusinessCentreFile(bcf); Assert.Equal("/BC Data/Sites/Chch Test Site", resultantBusinessCenterFile.Path); bcf = BusinessCenterFile.CreateBusinessCenterFile(_businessCenterFile.FileSpaceId, _businessCenterFile.Path, _businessCenterFile.Name, _businessCenterFile.CreatedUtc); bcf.Path = ""; var ex = Assert.Throws <ServiceException>(() => ProjectDataValidator.ValidateBusinessCentreFile(bcf)); Assert.NotEqual(-1, ex.GetContent.IndexOf("2083", StringComparison.Ordinal)); bcf = BusinessCenterFile.CreateBusinessCenterFile(_businessCenterFile.FileSpaceId, _businessCenterFile.Path, _businessCenterFile.Name, _businessCenterFile.CreatedUtc); bcf.Name = ""; ex = Assert.Throws <ServiceException>(() => ProjectDataValidator.ValidateBusinessCentreFile(bcf)); Assert.NotEqual(-1, ex.GetContent.IndexOf("2002", StringComparison.Ordinal)); bcf = BusinessCenterFile.CreateBusinessCenterFile(_businessCenterFile.FileSpaceId, _businessCenterFile.Path, _businessCenterFile.Name, _businessCenterFile.CreatedUtc); bcf.FileSpaceId = null; ex = Assert.Throws <ServiceException>(() => ProjectDataValidator.ValidateBusinessCentreFile(bcf)); Assert.NotEqual(-1, ex.GetContent.IndexOf("2084", StringComparison.Ordinal)); ex = Assert.Throws <ServiceException>(() => ProjectDataValidator.ValidateBusinessCentreFile(null)); Assert.NotEqual(-1, ex.GetContent.IndexOf("2082", StringComparison.Ordinal)); }
public async Task <ReturnLongV5Result> CreateProjectTBC([FromBody] CreateProjectV5Request projectRequest) { if (projectRequest == null) { ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 81); } Logger.LogInformation($"{nameof(CreateProjectTBC)} projectRequest: {JsonConvert.SerializeObject(projectRequest)}"); var projectValidation = MapV5Models.MapCreateProjectV5RequestToProjectValidation(projectRequest, CustomerUid); projectRequest.CoordinateSystem = ProjectDataValidator.ValidateBusinessCentreFile(projectRequest.CoordinateSystem); // Read CoordSystem file from TCC as byte[]. projectValidation.CoordinateSystemFileContent = await TccHelper .GetFileContentFromTcc(projectRequest.CoordinateSystem, Logger, ServiceExceptionHandler, FileRepo).ConfigureAwait(false); try { var resultPolygonWkt = PolygonUtils.MakeCounterClockwise(projectValidation.ProjectBoundaryWKT, out var hasBeenReversed); if (hasBeenReversed) { Logger.LogInformation($"{nameof(CreateProjectTBC)} Boundary has been reversed to: {projectValidation.ProjectBoundaryWKT}"); projectValidation.ProjectBoundaryWKT = resultPolygonWkt; } } catch (Exception e) { Logger.LogError(e, $"{nameof(CreateProjectTBC)} Boundary orientation check threw exception: "); throw; } var validationResult = await WithServiceExceptionTryExecuteAsync(() => RequestExecutorContainerFactory .Build <ValidateProjectExecutor>(LoggerFactory, ConfigStore, ServiceExceptionHandler, CustomerUid, UserId, null, customHeaders, Productivity3dV1ProxyCoord, cwsProjectClient : CwsProjectClient) .ProcessAsync(projectValidation) ); if (validationResult.Code != ContractExecutionStatesEnum.ExecutedSuccessfully) { ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, validationResult.Code); } var result = (await WithServiceExceptionTryExecuteAsync(() => RequestExecutorContainerFactory .Build <CreateProjectTBCExecutor>(LoggerFactory, ConfigStore, ServiceExceptionHandler, CustomerUid, UserId, null, customHeaders, Productivity3dV1ProxyCoord, dataOceanClient: DataOceanClient, authn: Authorization, cwsProjectClient: CwsProjectClient, cwsDeviceClient: CwsDeviceClient, cwsProfileSettingsClient: CwsProfileSettingsClient) .ProcessAsync(projectValidation)) as ProjectV6DescriptorsSingleResult ); Logger.LogInformation($"{nameof(CreateProjectTBC)}: completed successfully. ShortProjectId {result.ProjectDescriptor.ShortRaptorProjectId}"); return(ReturnLongV5Result.CreateLongV5Result(HttpStatusCode.Created, result.ProjectDescriptor.ShortRaptorProjectId)); }