public async Task Test_InvalidTagFile_UnableToRead() { SetupDITfa(false); var td = new TagFileDetail() { assetId = Guid.NewGuid(), projectId = Guid.NewGuid(), tagFileName = "Test.tag", tagFileContent = new byte[101], tccOrgId = "", IsJohnDoe = false }; // Validate tagfile var result = TagfileValidator.PreScanTagFile(td, out var tagFilePreScan); Assert.True(result.Code == (int)TRexTagFileResultCode.TRexTagFileReaderError, "Failed to return correct error code"); Assert.Equal("InvalidValueTypeID", result.Message); Assert.NotNull(tagFilePreScan); }
public async Task Test_PlatformSerialNoValidationOk() { // This test ensures platformSerialNumber (serial/deviceid) is extracted and used in validation. Note this Tagfile has no Radio Serial id. Only Serial id. var projectUid = Guid.NewGuid(); var moqRequest = new GetProjectUidsRequest(projectUid.ToString(), string.Empty, 40, 50); var moqResult = new GetProjectUidsResult(projectUid.ToString(), null, null, 0, "success"); SetupDITfa(true, moqRequest, moqResult); byte[] tagContent; using (var tagFileStream = new FileStream(Path.Combine("TestData", "TAGFiles", "2415J078SW-Serial-Test.tag"), FileMode.Open, FileAccess.Read)) { tagContent = new byte[tagFileStream.Length]; tagFileStream.Read(tagContent, 0, (int)tagFileStream.Length); } var td = new TagFileDetail() { assetId = null, projectId = null, // force validation on serial id tagFileName = "2415J078SW-Serial-Test.tag", tagFileContent = tagContent, tccOrgId = "", IsJohnDoe = false }; var tagFilePreScan = new TAGFilePreScan(); await using (var stream = new MemoryStream(td.tagFileContent)) tagFilePreScan.Execute(stream); var result = await TagfileValidator.ValidSubmission(td, tagFilePreScan).ConfigureAwait(false); Assert.True(result.Code == (int)TRexTagFileResultCode.Valid, "Failed to return a Valid request"); Assert.True(td.projectId != null, "Failed to return a Valid projectID"); Assert.Equal("success", result.Message); }
public async Task Test_HasAssetUid_TfaByPassed() { // note that assetId is available, thus this comes from the test tool TagFileSubmitted, // and although TFA is enabled, it won't be called SetupDITfa(); byte[] tagContent; using (var tagFileStream = new FileStream(Path.Combine("TestData", "TAGFiles", "TestTAGFile.tag"), FileMode.Open, FileAccess.Read)) { tagContent = new byte[tagFileStream.Length]; tagFileStream.Read(tagContent, 0, (int)tagFileStream.Length); } var td = new TagFileDetail() { assetId = Guid.NewGuid(), projectId = Guid.NewGuid(), tagFileName = "Test.tag", tagFileContent = tagContent, tccOrgId = "", IsJohnDoe = false }; var result = TagfileValidator.PreScanTagFile(td, out var tagFilePreScan); Assert.Equal("success", result.Message); Assert.NotNull(tagFilePreScan); Assert.Equal("0523J019SW", tagFilePreScan.HardwareID); result = await TagfileValidator.ValidSubmission(td, tagFilePreScan).ConfigureAwait(false); Assert.True(result.Code == (int)TRexTagFileResultCode.Valid, "Failed to return a Valid request"); Assert.Equal("success", result.Message); }
public async Task Test_ValidateFailed_InvalidManualProjectType() { var projectUid = Guid.NewGuid(); var moqRequest = new GetProjectUidsRequest(projectUid.ToString(), string.Empty, 0, 0); var moqResult = new GetProjectUidsResult(string.Empty, string.Empty, string.Empty, 3044, "Manual Import: cannot import to a Civil type project"); SetupDITfa(true, moqRequest, moqResult); byte[] tagContent; using (var tagFileStream = new FileStream(Path.Combine("TestData", "TAGFiles", "TestTAGFile.tag"), FileMode.Open, FileAccess.Read)) { tagContent = new byte[tagFileStream.Length]; tagFileStream.Read(tagContent, 0, (int)tagFileStream.Length); } var td = new TagFileDetail() { assetId = null, projectId = projectUid, tagFileName = "Test.tag", tagFileContent = tagContent, tccOrgId = "", IsJohnDoe = false }; var tagFilePreScan = new TAGFilePreScan(); await using (var stream = new MemoryStream(td.tagFileContent)) tagFilePreScan.Execute(stream); var result = await TagfileValidator.ValidSubmission(td, tagFilePreScan).ConfigureAwait(false); Assert.True(result.Code == 3044, "Failed to return correct error code"); Assert.Equal("Manual Import: cannot import to a Civil type project", result.Message); }
public async Task Test_UsingNEE_ValidateOk() { var projectUid = Guid.NewGuid(); var moqRequest = new GetProjectUidsRequest(projectUid.ToString(), "1639J101YU", 0, 0, 5876814.5384829007, 7562822.7801738745); var moqResult = new GetProjectUidsResult(projectUid.ToString(), string.Empty, string.Empty, 0, "success"); SetupDITfa(true, moqRequest, moqResult); byte[] tagContent; using (var tagFileStream = new FileStream(Path.Combine("TestData", "TAGFiles", "SeedPosition-usingNEE.tag"), FileMode.Open, FileAccess.Read)) { tagContent = new byte[tagFileStream.Length]; tagFileStream.Read(tagContent, 0, (int)tagFileStream.Length); } var td = new TagFileDetail() { assetId = null, projectId = projectUid, tagFileName = "Bug ccssscon-401 NEE SeedPosition.tag", tagFileContent = tagContent, tccOrgId = "", IsJohnDoe = false }; var tagFilePreScan = new TAGFilePreScan(); await using (var stream = new MemoryStream(td.tagFileContent)) tagFilePreScan.Execute(stream); var result = await TagfileValidator.ValidSubmission(td, tagFilePreScan).ConfigureAwait(false); Assert.True(result.Code == (int)TRexTagFileResultCode.Valid, "Failed to return a Valid request"); Assert.Equal("success", result.Message); }
/// <summary> /// Receive a TAG file to be processed, validate TAG File Authorization for the file, and add it to the /// queue to be processed. /// </summary> /// <param name="projectId">Project ID to be used as an override to any project ID that may be determined via TAG file authorization</param> /// <param name="assetId">Asset ID to be used as an override to any Asset ID that may be determined via TAG file authorization</param> /// <param name="tagFileName">Name of the physical tag file for archiving and logging</param> /// <param name="tagFileContent">The content of the TAG file to be processed, expressed as a byte array</param> /// <param name="tccOrgId">Used by TFA service to match VL customer to TCC org when looking for project if multiple projects and/or machine ID not in tag file</param> /// <param name="treatAsJohnDoe">The TAG file will be processed as if it were a john doe machine is projectId is also specified</param> /// <param name="tagFileSubmissionFlags">A flag set controlling how certain aspects of managing a submitted TAG file should be managed</param> /// <param name="originSource">Indictaes the system of origin this file came from</param> public async Task <SubmitTAGFileResponse> ExecuteAsync(Guid?projectId, Guid?assetId, string tagFileName, byte[] tagFileContent, string tccOrgId, bool treatAsJohnDoe, TAGFileSubmissionFlags tagFileSubmissionFlags, TAGFileOriginSource originSource) { if (OutputInformationalRequestLogging) { _log.LogInformation($"#In# SubmitTAGFileResponse. Processing {tagFileName} TAG file into ProjectUID:{projectId}, asset:{assetId}, John Doe?:{treatAsJohnDoe}, submission flags: {tagFileSubmissionFlags}, origin source:{originSource}"); } var response = new SubmitTAGFileResponse { FileName = tagFileName, Success = false, Message = "TRex unknown result (SubmitTAGFileResponse.Execute)", Code = (int)TRexTagFileResultCode.TRexUnknownException, }; try { try { // wrap up details into obj var td = new TagFileDetail { assetId = assetId, projectId = projectId, tagFileName = tagFileName, tagFileContent = tagFileContent, tccOrgId = tccOrgId, IsJohnDoe = treatAsJohnDoe }; ContractExecutionResult result; if (originSource == TAGFileOriginSource.LegacyTAGFileSource) { // Validate tag file submission result = TagfileValidator.PreScanTagFile(td, out var tagFilePreScan); if (result.Code == (int)TRexTagFileResultCode.Valid) { if (_isDeviceGatewayEnabled) { SendDeviceStatusToDeviceGateway(td, tagFilePreScan); } result = await TagfileValidator.ValidSubmission(td, tagFilePreScan); } } else { // For non legacy origins where we have no overt validation rules or need for device status notifications // note the presented file as valid for processing result = new ContractExecutionResult((int)TRexTagFileResultCode.Valid, "Success"); } response.Code = result.Code; response.Message = result.Message; if (result.Code == (int)TRexTagFileResultCode.Valid && td.projectId != null) // If OK add to process queue { // First archive the tag file if (_tagFileArchiving && tagFileSubmissionFlags.HasFlag(TAGFileSubmissionFlags.AddToArchive) // For now, GCS900/Earthworks style TAG files are the only ones archived && originSource == TAGFileOriginSource.LegacyTAGFileSource) { _log.LogInformation($"#Progress# SubmitTAGFileResponse. Archiving tag file:{tagFileName}, ProjectUID:{td.projectId}"); if (!await TagFileRepository.ArchiveTagfileS3(td)) { _log.LogError($"SubmitTAGFileResponse. Failed to archive tag file. Returning TRexQueueSubmissionError error. ProjectUID:{td.projectId}, AssetUID:{td.assetId}, Tagfile:{tagFileName}"); throw new ServiceException(HttpStatusCode.InternalServerError, new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError, $"SubmitTAGFileResponse. Failed to archive tag file {tagFileName} to S3")); } } // switch from nullable to not nullable var validProjectId = td.projectId ?? Guid.Empty; var validAssetId = td.assetId ?? Guid.Empty; if (OutputInformationalRequestLogging) { _log.LogInformation($"#Progress# SubmitTAGFileResponse. Submitting tag file to TagFileBufferQueue. ProjectUID:{validProjectId}, AssetUID:{validAssetId}, Tagfile:{tagFileName}, JohnDoe:{td.IsJohnDoe} "); } var tagKey = new TAGFileBufferQueueKey(tagFileName, validProjectId, validAssetId); var tagItem = new TAGFileBufferQueueItem { InsertUTC = DateTime.UtcNow, ProjectID = validProjectId, AssetID = validAssetId, FileName = tagFileName, Content = tagFileContent, IsJohnDoe = td.IsJohnDoe, SubmissionFlags = tagFileSubmissionFlags, OriginSource = originSource }; if (_queue == null) { throw new ServiceException(HttpStatusCode.InternalServerError, new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError, "SubmitTAGFileResponse. Processing queue not available")); } if (_queue.Add(tagKey, tagItem)) // Add tag file to queue { response.Success = true; response.Message = ""; response.Code = (int)TRexTagFileResultCode.Valid; // Commented out top reduce logging // Log.LogInformation($"Added TAG file {tagKey.FileName} representing asset {tagKey.AssetUID} within project {tagKey.ProjectUID} into the buffer queue"); } else { response.Success = false; response.Message = "SubmitTAGFileResponse. Failed to submit tag file to processing queue. Request already exists"; response.Code = (int)TRexTagFileResultCode.TRexQueueSubmissionError; _log.LogWarning(response.Message); } } else { response.Success = false; } } catch (Exception e) // catch all exceptions here { _log.LogError(e, $"#Exception# SubmitTAGFileResponse. Exception occured processing {tagFileName} Exception:"); throw new ServiceException(HttpStatusCode.InternalServerError, new ContractExecutionResult(ContractExecutionStatesEnum.InternalProcessingError, $"SubmitTAGFileResponse. Exception {e.Message}")); } } finally { if (OutputInformationalRequestLogging) { _log.LogInformation($"#Out# SubmitTAGFileResponse. Processed {tagFileName} Result: {response.Success}, Message:{response.Message} Code:{response.Code}"); } } return(response); }