Example #1
0
        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);
            }
        }
        private async Task <Boolean> ProcessEachLineAsync(ImportFileRecord importFileRecord)
        {
            Boolean retVal = false;

            try
            {
                if (importFileRecord != null)
                {
                    int resourceGroupId = await WorkspaceQueryHelper.GetResourcePoolAsync(AgentHelper.GetServicesManager(), ExecutionIdentity.System, WorkspaceArtifactId);

                    //get selected markup sub types in the import job
                    List <int> selectedMarkupSubTypes = _markupUtilityImportJob
                                                        .MarkupUtilityTypes
                                                        .Select(x =>
                                                                MarkupTypeHelper.GetMarkupSubTypeValueAsync(x.Name).Result)
                                                        .ToList();

                    //insert into import manager holding table only if the sub type is selected in the import job
                    if (selectedMarkupSubTypes.Contains(importFileRecord.MarkupSubType))
                    {
                        await QueryHelper.InsertRowIntoImportManagerHoldingTableAsync(
                            AgentHelper.GetDBContext(-1),
                            WorkspaceArtifactId,
                            importFileRecord.DocumentIdentifier,
                            importFileRecord.FileOrder,
                            resourceGroupId,
                            _markupUtilityImportJob.ArtifactId,
                            _markupUtilityImportJob.MarkupSetArtifactId,
                            _markupUtilityImportJob.JobType,
                            importFileRecord,
                            _markupUtilityImportJob.SkipDuplicateRedactions,
                            ImportManagerHoldingTable);

                        _expectedRedactionCount++;
                    }

                    retVal = true;
                }
            }
            catch (Exception ex)
            {
                throw new MarkupUtilityException("An error occured when inserting redaction record to the import manager holding table.", ex);
            }
            finally
            {
                _importFileRedactionCount++;

                if (_importFileRedactionCount % 100 == 0)
                {
                    RaiseMessage($"Parsed {_importFileRedactionCount} records in import file.");
                }
            }

            return(retVal);
        }
        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);
        }