public async Task <ImportedFileDescriptorSingleResult> CreateImportedFileDirectV6( [FromServices] ISchedulerProxy schedulerProxy, Guid projectUid, string filename, ImportedFileType importedFileType, DxfUnitsType dxfUnitsType, DateTime fileCreatedUtc, DateTime fileUpdatedUtc, DateTime?surveyedUtc = null) { if (importedFileType == ImportedFileType.ReferenceSurface) { ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 122); } FileImportDataValidator.ValidateUpsertImportedFileRequest(projectUid, importedFileType, dxfUnitsType, fileCreatedUtc, fileUpdatedUtc, UserEmailAddress, surveyedUtc, filename, null, null); Logger.LogInformation( $"{nameof(CreateImportedFileDirectV6)}: ProjectUID: `{projectUid}`, Filename: `{filename}` ImportedFileType: `{importedFileType}`, DxfUnitsType: `{dxfUnitsType}`, SurveyedUTC: `{(surveyedUtc == null ? "N/A" : surveyedUtc.ToString())}`"); //When debugging locally using Postman, remove this check so can do an update await ValidateFileDoesNotExist(projectUid.ToString(), filename, importedFileType, surveyedUtc, null, null); if (!MultipartRequestHelper.IsMultipartContentType(Request.ContentType)) { ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 58, $"Expected a multipart request, but got '{Request.ContentType}'"); } var tempFilePath = await HttpContext.Request.StreamFile(Guid.NewGuid().ToString(), Logger); var result = await UpsertFile(tempFilePath, filename, projectUid.ToString(), importedFileType, dxfUnitsType, fileCreatedUtc, fileUpdatedUtc, surveyedUtc, schedulerProxy); return(result); }
public void ValidateImportFile_ReferenceSurfaceMissingOffset() { var ex = Assert.Throws <ServiceException>( () => FileImportDataValidator.ValidateUpsertImportedFileRequest(projectUid, ImportedFileType.ReferenceSurface, DxfUnitsType.ImperialFeet, fileCreatedUtc, fileUpdatedUtc, IMPORTED_BY, null, "deblah", parentUid, 0)); Assert.NotEqual(-1, ex.GetContent.IndexOf(projectErrorCodesProvider.FirstNameWithOffset(118))); }
public async Task <ContractExecutionResult> CreateReferenceSurface( [FromQuery] Guid projectUid, [FromQuery] string filename, [FromQuery] DateTime fileCreatedUtc, [FromQuery] DateTime fileUpdatedUtc, [FromQuery] Guid parentUid, [FromQuery] double offset, [FromServices] ISchedulerProxy schedulerProxy, [FromServices] IPreferenceProxy prefProxy) { Logger.LogInformation($"{nameof(CreateReferenceSurface)}: projectUid {projectUid} filename: {filename} parentUid: {parentUid} offset: {offset}"); await ValidateProjectId(projectUid.ToString()); //Check parent design does exist var importedFiles = await ImportedFileRequestDatabaseHelper.GetImportedFileList(projectUid.ToString(), Logger, UserId, ProjectRepo); var parent = importedFiles.FirstOrDefault(i => i.ImportedFileUid == parentUid.ToString()); if (parent == null) { ServiceExceptionHandler.ThrowServiceException(HttpStatusCode.BadRequest, 120); } //Fill in file name if not provided if (string.IsNullOrEmpty(filename)) { filename = await DefaultReferenceSurfaceName(prefProxy, offset, Path.GetFileNameWithoutExtension(parent.Name)); } //Validate parameters FileImportDataValidator.ValidateUpsertImportedFileRequest(projectUid, ImportedFileType.ReferenceSurface, DxfUnitsType.Meters, fileCreatedUtc, fileUpdatedUtc, UserEmailAddress, null, filename, parentUid, offset); //Check reference surface does not exist await ValidateFileDoesNotExist(projectUid.ToString(), filename, ImportedFileType.ReferenceSurface, null, parentUid, offset); var importedFileResult = await UpsertFileInternal(filename, null, projectUid, ImportedFileType.ReferenceSurface, DxfUnitsType.Meters, fileCreatedUtc, fileUpdatedUtc, null, schedulerProxy, parentUid, offset); //If parent design is deactivated then deactivate reference surface if (!parent.IsActivated) { var filesToUpdate = new Dictionary <Guid, bool>(); filesToUpdate.Add(new Guid(importedFileResult.ImportedFileDescriptor.ImportedFileUid), false); await DoActivationAndNotification(projectUid.ToString(), filesToUpdate); importedFiles = await ImportedFileRequestDatabaseHelper.GetImportedFileList(projectUid.ToString(), Logger, UserId, ProjectRepo); importedFileResult.ImportedFileDescriptor = importedFiles.SingleOrDefault(i => i.ImportedFileUid == importedFileResult.ImportedFileDescriptor.ImportedFileUid); } Logger.LogInformation( $"{nameof(CreateReferenceSurface)}: Completed successfully. Response: {JsonConvert.SerializeObject(importedFileResult)}"); return(importedFileResult); }
public void ValidateImportFile_ReferenceSurfaceHappyPath() { var file = new FlowFile { path = "\\*", flowFilename = "deblah" }; FileImportDataValidator.ValidateUpsertImportedFileRequest(projectUid, ImportedFileType.ReferenceSurface, DxfUnitsType.ImperialFeet, fileCreatedUtc, fileUpdatedUtc, IMPORTED_BY, null, "deblah", parentUid, offset); }