Пример #1
0
        /// <summary>
        /// Validate the Create request e.g that the file has been uploaded and parameters are as expected.
        /// </summary>
        public static void ValidateUpsertImportedFileRequest(FlowFile file, Guid projectUid,
                                                             ImportedFileType importedFileType, DxfUnitsType dxfUnitsType,
                                                             DateTime fileCreatedUtc, DateTime fileUpdatedUtc,
                                                             string importedBy, DateTime?surveyedUtc, Guid?parentUid, double?offset)
        {
            if (file == null)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(27),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(27)));
            }

            if (file.flowFilename.Length > MAX_FILE_NAME_LENGTH || string.IsNullOrEmpty(file.flowFilename) ||
                file.flowFilename.IndexOfAny(Path.GetInvalidPathChars()) > 0)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(28),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(28)));
            }

            if (string.IsNullOrEmpty(file.path) || file.path.IndexOfAny(Path.GetInvalidPathChars()) > 0)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(29),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(29)));
            }

            ValidateUpsertImportedFileRequest(projectUid, importedFileType, dxfUnitsType, fileCreatedUtc, fileUpdatedUtc, importedBy, surveyedUtc, file.flowFilename, parentUid, offset);
        }
Пример #2
0
 public void Validate()
 {
     if (string.IsNullOrEmpty(OrgShortName))
     {
         throw new ServiceException(HttpStatusCode.BadRequest,
                                    new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(86),
                                                                string.Format(projectErrorCodesProvider.FirstNameWithOffset(86), OrgShortName)));
     }
 }
Пример #3
0
        public void ValidateImportFile_NoFlowFile()
        {
            var ex = Assert.Throws <ServiceException>(
                () => FlowJsFileImportDataValidator.ValidateUpsertImportedFileRequest(null, projectUid, ImportedFileType.MassHaulPlan, DxfUnitsType.ImperialFeet,
                                                                                      fileCreatedUtc, fileUpdatedUtc, IMPORTED_BY, surfaceUtc, parentUid, offset));

            Assert.NotEqual(-1, ex.GetContent.IndexOf(projectErrorCodesProvider.FirstNameWithOffset(27)));
        }
Пример #4
0
        /// <summary>
        /// Validate the Upsert request i.e. that the parameters are as expected.
        /// </summary>
        /// <param name="projectId"></param>
        /// <param name="importedFile"></param>
        public static ImportedFileTbc ValidateUpsertImportedFileRequest(Guid projectUid,
                                                                        ImportedFileTbc importedFile)
        {
            if (projectUid == Guid.Empty)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(5),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(5)));
            }

            if (!Enum.IsDefined(typeof(ImportedFileType), importedFile.ImportedFileTypeId))
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(30),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(30)));
            }

            if (!(importedFile.ImportedFileTypeId >= ImportedFileType.Linework && importedFile.ImportedFileTypeId <= ImportedFileType.Alignment))
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(31),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(31)));
            }

            ProjectDataValidator.ValidateBusinessCentreFile(importedFile);


            if (importedFile.ImportedFileTypeId == ImportedFileType.Linework &&
                (importedFile.LineworkFile == null ||
                 !Enum.IsDefined(typeof(DxfUnitsType), importedFile.LineworkFile.DxfUnitsTypeId))
                )
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(75),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(75)));
            }

            if (importedFile.ImportedFileTypeId == ImportedFileType.SurveyedSurface &&
                (importedFile.SurfaceFile == null ||
                 importedFile.SurfaceFile.SurveyedUtc < DateTime.UtcNow.AddYears(-30) || importedFile.SurfaceFile.SurveyedUtc > DateTime.UtcNow.AddDays(2))
                )
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(33),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(33)));
            }

            if (importedFile.ImportedFileTypeId == ImportedFileType.Alignment &&
                importedFile.AlignmentFile == null)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(95),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(95)));
            }

            var fileExtension = Path.GetExtension(importedFile.Name).ToLower();

            if (!(
                    (importedFile.ImportedFileTypeId == ImportedFileType.Linework && fileExtension == ".dxf") ||
                    (importedFile.ImportedFileTypeId == ImportedFileType.DesignSurface && fileExtension == ".ttm") ||
                    (importedFile.ImportedFileTypeId == ImportedFileType.SurveyedSurface && fileExtension == ".ttm") ||
                    (importedFile.ImportedFileTypeId == ImportedFileType.Alignment && fileExtension == ".svl")
                    ))
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(projectErrorCodesProvider.GetErrorNumberwithOffset(32),
                                                                       projectErrorCodesProvider.FirstNameWithOffset(32)));
            }

            return(importedFile);
        }
