Example #1
0
        /// <summary>
        /// Get search results...
        /// </summary>
        public void GetSearchResults()
        {
            if (string.IsNullOrEmpty(_mCollectionId))
            {
                return;
            }
            //Get the dataset id

            var dataSet = DataSetBO.GetDataSetDetailForCollectionId(_mCollectionId);

            dataSet.ShouldNotBe(null);
            var dataSetId = dataSet.FolderID.ToString(CultureInfo.InvariantCulture);
            //Construct query
            var query = _mBootParameters.BulkPrintOptions.FilterOption.FilterQuery;
            var documentFilterType = _mBootParameters.BulkPrintOptions.FilterOption.DocumentFilterType;
            var index = documentFilterType == DocumentFilterTypeBEO.SavedSearch
                ? query.LastIndexOf(Constants.IsConceptSearchingEnabled, StringComparison.Ordinal)
                : 0;
            var enableConceptSearch = documentFilterType == DocumentFilterTypeBEO.SavedSearch &&
                                      bool.Parse(
                query.Substring(
                    query.LastIndexOf(Constants.IsConceptSearchingEnabled,
                                      StringComparison.Ordinal) + 30, 5).Trim());
            var includeFamilyThread = documentFilterType == DocumentFilterTypeBEO.SavedSearch &&
                                      (query.Substring(
                                           query.LastIndexOf(Constants.IncludeFamily, StringComparison.Ordinal) + 18, 4)
                                       .Contains(Constants.True));

            query = documentFilterType == DocumentFilterTypeBEO.SavedSearch ? query.Substring(0, index - 1) : query;

            var documentQueryEntity = new DocumentQueryEntity
            {
                QueryObject = new SearchQueryEntity
                {
                    ReviewsetId            = string.Empty,
                    DatasetId              = Convert.ToInt32(dataSetId),
                    MatterId               = Convert.ToInt32(_mBootParameters.DataSet.MatterId),
                    IsConceptSearchEnabled = enableConceptSearch
                },
                IgnoreDocumentSnippet = true
            };

            documentQueryEntity.QueryObject.QueryList.Add(new Query(query));
            documentQueryEntity.OutputFields.Add(new Field {
                FieldName = EVSystemFields.DcnField
            });
            documentQueryEntity.SortFields.Add(new Sort {
                SortBy = Constants.SearchResultsSortByRelevance
            });
            documentQueryEntity.TransactionName = "PrintStartupWorker - GetSearchResults";

            //Fetch search results
            _mSearchResults = JobSearchHandler.GetAllDocuments(documentQueryEntity, includeFamilyThread);
        }
        /// <summary>
        /// Atomic work 1)Get old search result 2)New Search 3) Compare 4) generate report to database.
        /// </summary>
        /// <param name="task"></param>
        /// <param name="jobParameters"></param>
        /// <returns></returns>
        protected override bool DoAtomicWork(CompareSavedSearchResultsJobTaskEntity task,
                                             CompareSavedSearchResultsJobBEO jobParameters)
        {
            task.ShouldNotBe(null);
            jobParameters.ShouldNotBe(null);
            var queryContext = _searchResultsProperty.DocumentQuery;

            queryContext.DocumentStartIndex    = 0;
            queryContext.DocumentCount         = 1;
            queryContext.IgnoreDocumentSnippet = true;
            queryContext.OutputFields.Clear();
            queryContext.OutputFields.Add(new Field {
                FieldName = EVSystemFields.DcnField
            });
            try
            {
                LogMessage(string.Format(Constants.DoAtomicWorkStartMessage, task.TaskNumber), GetType(),
                           Constants.DoAtomicMethodFullName, EventLogEntryType.Information, jobParameters.JobId,
                           jobParameters.JobRunId);
                switch (task.TaskType)
                {
                case TypeOfTask.FetchRecordFromDb:
                {
                    var searchResultuuid = string.Format(SaveSearchResultIdentifierBEO.UniqueIdentifierFormat,
                                                         _searchResultsProperty.DocumentQuery.QueryObject.MatterId,
                                                         _searchResultsProperty.DocumentQuery.QueryObject.DatasetId,
                                                         _searchResultsProperty.SearchResultId);
                    _oldSearchResult = SearchResultsService.GetSavedSearchResultsWithDocument(searchResultuuid);
                }
                break;

                case TypeOfTask.FetchRecordFromSearchSubSystem:
                {
                    LogMessage(string.Format("New Search start at : {0}",
                                             DateTime.UtcNow.ConvertToUserTime()), GetType(), Constants.DoAtomicMethodFullName,
                               EventLogEntryType.Information, jobParameters.JobId, jobParameters.JobRunId);

                    //SearchContextObject searchContextObject = ConvertToSearchContextObject(queryContext);
                    ReviewerSearchResults rvwSearchBeo;
                    queryContext.QueryObject.TransactionName =
                        "CompareSavedSearchResultsJob - DoAtomicWork (GetCount)";
                    var totalResultCount = JobSearchHandler.GetSearchResultsCount(queryContext.QueryObject);
                    //searchContextObject.ItemsPerPage = totalResultCount;
                    queryContext.DocumentCount   = (int)totalResultCount;
                    queryContext.TransactionName = "CompareSavedSearchResultsJob - DoAtomicWork (GetAll)";
                    rvwSearchBeo = JobSearchHandler.GetAllDocuments(queryContext, false);
                    // Getting search result list by page index
                    LogMessage(string.Format("New Search End at : {0}", DateTime.UtcNow.ConvertToUserTime()),
                               GetType(), Constants.DoAtomicMethodFullName, EventLogEntryType.Information,
                               jobParameters.JobId, jobParameters.JobRunId);
                    //Constructing New search Result Beo
                    _newSearchResult = new SearchResultsDataContract
                    {
                        Information = new SearchResultsInformationDataContract
                        {
                            Properties =
                                new SearchResultsPropertiesDataContract
                            {
                                SearchResultId           = _searchResultsProperty.SearchResultId,
                                SearchResultsName        = _searchResultsProperty.SearchResultsName,
                                SearchResultsDescription = _searchResultsProperty.SearchResultsDescription,
                                DocumentQuery            = _searchResultsProperty.DocumentQuery
                            },
                            CreatedBy   = _userEntityOfJobOwner.UserId,
                            CreatedDate = DateTime.UtcNow.ConvertToUserTime()
                        }
                    };
                    if (rvwSearchBeo != null)
                    {
                        if (rvwSearchBeo.ResultDocuments != null && rvwSearchBeo.ResultDocuments.Any())
                        {
                            //int totalHitCount = 0;
                            foreach (var document in rvwSearchBeo.ResultDocuments)
                            {
                                var documentDeatail = new SearchResultDocumentDetailsDataContract();
                                documentDeatail.DocumentId            = document.DocumentID;
                                documentDeatail.DocumentControlNumber = document.DocumentControlNumber;
                                documentDeatail.NativeFilePath        = GetNativeFilePath(document);
                                _newSearchResult.Details.Add(documentDeatail);
                            }
                            _newSearchResult.Information.NumberOfDocuments = rvwSearchBeo.ResultDocuments.Count;
                        }
                    }
                    LogMessage(string.Format("New Search Results Construction done at : {0}",
                                             DateTime.UtcNow.ConvertToUserTime()), GetType(), Constants.DoAtomicMethodFullName,
                               EventLogEntryType.Information, jobParameters.JobId, jobParameters.JobRunId);
                }
                break;

                case TypeOfTask.CompareRecords:
                {
                    var comparisonStart = DateTime.Now;
                    _savedSearchCompareReport = new SavedSearchCompareReportBEO();
                    LogMessage(string.Format("Comparison Start at: {0}", DateTime.UtcNow.ConvertToUserTime()),
                               GetType(), Constants.DoAtomicMethodFullName, EventLogEntryType.Information,
                               jobParameters.JobId, jobParameters.JobRunId);
                    var oldResultSet = new List <SearchResultsDetailBEO>();
                    var newResultSet = new List <SearchResultsDetailBEO>();
                    _oldSearchResult.Details.SafeForEach(x => oldResultSet.Add(x.ToBusinessEntity()));
                    _newSearchResult.Details.SafeForEach(x => newResultSet.Add(x.ToBusinessEntity()));

                    // Extracting Common document details
                    (newResultSet.Intersect(oldResultSet).ToList()).SafeForEach(x =>
                                                                                _savedSearchCompareReport.CommonDocumentSet.Add(x));
                    //Extracting Unique document details from new Search result
                    (newResultSet.Except(_savedSearchCompareReport.CommonDocumentSet).ToList()).
                    SafeForEach(x => _savedSearchCompareReport.DocumentsOnlyInNewResultSet.Add(x));
                    //Extracting Unique document details from old(Saved) Search result
                    (oldResultSet.Except(_savedSearchCompareReport.CommonDocumentSet).ToList()).
                    SafeForEach(x => _savedSearchCompareReport.DocumentOnlyInOldResultSet.Add(x));
                    var comparisonStop = DateTime.Now;
                    LogMessage(string.Format("Total Time taken for comparison: {0}",
                                             (comparisonStop - comparisonStart).Milliseconds), GetType(),
                               Constants.DoAtomicMethodFullName, EventLogEntryType.Information, jobParameters.JobId,
                               jobParameters.JobRunId);
                }
                break;

                case TypeOfTask.ConstructFileContent:
                {
                    LogMessage(
                        string.Format("File Construction start at: {0}", DateTime.UtcNow.ConvertToUserTime()),
                        GetType(), Constants.DoAtomicMethodFullName, EventLogEntryType.Information,
                        jobParameters.JobId, jobParameters.JobRunId);

                    //Saving Old search results information
                    _savedSearchCompareReport.OldResultDetails = new SearchResultsInformationBEO
                    {
                        CreatedBy          = _oldSearchResult.Information.CreatedBy,
                        CreatedDate        = _oldSearchResult.Information.CreatedDate,
                        NumberOfDocuments  = _oldSearchResult.Information.NumberOfDocuments,
                        NumberOfSearchHits = _oldSearchResult.Information.NumberOfSearchHits
                    };
                    //Saving Old search results information
                    _savedSearchCompareReport.NewResultDetails = new SearchResultsInformationBEO
                    {
                        CreatedBy          = _newSearchResult.Information.CreatedBy,
                        CreatedDate        = _newSearchResult.Information.CreatedDate,
                        NumberOfDocuments  = _newSearchResult.Information.NumberOfDocuments,
                        NumberOfSearchHits = _newSearchResult.Information.NumberOfSearchHits
                    };
                    _savedSearchCompareReport.CreatedBy       = _userEntityOfJobOwner.UserId;
                    _savedSearchCompareReport.SearchQueryTerm = queryContext.QueryObject.DisplayQuery;
                    _savedSearchCompareReport.CreatedDate     = DateTime.UtcNow.ConvertToUserTime();
                    //File Creation Logic
                    CreateReportFile(out _reportString);
                    LogMessage(string.Format("File Construction End at: {0}", DateTime.UtcNow.ConvertToUserTime()),
                               GetType(), Constants.DoAtomicMethodFullName, EventLogEntryType.Information,
                               jobParameters.JobId, jobParameters.JobRunId);
                    //Clean up all class level variable
                    _oldSearchResult = null;
                    _newSearchResult = null;
                }
                break;
                }
            }
            catch (EVException ex)
            {
                _isJobFailed = true;
                WriteToEventViewer(ex, GetType(), MethodBase.GetCurrentMethod().Name, jobParameters.JobId,
                                   jobParameters.JobRunId);
                HandleTaskException(null, string.Format(Constants.TaskKeyStringFormat, task.TaskType),
                                    ErrorCodes.ProblemInDoAtomicWork);
            }
            catch (Exception ex)
            {
                _isJobFailed = true;
                // Handle exception in DoAutomic
                LogMessage(ex, GetType(), MethodBase.GetCurrentMethod().Name, EventLogEntryType.Error,
                           jobParameters.JobId, jobParameters.JobRunId);
                HandleTaskException(ex, string.Format(Constants.TaskKeyStringFormat, task.TaskType),
                                    ErrorCodes.ProblemInDoAtomicWork);
            }
            return(true);
        }
        /// <summary>
        /// Does atomic 1)Gets document links2) Generate xml 3) Update xml file to database.
        /// </summary>
        /// <param name="task">ConvertDCBLinkTaskBusinessEntityObject</param>
        /// <param name="jobParameters">Job business entity</param>
        /// <returns></returns>
        protected override bool DoAtomicWork(SendDocumentLinksToCaseMapTaskBusinessEntity Task, BaseJobBEO jobParameters)
        {
            var StatusFlag = true; // Function return status.

            try
            {
                EvLog.WriteEntry(
                    Constants.JobTypeName + " - " + jobParameters.JobRunId.ToString(CultureInfo.InvariantCulture),
                    Constants.Event_Job_DoAtomicWork_Start, EventLogEntryType.Information);
                var xml        = string.Empty;
                var taskEntity =
                    (SendDocumentLinksToCaseMapTaskBusinessEntity)
                    XmlUtility.DeserializeObject(jobParameters.BootParameters,
                                                 typeof(SendDocumentLinksToCaseMapTaskBusinessEntity));
                switch (taskEntity.CaseMapSource)
                {
                case SendDocumentLinksToCaseMapTaskBusinessEntity.Source.SearchResults:
                {
                    var documentLinks = new List <DocumentLinkBEO>();
                    if (taskEntity.DocumentLinkTasks.DocumentSelectionMode ==
                        DocumentLinksTaskEntity.SelectionMode.UseSelection &&
                        taskEntity.DocumentLinkTasks.DocumentIdList != null)
                    {
                        documentLinks.AddRange(taskEntity.DocumentLinkTasks.DocumentIdList.Select(documentId =>
                                                                                                  getDocumentLink(taskEntity.DocumentLinkTasks.SearchContext.MatterId,
                                                                                                                  taskEntity.DocumentLinkTasks.SearchContext.CollectionId,
                                                                                                                  documentId, taskEntity.DocumentLinkTasks.BaseLink,
                                                                                                                  DocumentBO.GetDCNNumber(taskEntity.DocumentLinkTasks.SearchContext.MatterId,
                                                                                                                                          taskEntity.DocumentLinkTasks.SearchContext.CollectionId,
                                                                                                                                          documentId, jobParameters.JobScheduleCreatedBy
                                                                                                                                          )
                                                                                                                  )));
                    }
                    else
                    {
                        var documentQueryEntity = new DocumentQueryEntity
                        {
                            QueryObject = new SearchQueryEntity
                            {
                                ReviewsetId            = taskEntity.DocumentLinkTasks.SearchContext.ReviewsetId,
                                DatasetId              = Convert.ToInt32(taskEntity.DocumentLinkTasks.SearchContext.DatasetId),
                                MatterId               = Convert.ToInt32(taskEntity.DocumentLinkTasks.SearchContext.MatterId),
                                IsConceptSearchEnabled =
                                    taskEntity.DocumentLinkTasks.SearchContext.EnableConceptSearch
                            }
                        };
                        documentQueryEntity.QueryObject.QueryList.Add(
                            new Query(taskEntity.DocumentLinkTasks.SearchContext.Query));
                        documentQueryEntity.SortFields.Add(new Sort {
                                SortBy = Constants.Relevance
                            });
                        documentQueryEntity.IgnoreDocumentSnippet = true;
                        documentQueryEntity.TransactionName       = "SendDocumentLinksToCaseMap - DoAtomicWork";
                        var searchResults = JobSearchHandler.GetAllDocuments(documentQueryEntity, false);
                        if (taskEntity.DocumentLinkTasks.DocumentIdList != null &&
                            taskEntity.DocumentLinkTasks.DocumentIdList.Count > 0)
                        {
                            documentLinks =
                                searchResults.ResultDocuments.Where(
                                    x =>
                                    taskEntity.DocumentLinkTasks.DocumentIdList.Find(
                                        y => string.Compare(x.DocumentID, y, true) == 0) == null).
                                Select(
                                    z =>
                                    getDocumentLink(z.MatterID.ToString(), z.CollectionID, z.DocumentID,
                                                    taskEntity.DocumentLinkTasks.BaseLink, z.DocumentControlNumber)
                                    ).ToList();
                        }
                        else
                        {
                            searchResults.ResultDocuments.SafeForEach(d => documentLinks.Add(
                                                                          getDocumentLink(d.MatterID.ToString(), d.CollectionID, d.DocumentID,
                                                                                          taskEntity.DocumentLinkTasks.BaseLink, d.DocumentControlNumber)));
                        }
                    }


                    fileType = ApplicationConfigurationManager.GetValue(Constants.SearchResultsFileType);
                    xml      = DocumentFactBusinessObject.GenerateDocumentLinksXml(documentLinks,
                                                                                   jobParameters.JobScheduleCreatedBy);

                    break;
                }

                case SendDocumentLinksToCaseMapTaskBusinessEntity.Source.DocumentViewer:
                {
                    var documentFactLinks = taskEntity.DocumentFactLinks;
                    fileType = ApplicationConfigurationManager.GetValue(Constants.DocumentViewerFileType);
                    xml      = DocumentFactBusinessObject.GenerateDocumentFactXml(documentFactLinks,
                                                                                  jobParameters.JobScheduleCreatedBy);

                    break;
                }

                case SendDocumentLinksToCaseMapTaskBusinessEntity.Source.NearNative:
                {
                    var documentFactLinks = taskEntity.DocumentFactLinks;
                    fileType = ApplicationConfigurationManager.GetValue(Constants.NearNativeFileType);
                    xml      = DocumentFactBusinessObject.GenerateDocumentFactXml(documentFactLinks,
                                                                                  jobParameters.JobScheduleCreatedBy);

                    break;
                }
                }

                // Perform Atomic Task
                var encoding    = new UTF8Encoding();
                var content     = encoding.GetBytes(xml);
                var nameBuilder = new StringBuilder();
                nameBuilder.Append(Constants.TaskName);
                nameBuilder.Append(Constants.OnDate);
                nameBuilder.Append(startedTime.ConvertToUserTime());
                var requestName = nameBuilder.ToString();

                nameBuilder = new StringBuilder();
                nameBuilder.Append(Constants.TaskName);
                nameBuilder.Append(Constants.RequestByUser);
                nameBuilder.Append(jobParameters.JobScheduleCreatedBy);
                nameBuilder.Append(Constants.OnDate);
                nameBuilder.Append(startedTime.ConvertToUserTime());
                requestDescription = nameBuilder.ToString();


                conversionId = CaseMapDAO.SaveConversionResults(jobParameters.JobRunId, requestName, requestDescription,
                                                                content, fileType, createdByUserGuid);
                StatusFlag = true;
                EvLog.WriteEntry(Constants.JobTypeName + " - " + jobParameters.JobRunId,
                                 Constants.Event_Job_DoAtomicWork_Success, EventLogEntryType.Information);
            }
            catch (EVTaskException ex)
            {
                isJobFailed = true;
                EvLog.WriteEntry(Constants.JobTypeName + MethodBase.GetCurrentMethod().Name, ex.Message,
                                 EventLogEntryType.Error);
                LogException(TaskLogInfo, ex, LogCategory.Task, ErrorCodes.ProblemInDoAtomicWork, string.Empty);
            }
            catch (Exception ex)
            {
                isJobFailed = true;
                // Handle exception in Generate Tasks
                EvLog.WriteEntry(Constants.JobTypeName + MethodBase.GetCurrentMethod().Name, ex.Message,
                                 EventLogEntryType.Error);
                LogException(TaskLogInfo, ex, LogCategory.Task, ErrorCodes.ProblemInDoAtomicWork, string.Empty);
            }
            return(StatusFlag);
        }
