Ejemplo n.º 1
0
        public async Task <ReturnLongV5Result> UpsertImportedFileV5TBC(
            [FromRoute] long projectId,
            [FromBody] ImportedFileTbc importedFileTbc,
            [FromServices] ISchedulerProxy schedulerProxy)
        {
            // MobileLinework .kml/.kmz files are sent along with linework files
            //     we need to suppress any error and return as if all ok.
            //     however we won't have a LegacyFileId to return - hmmm hope Business centre ignores this
            if (importedFileTbc.ImportedFileTypeId == ImportedFileType.MobileLinework)
            {
                Logger.LogInformation(
                    $"{nameof(UpsertImportedFileV5TBC)}: Ignore MobileLinework from BusinessCentre. projectId {projectId} importedFile: {JsonConvert.SerializeObject(importedFileTbc)}");

                return(ReturnLongV5Result.CreateLongV5Result(HttpStatusCode.OK, -1));
            }

            // this also validates that this customer has access to the projectUid
            var project = await ProjectRequestHelper.GetProjectForCustomer(new Guid(CustomerUid), new Guid(UserId), projectId, Logger, ServiceExceptionHandler, CwsProjectClient, customHeaders);

            var projectUid = project.ProjectId;

            importedFileTbc = FileImportV5TBCDataValidator.ValidateUpsertImportedFileRequest(new Guid(projectUid), importedFileTbc);
            Logger.LogInformation(
                $"{nameof(UpsertImportedFileV5TBC)}: projectId {projectId} projectUid {projectUid} importedFile: {JsonConvert.SerializeObject(importedFileTbc)}");

            var fileEntry = await TccHelper.GetFileInfoFromTccRepository(importedFileTbc, Logger, ServiceExceptionHandler, FileRepo);

            await TccHelper.CopyFileWithinTccRepository(importedFileTbc,
                                                        CustomerUid, projectUid, FileSpaceId,
                                                        Logger, ServiceExceptionHandler, FileRepo).ConfigureAwait(false);

            ImportedFileDescriptorSingleResult importedFileResult;

            using (var ms = await TccHelper.GetFileStreamFromTcc(importedFileTbc, Logger, ServiceExceptionHandler, FileRepo))
            {
                importedFileResult = await UpsertFileInternal(importedFileTbc.Name, ms, new Guid(projectUid),
                                                              importedFileTbc.ImportedFileTypeId,
                                                              importedFileTbc.ImportedFileTypeId == ImportedFileType.Linework
                                                              ?importedFileTbc.LineworkFile.DxfUnitsTypeId
                                                              : DxfUnitsType.Meters,
                                                              fileEntry.createTime, fileEntry.modifyTime,
                                                              importedFileTbc.ImportedFileTypeId == ImportedFileType.SurveyedSurface
                                                              ?importedFileTbc.SurfaceFile.SurveyedUtc
                                                              : (DateTime?)null, schedulerProxy);
            }

            // Automapper maps src.ImportedFileId to LegacyFileId, so this IS the one sent to TRex and used to ref via TCC
            var response = importedFileResult != null
        ? ReturnLongV5Result.CreateLongV5Result(HttpStatusCode.OK, importedFileResult.ImportedFileDescriptor.LegacyFileId)
        : ReturnLongV5Result.CreateLongV5Result(HttpStatusCode.InternalServerError, -1);

            Logger.LogInformation(
                $"{nameof(UpsertImportedFileV5TBC)}: Completed successfully. Response: {response} importedFile: {JsonConvert.SerializeObject(importedFileResult)}");

            return(response);
        }
Ejemplo n.º 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));
        }