Пример #5
0
        /// <summary>
        /// Validate the Create request e.g that the file has been uploaded and parameters are as expected.
        /// </summary>
        public static void ValidateUpsertImportedFileRequest(Guid projectUid, ImportedFileType importedFileType, DxfUnitsType dxfUnitsType, DateTime fileCreatedUtc,
                                                             DateTime fileUpdatedUtc, string importedBy, DateTime?surveyedUtc, string filename, Guid?parentUid, double?offset)
        {
            if (projectUid == Guid.Empty)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(5),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(5)));
            }

            if (!Enum.IsDefined(typeof(ImportedFileType), importedFileType))
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(30),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(30)));
            }

            var validType = (importedFileType >= ImportedFileType.Linework && importedFileType <= ImportedFileType.Alignment) ||
                            importedFileType == ImportedFileType.ReferenceSurface || importedFileType == ImportedFileType.GeoTiff;

            if (!validType)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(30),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(31)));
            }

            if (importedFileType != ImportedFileType.ReferenceSurface)
            {
                var fileExtension = Path.GetExtension(filename).ToLower();
                if (!(importedFileType == ImportedFileType.Linework && fileExtension == ".dxf" ||
                      importedFileType == ImportedFileType.DesignSurface && fileExtension == ".ttm" ||
                      importedFileType == ImportedFileType.SurveyedSurface && fileExtension == ".ttm" ||
                      importedFileType == ImportedFileType.Alignment && fileExtension == ".svl" ||
                      importedFileType == ImportedFileType.GeoTiff && fileExtension == ".tif"))
                {
                    throw new ServiceException(HttpStatusCode.BadRequest,
                                               new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(32),
                                                                           ProjectErrorCodesProvider.FirstNameWithOffset(32) + $"imported filetype: {importedFileType} and extension is {fileExtension} "));
                }
            }

            if (!Enum.IsDefined(typeof(DxfUnitsType), dxfUnitsType))
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(75),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(75)));
            }

            if (importedFileType == ImportedFileType.Linework && (dxfUnitsType < DxfUnitsType.Meters || dxfUnitsType > DxfUnitsType.UsSurveyFeet))
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(75),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(76)));
            }

            if (fileCreatedUtc < DateTime.UtcNow.AddYears(-30) || fileCreatedUtc > DateTime.UtcNow.AddDays(2))
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(33),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(33)));
            }

            if (fileUpdatedUtc < DateTime.UtcNow.AddYears(-30) || fileUpdatedUtc > DateTime.UtcNow.AddDays(2))
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(34),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(34)));
            }

            if (string.IsNullOrEmpty(importedBy))
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(35),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(35)));
            }

            if ((importedFileType == ImportedFileType.SurveyedSurface || importedFileType == ImportedFileType.GeoTiff) && surveyedUtc == null)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(36),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(36)));
            }

            if (importedFileType == ImportedFileType.ReferenceSurface && (parentUid == null || offset == null || offset.Value == 0))
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(118),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(118)));
            }
        }
Пример #6
0
        /// <summary>
        /// Processes the Upsert
        /// </summary>
        protected override async Task <ContractExecutionResult> ProcessAsyncEx <T>(T item)
        {
            var importedFile = CastRequestObjectTo <UpdateImportedFile>(item, errorCode: 68);

            var existingImportedFile = await projectRepo.GetImportedFile(importedFile.ImportedFileUid.ToString());

            if (existingImportedFile == null)
            {
                throw new ServiceException(HttpStatusCode.BadRequest,
                                           new ContractExecutionResult(ProjectErrorCodesProvider.GetErrorNumberwithOffset(122),
                                                                       ProjectErrorCodesProvider.FirstNameWithOffset(122)));
            }

            if (importedFile.IsTRexDesignFileType)
            {
                await ImportedFileRequestHelper.NotifyTRexUpdateFile(importedFile.ProjectUid,
                                                                     importedFile.ImportedFileType, importedFile.FileDescriptor.FileName, importedFile.ImportedFileUid,
                                                                     importedFile.SurveyedUtc,
                                                                     log, customHeaders, serviceExceptionHandler,
                                                                     tRexImportFileProxy);
            }

            if (importedFile.ImportedFileType == ImportedFileType.Linework ||
                importedFile.ImportedFileType == ImportedFileType.GeoTiff)
            {
                string dcFileName = null;
                if (importedFile.ImportedFileType == ImportedFileType.Linework)
                {
                    var project = await ProjectRequestHelper.GetProject(importedFile.ProjectUid, new Guid(customerUid), new Guid(userId), log, serviceExceptionHandler, cwsProjectClient, customHeaders);

                    dcFileName = DataOceanFileUtil.DataOceanFileName(project.CoordinateSystemFileName, false, importedFile.ProjectUid, null);
                }

                var jobRequest = TileGenerationRequestHelper.CreateRequest(
                    importedFile.ImportedFileType,
                    customerUid,
                    importedFile.ProjectUid.ToString(),
                    existingImportedFile.ImportedFileUid,
                    importedFile.DataOceanRootFolder,
                    importedFile.DataOceanFileName,
                    dcFileName,
                    importedFile.DxfUnitsTypeId,
                    importedFile.SurveyedUtc);
                await schedulerProxy.ScheduleVSSJob(jobRequest, customHeaders);
            }

            // if all succeeds, update Db and  put update to kafka que
            var updateImportedFileEvent = await ImportedFileRequestDatabaseHelper.UpdateImportedFileInDb(existingImportedFile,
                                                                                                         existingImportedFile.FileDescriptor,
                                                                                                         importedFile.SurveyedUtc, existingImportedFile.MinZoomLevel, existingImportedFile.MaxZoomLevel,
                                                                                                         importedFile.FileCreatedUtc, importedFile.FileUpdatedUtc, userEmailAddress,
                                                                                                         log, serviceExceptionHandler, projectRepo);

            var fileDescriptor = new ImportedFileDescriptorSingleResult(
                (await ImportedFileRequestDatabaseHelper.GetImportedFileList(importedFile.ProjectUid.ToString(), log, userId, projectRepo))
                .ToImmutableList()
                .FirstOrDefault(f => f.ImportedFileUid == importedFile.ImportedFileUid.ToString())
                );

            log.LogInformation(
                $"UpdateImportedFileExecutor. entry {(fileDescriptor.ImportedFileDescriptor == null ? "not " : "")}retrieved from DB : {JsonConvert.SerializeObject(fileDescriptor)}");

            return(fileDescriptor);
        }