Example #1
0
        public async Task CreateProjectV5TBCExecutor_GetTCCFile()
        {
            var serviceExceptionHandler = ServiceProvider.GetRequiredService <IServiceExceptionHandler>();
            var fileRepo = new Mock <IFileRepository>();

            fileRepo.Setup(fr => fr.FolderExists(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(true);

            byte[] buffer = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0, 1, 2, 3 };

            fileRepo.Setup(fr => fr.GetFile(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <int>()))
            .ReturnsAsync(new MemoryStream(buffer));

            var coordinateSystemFileContent = await TccHelper.GetFileContentFromTcc(_businessCenterFile, _log, serviceExceptionHandler, fileRepo.Object);

            Assert.True(buffer.SequenceEqual(coordinateSystemFileContent), "CoordinateSystemFileContent not read from DC.");
        }
Example #2
0
        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));
        }