public async Task ExecuteAsync() { var queryHelper = new Query(); var resourceGroupIds = GetResourceGroupIDs(); IArtifactQueries artifactQueries = new ArtifactQueries(); IImportFileParser importFileParser = new ImportFileParser(); IWorkspaceQueries workspaceQueries = new WorkspaceQueries(); IErrorQueries errorQueries = new ErrorQueries(); IMarkupTypeHelper markupTypeHelper = new MarkupTypeHelper(); var job = new ImportManagerJob( AgentID, Helper, queryHelper, DateTime.Now, resourceGroupIds, artifactQueries, importFileParser, workspaceQueries, errorQueries, markupTypeHelper); job.OnMessage += MessageRaised; try { RaiseMessage(string.Empty, 10); RaiseMessage("Enter Agent", 10); await job.ExecuteAsync(); RaiseMessage("Exit Agent", 10); RaiseMessage(string.Empty, 10); } catch (Exception ex) { //Raise an error on the agents tab and event viewer RaiseError(ex.ToString(), ex.ToString()); //Add the error to our custom Errors table queryHelper.InsertRowIntoImportErrorLogAsync(Helper.GetDBContext(-1), job.WorkspaceArtifactId, Constant.Tables.ImportManagerQueue, job.RecordId, job.AgentId, ex.ToString()).Wait(); //Add the error to the Relativity Errors tab //this second try catch is in case we have a problem connecting to the RSAPI try { errorQueries.WriteError(Helper.GetServicesManager(), ExecutionIdentity.System, job.WorkspaceArtifactId, ex); } catch (Exception rsapiException) { RaiseError(rsapiException.ToString(), rsapiException.ToString()); } //Set the status in the queue to error await queryHelper.UpdateStatusInImportManagerQueueAsync(Helper.GetDBContext(-1), Constant.Status.Queue.Error, job.RecordId); } }
public async Task ExecuteAsync_QueueHasARecord_Validate_Job_Type_Bad_Import_File_Data_Valid_Test() { // Arrange //when import manager queue has a record(s) var dataTable = GetImportManagerDataTable(Constant.ImportJobType.VALIDATE); MockRetrieveNextInImportManagerQueueAsync(dataTable); //retrieve import job var markupUtilityImportJob = GetMarkupUtilityImportJob(Constant.ImportJobType.IMPORT); MockRetrieveImportJob(markupUtilityImportJob); //update status of the import job to validating //update status of the import job to validated //update details of the import job MockUpdateRdoJobTextFieldAsync(); //read contents of the import job file var streamReader = GetBadImportFileDataFileStreamReader(); MockGetFileFieldContentsAsync(streamReader); //create an instance of ImportFileParser to parse the actual import file IImportFileParser importFileParser = new ImportFileParser(); //deletes the completed job from the Manager Queue MockRemoveRecordFromTableByIdAsync(); //pass created importFileParser var importManagerJob = GetImportManagerJob(importFileParser); // Act await importManagerJob.ExecuteAsync(); // Assert AssertRetrieveNextInImportManagerQueueAsyncWasCalled(1); AssertRetrieveImportJobAsyncWasCalled(1); AssertUpdateRdoJobTextFieldAsyncWasCalled(4); AssertGetFileFieldContentsAsyncWasCalled(1); AssertInsertRowIntoImportErrorLogAsyncWasCalled(1); AssertWriteErrorWasCalled(1); AssertRemoveRecordFromTableByIdAsyncWasCalled(1); }
public async Task ExecuteAsync_QueueHasARecord_Import_Job_Type_Bad_Import_File_Data_Valid_Test() { // Arrange //when import manager queue has a record(s) var dataTable = GetImportManagerDataTable(Constant.ImportJobType.IMPORT); MockRetrieveNextInImportManagerQueueAsync(dataTable); //Create import manager holding table MockCreateImportManagerHoldingTableAsync(); //retrieve import job var markupUtilityImportJob = GetMarkupUtilityImportJob(Constant.ImportJobType.IMPORT); MockRetrieveImportJob(markupUtilityImportJob); //update status of the import job to validating //update status of the import job to validated //update details of the import job MockUpdateRdoJobTextFieldAsync(); //read contents of the import job file var streamReader = GetBadImportFileDataFileStreamReader(); MockGetFileFieldContentsAsync(streamReader); //create an instance of ImportFileParser to parse the actual import file IImportFileParser importFileParser = new ImportFileParser(); //create an instance of IMarkupTypeHelper to parse the actual import file IMarkupTypeHelper markupTypeHelper = new MarkupTypeHelper(); //get resource group id to insert into worker queue MockGetResourcePoolAsync(); //insert import file redaction record into import manager holding table MockInsertRowsIntoImportManagerHoldingTableAsync(); //copy data from import manager holding table to import worker queue table MockCopyDataFromImportManagerHoldingTableIntoImportWorkerQueueTableAsync(); //drop import manager holding table MockDropTableAsync(); //deletes the completed job from the Manager Queue MockRemoveRecordFromTableByIdAsync(); //pass created importFileParser and markupTypeHelper var importManagerJob = GetImportManagerJob(importFileParser, markupTypeHelper); // Act await importManagerJob.ExecuteAsync(); // Assert AssertRetrieveNextInImportManagerQueueAsyncWasCalled(1); AssertCreateImportManagerHoldingTableAsyncWasCalled(1); AssertRetrieveImportJobAsyncWasCalled(1); AssertUpdateRdoJobTextFieldAsyncWasCalled(4); AssertGetFileFieldContentsAsyncWasCalled(1); AssertCopyDataFromImportManagerHoldingTableIntoImportWorkerQueueTableAsyncWasNeverCalled(); AssertGetResourcePoolAsyncWasNeverCalled(); AssertInsertRowsIntoImportManagerHoldingTableAsyncWasNeverCalled(); AssertInsertRowIntoImportErrorLogAsyncWasCalled(1); AssertWriteErrorWasCalled(1); AssertDropTableAsyncWasCalled(1); AssertRemoveRecordFromTableByIdAsyncWasCalled(1); }
private async Task ParseImportJobFileContentsAsync(StreamReader fileContentsStream) { RaiseMessage($"Parsing contents of import file for import job. {_errorContext}"); await ImportFileParser.ParseFileContentsAsync(fileContentsStream, ProcessEachLineAsync, AfterProcessingAllLinesAsync); }
private async Task ValidateImportJobFileContentsAsync(StreamReader fileContentsStream) { RaiseMessage($"Validating contents of import file for import job. {_errorContext}"); await ImportFileParser.ValidateFileContentsAsync(fileContentsStream); }