Example #4
0
        /// <summary>
        /// Generates No.of Reviewsets to be created tasks
        /// </summary>
        /// <param name="jobParameters">Create Reviewset BEO</param>
        /// <param name="lastCommitedTaskCount">int</param>
        /// <returns>List of Create ReviewsetJob Tasks (BEOs)</returns>
        protected override Tasks <MergeReviewSetTaskBEO> GenerateTasks(MergeReviewSetJobBEO jobParameters, out int lastCommitedTaskCount)
        {
            Tasks <MergeReviewSetTaskBEO> tasks = new Tasks <MergeReviewSetTaskBEO>();

            lastCommitedTaskCount = 0;
            try
            {
                if (jobParameters != null)
                {
                    string datasetId = jobParameters.DatasetId.ToString(CultureInfo.InvariantCulture);
                    /* Get Dataset Details for dataset id to get know about the Collection id and the Matter ID*/
                    DatasetBEO datasetEntity = DataSetService.GetDataSet(datasetId);
                    string     sMatterId     = datasetEntity.Matter.FolderID.ToString(CultureInfo.InvariantCulture);
                    jobParameters.Activity = Constants.Create;

                    List <RVWDocumentBEO>        docList      = new List <RVWDocumentBEO>();
                    List <MergeReviewSetTaskBEO> mergedRsList = new List <MergeReviewSetTaskBEO>();

                    foreach (string reviewsetId in jobParameters.MergedReviewSetIds)
                    {
                        ReviewsetDetailsBEO reviewsetDetailsBeo = ReviewSetService.GetReviewSetDetails(sMatterId, reviewsetId);

                        ReviewerSearchResults qualifiedDocuments = new ReviewerSearchResults();
                        jobParameters.ReviewSetId = reviewsetId;
                        var queryContext = ConstructDocQueryEntity(jobParameters, datasetEntity);
                        queryContext.TransactionName = "MergeReviewSetJob - DoAtomicWork";
                        ReviewerSearchResults searchDocs = JobSearchHandler.GetAllDocuments(queryContext, false);

                        if (searchDocs != null)
                        {
                            searchDocs.ResultDocuments.SafeForEach(x => qualifiedDocuments.ResultDocuments.Add(x));
                        }

                        List <RVWDocumentBEO> iterationDocuments = qualifiedDocuments.ResultDocuments.
                                                                   Select(d => new RVWDocumentBEO
                        {
                            DocumentId   = d.DocumentID,
                            MatterId     = d.MatterID,
                            CollectionId = d.CollectionID,
                            FamilyId     = d.FamilyID
                        }).ToList();

                        reviewsetDetailsBeo.Documents.Clear();
                        reviewsetDetailsBeo.Documents.AddRange(iterationDocuments);
                        reviewsetDetailsBeo.StatusId = 2;
                        MergeReviewSetTaskBEO mReviewsetDetailsBeo = ConvertToTaskBeo(reviewsetDetailsBeo);
                        docList.AddRange(reviewsetDetailsBeo.Documents);
                        mergedRsList.Add(mReviewsetDetailsBeo);
                    }
                    jobParameters.Documents.AddRange(docList);
                    tasks.Add(mergedRsList);
                    MergeReviewSetTaskBEO lstUpdateReviewSetTaskBeo = ConvertToTaskBeo(jobParameters);
                    tasks.Add(lstUpdateReviewSetTaskBeo);

                    for (int i = 1; i <= tasks.Count; i++)
                    {
                        tasks[i - 1].TaskNumber = i;
                    }
                }
                else
                {
                    lastCommitedTaskCount = 0;
                    EvLog.WriteEntry(Constants.JobLogName + Constants.GenerateTasks, Constants.JobParamND, EventLogEntryType.Error);
                    JobLogInfo.AddParameters(Constants.JobParamND);
                    JobLogInfo.IsError = true;
                }
            }
            catch (Exception ex)
            {
                LogException(JobLogInfo, ex, LogCategory.Job, string.Empty, ErrorCodes.ProblemInGenerateTasks);
            }
            return(tasks);
        }