/// <summary> /// Add a string array of data /// </summary> public Task <string> SendImportedFilesToWebApiV5TBC(TestSupport ts, long projectId, string[] importFileArray, int row, HttpStatusCode statusCode = HttpStatusCode.OK) { var uri = $"api/v5/projects/{projectId}/importedfiles"; var ed = ts.ConvertImportFileArrayToObject(importFileArray, row); var importedFileTbc = new ImportedFileTbc { FileSpaceId = "u710e3466-1d47-45e3-87b8-81d1127ed4ed", Path = Path.GetFullPath(ed.Name), Name = Path.GetFileName(ed.Name), ImportedFileTypeId = ed.ImportedFileType, CreatedUtc = ed.FileCreatedUtc, AlignmentFile = ed.ImportedFileType == ImportedFileType.Alignment ? new AlignmentFile { Offset = 1 } : null, SurfaceFile = ed.ImportedFileType == ImportedFileType.SurveyedSurface ? new SurfaceFile { SurveyedUtc = new DateTime() } : null, LineworkFile = ed.ImportedFileType == ImportedFileType.Linework ? new LineworkFile { DxfUnitsTypeId = DxfUnitsType.Meters } : null }; var requestJson = JsonConvert.SerializeObject(importedFileTbc, new JsonSerializerSettings { DateTimeZoneHandling = DateTimeZoneHandling.Unspecified }); return(RestClient.SendHttpClientRequest(uri, HttpMethod.Put, MediaTypes.JSON, MediaTypes.JSON, ts.CustomerUid.ToString(), requestJson, expectedHttpCode: statusCode)); }
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); }
/// <summary> /// Copies importedFile between filespaces in TCC /// From FilespaceIDBcCustomer\BC Data to FilespaceIdVisionLink\CustomerUID\ProjectUID /// returns filespaceID; path and filename which identifies it uniquely in TCC /// this may be a create or update, so ok if it already exists /// </summary> /// <returns></returns> public static async Task <FileDescriptor> CopyFileWithinTccRepository(ImportedFileTbc sourceFile, string customerUid, string projectUid, string dstFileSpaceId, ILogger log, IServiceExceptionHandler serviceExceptionHandler, IFileRepository fileRepo) { var srcTccPathAndFile = $"{sourceFile.Path}/{sourceFile.Name}"; var destTccPath = $"/{customerUid}/{projectUid}"; string tccDestinationFileName = sourceFile.Name; if (sourceFile.ImportedFileTypeId == ImportedFileType.SurveyedSurface) { tccDestinationFileName = tccDestinationFileName.IncludeSurveyedUtcInName(sourceFile.SurfaceFile.SurveyedUtc); } var destTccPathAndFile = $"/{customerUid}/{projectUid}/{tccDestinationFileName}"; var tccCopyFileResult = false; try { // The filename already contains the surveyUtc where appropriate log.LogInformation( $"CopyFileWithinTccRepository: srcFileSpaceId: {sourceFile.FileSpaceId} destFileSpaceId {dstFileSpaceId} srcTccPathAndFile {srcTccPathAndFile} destTccPathAndFile {destTccPathAndFile}"); // check for exists first to avoid an misleading exception in our logs. var folderAlreadyExists = await fileRepo.FolderExists(dstFileSpaceId, destTccPath).ConfigureAwait(false); if (folderAlreadyExists == false) { await fileRepo.MakeFolder(dstFileSpaceId, destTccPath).ConfigureAwait(false); } // this creates folder if it doesn't exist, and upserts file if it does tccCopyFileResult = await fileRepo .CopyFile(sourceFile.FileSpaceId, dstFileSpaceId, srcTccPathAndFile, destTccPathAndFile) .ConfigureAwait(false); } catch (Exception e) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 92, "fileRepo.PutFile", e.Message); } if (tccCopyFileResult == false) { serviceExceptionHandler.ThrowServiceException(HttpStatusCode.InternalServerError, 92); } var fileDescriptorTarget = FileDescriptor.CreateFileDescriptor(dstFileSpaceId, destTccPath, tccDestinationFileName); log.LogInformation( $"CopyFileWithinTccRepository: fileDescriptorTarget {JsonConvert.SerializeObject(fileDescriptorTarget)}"); return(fileDescriptorTarget); }
public void ValidateImportFile_CompleteDesignSurface() { var importedFileTbc = new ImportedFileTbc { FileSpaceId = _fileSpaceId, Path = _path, Name = "TheAlignment.ttm", ImportedFileTypeId = ImportedFileType.DesignSurface, CreatedUtc = _createdUtc }; FileImportV5TBCDataValidator.ValidateUpsertImportedFileRequest(_projectUid, importedFileTbc); }
public void ValidateImportFile_CompleteLinework() { var importedFileTbc = new ImportedFileTbc { FileSpaceId = _fileSpaceId, Path = _path, Name = "TheLineWork.dxf", ImportedFileTypeId = ImportedFileType.Linework, CreatedUtc = _createdUtc, LineworkFile = new LineworkFile { DxfUnitsTypeId = DxfUnitsType.ImperialFeet } }; FileImportV5TBCDataValidator.ValidateUpsertImportedFileRequest(_projectUid, importedFileTbc); }
public void ValidateImportFile_IncompleteLinework() { var importedFileTbc = new ImportedFileTbc { FileSpaceId = _fileSpaceId, Path = _path, Name = "TheLineWork.dxf", ImportedFileTypeId = ImportedFileType.Linework, CreatedUtc = _createdUtc }; var ex = Assert.Throws <ServiceException>( () => FileImportV5TBCDataValidator.ValidateUpsertImportedFileRequest(_projectUid, importedFileTbc)); Assert.NotEqual(-1, ex.GetContent.IndexOf("2075", StringComparison.Ordinal)); }
public void ValidateImportFile_UnsupportedImportedFileType() { var importedFileTbc = new ImportedFileTbc { FileSpaceId = _fileSpaceId, Path = _path, Name = _name, ImportedFileTypeId = ImportedFileType.MassHaulPlan, CreatedUtc = _createdUtc }; var ex = Assert.Throws <ServiceException>( () => FileImportV5TBCDataValidator.ValidateUpsertImportedFileRequest(_projectUid, importedFileTbc)); Assert.NotEqual(-1, ex.GetContent.IndexOf("2031", StringComparison.Ordinal)); }
public void ValidateImportFile_InvalidProjectId() { var importedFileTbc = new ImportedFileTbc { FileSpaceId = _fileSpaceId, Path = _path, Name = _name, ImportedFileTypeId = _importedFileTypeId, CreatedUtc = _createdUtc }; var ex = Assert.Throws <ServiceException>( () => FileImportV5TBCDataValidator.ValidateUpsertImportedFileRequest(new Guid(), importedFileTbc)); Assert.NotEqual(-1, ex.GetContent.IndexOf("2005", StringComparison.Ordinal)); }
public void ValidateImportFile_CompleteAlignment() { var importedFileTbc = new ImportedFileTbc { FileSpaceId = _fileSpaceId, Path = _path, Name = "TheAlignment.svl", ImportedFileTypeId = ImportedFileType.Alignment, CreatedUtc = _createdUtc, AlignmentFile = new AlignmentFile { Offset = 3 } }; FileImportV5TBCDataValidator.ValidateUpsertImportedFileRequest(_projectUid, importedFileTbc); }
public void ValidateImportFile_CompleteSurveyedSurface() { var importedFileTbc = new ImportedFileTbc { FileSpaceId = _fileSpaceId, Path = _path, Name = "TheSurfaceFile.ttm", ImportedFileTypeId = ImportedFileType.SurveyedSurface, CreatedUtc = _createdUtc, SurfaceFile = new SurfaceFile { SurveyedUtc = DateTime.UtcNow.AddDays(-1) } }; FileImportV5TBCDataValidator.ValidateUpsertImportedFileRequest(_projectUid, importedFileTbc); }
public async Task CopyTCCFile() { var serviceExceptionHandler = ServiceProvider.GetRequiredService <IServiceExceptionHandler>(); var importedFileTbc = new ImportedFileTbc { FileSpaceId = _fileSpaceId, Name = "MoundRoadlinework.dxf", Path = "/BC Data/Sites/Chch Test Site/Designs/Mound Road", ImportedFileTypeId = ImportedFileType.Linework, CreatedUtc = DateTime.UtcNow }; var fileRepo = new Mock <IFileRepository>(); fileRepo.Setup(fr => fr.FolderExists(It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true); fileRepo.Setup(fr => fr.CopyFile(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>(), It.IsAny <string>())).ReturnsAsync(true); await TccHelper.CopyFileWithinTccRepository(importedFileTbc, _customerUid.ToString(), Guid.NewGuid().ToString(), "f9sdg0sf9", _log, serviceExceptionHandler, fileRepo.Object).ConfigureAwait(false); }
/// <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); }