Example #1
0
        /// <summary>
        /// Get service uri
        /// </summary>
        /// <param name="datasetId">Datase Id</param>
        /// <param name="searchQuery">Search Query</param>
        /// <param name="pageSize">Size of the page results</param>
        /// <returns>Uri for Search results</returns>
        private DocumentQueryEntity GetDocumentQueryEntity(string datasetId, string searchQuery, string pageSize)
        {
            DocumentQueryEntity documentQueryEntity = new DocumentQueryEntity
            {
                DocumentStartIndex = 0,
                QueryObject        = new SearchQueryEntity
                {
                    DatasetId = Convert.ToInt32(datasetId),
                    IsConceptSearchEnabled = false
                }
            };

            documentQueryEntity.QueryObject.QueryList.Add(new Query(searchQuery));
            documentQueryEntity.IgnoreDocumentSnippet = true;

            int docCount = 0;

            Int32.TryParse(pageSize, out docCount);
            if (docCount <= 0)
            {
                docCount = 1;
            }
            documentQueryEntity.DocumentCount = docCount;
            return(documentQueryEntity);
        }
Example #2
0
        /// <summary>
        /// Constructs the doc query entity.
        /// </summary>
        /// <param name="jobParameters">The job parameters.</param>
        /// <param name="datasetEntity">The dataset entity.</param>
        /// <returns></returns>
        private static DocumentQueryEntity ConstructDocQueryEntity(CreateReviewSetJobBEO jobParameters, DatasetBEO datasetEntity)
        {
            DocumentQueryEntity documentQueryEntity = new DocumentQueryEntity
            {
                QueryObject = new SearchQueryEntity
                {
                    ReviewsetId            = jobParameters.ReviewSetId,
                    MatterId               = datasetEntity.Matter.FolderID,
                    IsConceptSearchEnabled = false,
                    DatasetId              = datasetEntity.FolderID
                }
            };

            documentQueryEntity.IgnoreDocumentSnippet = true;
            documentQueryEntity.SortFields.Add(new Sort {
                SortBy = Constants.Relevance
            });
            documentQueryEntity.OutputFields.AddRange(new List <Field>
            {
                new Field {
                    FieldName = EVSystemFields.FamilyId
                },
                new Field {
                    FieldName = EVSystemFields.ReviewSetId
                },
                new Field {
                    FieldName = datasetEntity.DocumentControlNumberName
                },
                new Field {
                    FieldName = EVSystemFields.DuplicateId
                },
            });
            return(documentQueryEntity);
        }
        /// <summary>
        /// Absorb the boot parameters, deserialize and pass on the messages to the Search Worker
        /// </summary>
        public void DoBeginWork(string bootParameter)
        {
            bootParameter.ShouldNotBeEmpty();
            // Deserialize and determine the boot object
            _mBootObject = GetBootObject(bootParameter);
            _mBootObject.ShouldNotBe(null);

            _mBootObject.TagDetails.ShouldNotBe(null);
            _mBootObject.TagDetails.Id.ShouldBeGreaterThan(0);
            _mBootObject.TagDetails.MatterId.ShouldBeGreaterThan(0);
            _mBootObject.TagDetails.CollectionId.ShouldNotBeEmpty();

            _mBootObject.DocumentListDetails.ShouldNotBe(null);
            _mBootObject.DocumentListDetails.SearchContext.ShouldNotBe(null);

            _mBootObject.DocumentListDetails.SearchContext.MatterId.ShouldBeGreaterThan(0);
            _mBootObject.JobScheduleCreatedBy.ShouldNotBeEmpty();
            MockSession(_mBootObject.JobScheduleCreatedBy);

            // Fetch tag details
            _mTagDetails = RvwTagService.GetTag(_mBootObject.TagDetails.Id.ToString(CultureInfo.InvariantCulture),
                                                _mBootObject.TagDetails.CollectionId,
                                                _mBootObject.TagDetails.MatterId.ToString(
                                                    CultureInfo.InvariantCulture));

            if (_mTagDetails == null)
            {
                throw new Exception("Given tag does not exists");
            }

            if (!_mTagDetails.Status)
            {
                throw new Exception(string.Format("Tag {0} does not exists in active state", _mTagDetails.TagDisplayName));
            }

            _mSearchContext = GetSearchContext(_mBootObject, true, false);

            var documents = GetDocuments(_mSearchContext);

            if (!documents.Any())
            {
                LogMessage(true,
                           String.Format("Tag Startup Worker : No document(s) qualified to tag {0} for the job run id : {1}",
                                         _mTagDetails.Name, PipelineId));
                return;
            }

            //// Retrieve the total documents qualified
            _mTotalDocumentCount = documents.Count;
            var strMsg = String.Format("{0} documents are qualified to tag {1} for the job run id : {2}",
                                       _mTotalDocumentCount, _mTagDetails.Name, PipelineId);

            LogMessage(false, strMsg);

            // Group the results and send it in batches
            GroupDocumentsAndSend(documents);
        }
Example #4
0
        /// <summary>
        /// Converts Data row returned by stored procedure to a Task object
        /// </summary>
        /// <param name="datarow">Data row to be converted</param>
        /// <returns>Converted Task object returned</returns>
        private SearchAlertsTaskBEO ConvertToTask(DataRow datarow)
        {
            SearchAlertsTaskBEO searchAlertsTaskBeo;

            try
            {
                DocumentQueryEntity tmpSearchContext = null;
                if (!datarow[Constants.GA_SEARCH_QUERY].Equals(DBNull.Value))
                {
                    tmpSearchContext = (DocumentQueryEntity)XmlUtility.DeserializeObject
                                           (datarow[Constants.GA_SEARCH_QUERY].ToString(), typeof(DocumentQueryEntity));
                }

                searchAlertsTaskBeo = new SearchAlertsTaskBEO
                {
                    SearchAlert = new SearchAlertEntity
                    {
                        AlertId = (datarow[Constants.GA_SEARCH_ALERT_ID].Equals(DBNull.Value))
                                ? Constants.INTEGER_INITIALIZE_VALUE
                                : Convert.ToInt64(datarow[Constants.GA_SEARCH_ALERT_ID]),
                        Duration = (datarow[Constants.GA_DURATION_IN_MINUTES].Equals(DBNull.Value))
                                ? Constants.INTEGER_INITIALIZE_VALUE
                                : Convert.ToInt32(datarow[Constants.GA_DURATION_IN_MINUTES]),
                        LastRunDate = (datarow[Constants.GA_LAST_RUN_DATE].Equals(DBNull.Value))
                                    ? Constants.MSSQL2005_MINDATE
                                    : Convert.ToDateTime(datarow[Constants.GA_LAST_RUN_DATE]),
                        Name = (datarow[Constants.GA_SEARCH_ALERT_NAME].Equals(DBNull.Value))
                                ? string.Empty
                                : datarow[Constants.GA_SEARCH_ALERT_NAME].ToString(),
                        NextRunDate = (datarow[Constants.GA_NEXT_RUN_DATE].Equals(DBNull.Value))
                                ? Constants.MSSQL2005_MINDATE
                                : Convert.ToDateTime(datarow[Constants.GA_NEXT_RUN_DATE].ToString().Trim()),
                        NotificationId = (datarow[Constants.GA_NOTIFICATION_ID].Equals(DBNull.Value))
                                ? Constants.INTEGER_INITIALIZE_VALUE
                                : Convert.ToInt64(datarow[Constants.GA_NOTIFICATION_ID]),
                        OwnerId = (datarow[Constants.GA_OWNER_ID].Equals(DBNull.Value))
                                ? string.Empty
                                : datarow[Constants.GA_OWNER_ID].ToString(),
                        ActualOccurrenceCount = (datarow[Constants.GA_ACUAL_OCCURANCE_COUNT].Equals(DBNull.Value))
                                ? Constants.INTEGER_INITIALIZE_VALUE
                                : Convert.ToInt64(datarow[Constants.GA_ACUAL_OCCURANCE_COUNT]),
                        CreatedBy = (datarow[Constants.GA_CREATED_BY].Equals(DBNull.Value))
                                    ? String.Empty
                                    : datarow[Constants.GA_CREATED_BY].ToString(),
                        DocumentQuery = tmpSearchContext,
                        IsActive      = Convert.ToBoolean(datarow[Constants.IsActive])
                    }
                };
            }
            catch
            {
                //--RVWSEarchBEO type is deprecated and no longer supported. hence past records can not be processed and returned..
                return(null);
            }
            // return the task object
            return(searchAlertsTaskBeo);
        }
Example #5
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);
        }
Example #6
0
        /// <summary>
        /// Generates Concvert DCB Link tasks
        /// </summary>
        /// <param name="jobParameters">Job BEO</param>
        /// <param name="previouslyCommittedTaskCount"> </param>
        /// <returns>List of Job Tasks (BEOs)</returns>
        protected override Tasks <ConvertDCBLinkTaskBusinessEntityObject> GenerateTasks(BaseJobBEO jobParameters, out int previouslyCommittedTaskCount)
        {
            Tasks <ConvertDCBLinkTaskBusinessEntityObject> tasks = null;

            try
            {
                EvLog.WriteEntry(Constants.JobTypeName + " - " + jobParameters.JobRunId.ToString(CultureInfo.InvariantCulture), Constants.Event_Job_GenerateTask_Start, EventLogEntryType.Information);
                previouslyCommittedTaskCount = 0;
                EvLog.WriteEntry(Constants.JobTypeName + " - " + jobParameters.JobId, MethodInfo.GetCurrentMethod().Name, EventLogEntryType.Information);
                tasks = GetTaskList <BaseJobBEO, ConvertDCBLinkTaskBusinessEntityObject>(jobParameters);
                previouslyCommittedTaskCount = tasks.Count;
                if (tasks.Count <= 0)
                {
                    ConvertDCBLinkTaskBusinessEntityObject convertDcbLinkTask = new ConvertDCBLinkTaskBusinessEntityObject();
                    convertDcbLinkTask = (ConvertDCBLinkTaskBusinessEntityObject)XmlUtility.DeserializeObject(jobParameters.BootParameters, typeof(ConvertDCBLinkTaskBusinessEntityObject));
                    _query             = ApplicationConfigurationManager.GetValue(Constants.SearchQuery);
                    _createdByUserGuid = convertDcbLinkTask.CreateByUserGuid;
                    string pageSize = "1";
                    DocumentQueryEntity docQueryEntity = GetDocumentQueryEntity(convertDcbLinkTask.DatasetId.ToString(CultureInfo.InvariantCulture), _query, pageSize);
                    docQueryEntity.TransactionName = "ConvertDCBLinksToCaseMap - GenerateTasks";
                    ReviewerSearchResults searchResults = JobSearchHandler.GetSearchResults(docQueryEntity);
                    if (searchResults.TotalRecordCount > 0)
                    {
                        convertDcbLinkTask.TaskNumber   = 1;
                        convertDcbLinkTask.TaskPercent  = 100;
                        convertDcbLinkTask.TaskComplete = false;
                    }
                    _documentCount = searchResults.TotalHitCount;
                    tasks.Add(convertDcbLinkTask);
                }
                EvLog.WriteEntry(Constants.JobTypeName + " - " + jobParameters.JobRunId.ToString(CultureInfo.InvariantCulture), Constants.Event_Job_GenerateTask_Success, EventLogEntryType.Information);
            }
            catch (EVJobException ex)
            {
                _isJobFailed = true;
                EvLog.WriteEntry(Constants.JobTypeName + MethodInfo.GetCurrentMethod().Name, ex.Message, EventLogEntryType.Error);
                throw;
            }
            catch (Exception ex)
            {
                _isJobFailed = true;
                EvLog.WriteEntry(Constants.JobTypeName + MethodInfo.GetCurrentMethod().Name, ex.Message, EventLogEntryType.Error);
                EVJobException jobException = new EVJobException(ErrorCodes.GenerateTasksError, ex, JobLogInfo);
                throw (jobException);
            }
            return(tasks);
        }
        /// <summary>
        /// Get document list by velocity search.
        /// Get document list by Searching in search sub-system
        /// </summary>
        /// <returns></returns>
        private List <string> GetDocumentsBySearch(DocumentQueryEntity queryEntity)
        {
            queryEntity.ShouldNotBe(null);
            var documentId = new List <string>();

            queryEntity.TransactionName = "ExportStartupWorker - GetDocumentsBySearch";


            var results = (RvwReviewerSearchResults)SearchBo.Search(queryEntity);

            if (results == null || results.Documents == null || !results.Documents.Any())
            {
                return(documentId);
            }
            documentId.AddRange(results.Documents.Select(document => document.DocumentId.DocumentId));
            return(documentId);
        }
Example #8
0
 /// <summary>
 /// Method to execute the query and get the search results
 /// </summary>
 /// <param name="searchBizEntityObj">Document Query Entity</param>
 /// <param name="query">query to execute</param>
 /// <returns></returns>
 private long GetAlertResultCount(DocumentQueryEntity searchBizEntityObj, string query)
 {
     if (searchBizEntityObj != null)
     {
         searchBizEntityObj.QueryObject.QueryList.Clear();
         searchBizEntityObj.QueryObject.QueryList.AddRange(new List <Query>
         {
             new Query
             {
                 SearchQuery = HttpUtility.HtmlDecode(query),
                 Precedence  = 1
             }
         });
         searchBizEntityObj.TransactionName = "AlertsJob - GetAlertResultCount";
         // Do the search to get all results
         return(JobSearchHandler.GetSearchResultsCount(searchBizEntityObj.QueryObject));
     }
     return(0);
 }
        /// <summary>
        /// This method fetch the documents from search engine for the given search context
        /// </summary>
        public List <BulkDocumentInfoBEO> GetDocuments(DocumentQueryEntity searchContext)
        {
            var tagDocuments = new List <BulkDocumentInfoBEO>();

            searchContext.TransactionName = "TagStartupWorker - GetDocuments";
            var watch = new Stopwatch();

            watch.Start();
            var searchResults = SearchBo.Search(searchContext, true);

            watch.Stop();
            Tracer.Info("Total time in retrieving document(s) from Search sub-system is {0} milli seconds",
                        watch.Elapsed.TotalMilliseconds);

            if (searchResults.Documents.Any())
            {
                searchResults.Documents.ForEach(r => tagDocuments.Add(ConvertToDocumentIdentityRecord(r)));
            }
            return(tagDocuments);
        }
        /// <summary>
        /// Construct Document Query
        /// </summary>
        /// <returns></returns>
        private DocumentQueryEntity ConstructDocumentQuery()
        {
            var queryEntity = new DocumentQueryEntity
            {
                DocumentStartIndex = 0,
                DocumentCount      = _batchSize,
                QueryObject        = new SearchQueryEntity()
            };

            //Default maximum 100 document batch to retrieve from search sub-system

            #region Output Fields

            //Get only the ImportedDate as output fields rather than fetch all fields for document. This helps to improve performance
            var outputFields = new List <Field> {
                new Field {
                    FieldName = EVSystemFields.ImportDescription
                }
            };
            queryEntity.OutputFields.Clear();
            queryEntity.OutputFields.AddRange(outputFields);

            #endregion

            queryEntity.QueryObject.QueryList.Add(new Query(_searchQuery)
            {
                Precedence = 1
            });
            queryEntity.QueryObject.MatterId  = Convert.ToInt32(_dataset.Matter.FolderID);
            queryEntity.QueryObject.DatasetId = Convert.ToInt32(_dataset.FolderID);
            queryEntity.QueryObject.IsConceptSearchEnabled = _isIncludeConceptSearch;
            if (!string.IsNullOrEmpty(_reviewsetId))
            {
                queryEntity.QueryObject.ReviewsetId = _reviewsetId;
            }
            queryEntity.QueryObject.LogSearchHistory = false;

            //Explicitly set - to not to return snippet from search engine..Will be scrapped as part of search engine replacement
            queryEntity.IgnoreDocumentSnippet = true;
            return(queryEntity);
        }
        /// <summary>
        /// Get the Qualified Documents
        /// </summary>
        /// <param name="jobParameters"></param>
        /// <param name="datasetId"> </param>
        /// <param name="sMatterId"></param>
        /// <param name="operation"> </param>
        /// <returns></returns>
        private static List <FilteredDocumentBusinessEntity> GetQualifiedDocuments(UpdateReviewSetJobBEO jobParameters,
                                                                                   string datasetId, string sMatterId, string sBinderId, string operation)
        {
            DocumentQueryEntity documentQueryEntity = new DocumentQueryEntity
            {
                QueryObject = new SearchQueryEntity
                {
                    DatasetId = Convert.ToInt64(datasetId),
                    MatterId  = Convert.ToInt64(sMatterId),
                    IsConceptSearchEnabled = jobParameters.DocumentSelectionContext.SearchContext.IsConceptSearchEnabled,
                    ReviewsetId            = operation.Equals(Constants.Add) ? string.Empty : jobParameters.ReviewSetId
                }
            };


            if (operation.Equals(Constants.Add))
            {
                if (!String.IsNullOrEmpty(jobParameters.DocumentSelectionContext.SearchContext.Query))
                {
                    jobParameters.DocumentSelectionContext.SearchContext.Query = string.Format("({0}) AND (NOT ({1}:\"{2}\"))",
                                                                                               jobParameters.DocumentSelectionContext.SearchContext.Query, EVSystemFields.BinderId.ToLowerInvariant(), sBinderId);
                }
                else
                {
                    jobParameters.DocumentSelectionContext.SearchContext.Query = string.Format("(NOT ({0}:\"{1}\"))",
                                                                                               EVSystemFields.BinderId.ToLowerInvariant(), sBinderId);
                }
            }

            documentQueryEntity.QueryObject.QueryList.Add(new Query(jobParameters.DocumentSelectionContext.SearchContext.Query));
            documentQueryEntity.SortFields.Add(new Sort {
                SortBy = Constants.Relevance
            });
            documentQueryEntity.IgnoreDocumentSnippet = true;
            documentQueryEntity.TransactionName       = "UpdateReviewSetJob - GetQualifiedDocuments";
            // -- get the qualified documents to beassigned for the reviewset
            List <FilteredDocumentBusinessEntity> qualifiedDocuments = JobSearchHandler.GetFilteredListOfDocuments(documentQueryEntity, jobParameters.DocumentSelectionContext);

            return(qualifiedDocuments);
        }
        /// <summary>
        /// Absorb the boot parameters, deserialize and pass on the messages to the Search Worker
        /// </summary>
        public void DoBeginWork(string bootParameter)
        {
            bootParameter.ShouldNotBeEmpty();
            // Deserialize and determine the boot object
            _bootObject = GetBootObject(bootParameter);

            // Assert condition to check for jobscheduled by
            _bootObject.JobScheduleCreatedBy.ShouldNotBeEmpty();
            _bootObject.BinderFolderId.ShouldNotBe(0);

            // Get Dataset Details to know about the Collection id and the Matter ID details
            _datasetEntity = DataSetBO.GetDataSetDetailForDataSetId(_bootObject.datasetId);
            //Assert condition to check for dataset details
            _datasetEntity.ShouldNotBe(null);

            _binderEntity = BinderBO.GetBinderDetails(_bootObject.BinderFolderId.ToString());
            _binderEntity.ShouldNotBe(null);

            _reviewSetRecord = ConvertToReviewSetRecord(_bootObject);

            // Construct the document query entity to determine the total documents
            _docQueryEntity = GetQueryEntity(_bootObject, _datasetEntity, 0, 1, null);

            // Mock the user session
            MockSession();

            _docQueryEntity.TransactionName = _docQueryEntity.QueryObject.TransactionName = "ReviewsetStartupWorker - DoBeginWork (GetCount)";

            var reviewsetLogic = _reviewSetRecord.ReviewSetLogic.ToLower();

            if (reviewsetLogic == "all" || reviewsetLogic == "tag")
            {
                var searchQuery = !string.IsNullOrEmpty(_bootObject.SearchQuery)? _bootObject.SearchQuery.Replace("\"", ""): string.Empty;
                _totalDocumentCount = DocumentBO.GetDocumentCountForCreateReviewsetJob(_datasetEntity.Matter.FolderID, _datasetEntity.CollectionId,
                                                                                       reviewsetLogic, searchQuery);
            }
            else
            {
                // Retrieve the total documents qualified
                _totalDocumentCount = ReviewerSearchInstance.GetDocumentCount(_docQueryEntity.QueryObject);
            }

            Tracer.Info("Reviewset Startup Worker : {0} matching documents determined for the requested query", _totalDocumentCount);
            if (_totalDocumentCount < 1)
            {
                var message = String.Format("Search server does not return any documents for the reviewset '{0}'", _reviewSetRecord.ReviewSetName);
                throw new ApplicationException(message);
            }

            LogMessage(true, string.Format("{0} documents are qualified", _totalDocumentCount));

            // Construct the document query entity to write the resultant documents in xml file
            var outputFields = new List <Field>();

            outputFields.AddRange(new List <Field>()
            {
                new Field {
                    FieldName = EVSystemFields.DcnField
                },
                new Field {
                    FieldName = EVSystemFields.FamilyId
                },
                new Field {
                    FieldName = EVSystemFields.DuplicateId
                }
            });
            _docQueryEntity = GetQueryEntity(_bootObject, _datasetEntity, 0, Convert.ToInt32(_totalDocumentCount), outputFields);
        }
Example #13
0
        /// <summary>
        /// Does atomic 1)Gets DCB document 2) 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(ConvertDCBLinkTaskBusinessEntityObject task, BaseJobBEO jobParameters)
        {
            bool StatusFlag = true;// Function return status.

            try
            {
                EvLog.WriteEntry(Constants.JobTypeName + " - " + jobParameters.JobRunId.ToString(CultureInfo.InvariantCulture), Constants.Event_Job_DoAtomicWork_Start, EventLogEntryType.Information);
                // Perform Atomic Task
                DCBLinkCollectionBEO  dcbLinks = new DCBLinkCollectionBEO();
                DCBLinkBEO            dcbLink;
                ReviewerSearchResults searchResults = null;
                if (_documentCount > 0)
                {
                    DocumentQueryEntity documentQueryEntity = GetDocumentQueryEntity(task.DatasetId.ToString(CultureInfo.InvariantCulture), _query, _documentCount.ToString(CultureInfo.InvariantCulture));
                    documentQueryEntity.TransactionName = "ConvertDCBLinksToCaseMap - DoAtomicWork";
                    searchResults = JobSearchHandler.GetSearchResults(documentQueryEntity);
                }
                List <DCBLinkBEO> linkList = new List <DCBLinkBEO>();
                string            uuid     = string.Empty;
                int count = 0;
                foreach (DocumentResult document in searchResults.ResultDocuments)
                {
                    dcbLink = new DCBLinkBEO();
                    DocumentIdentifierBEO docIdentifier = new DocumentIdentifierBEO(document.MatterID.ToString(CultureInfo.InvariantCulture), document.CollectionID, document.DocumentID);
                    if (count == 0)
                    {
                        uuid = docIdentifier.UniqueIdentifier.Replace(docIdentifier.DocumentId, string.Empty);
                    }
                    dcbLink.NewDocumentId = docIdentifier.DocumentId;

                    List <FieldResult> fieldValues = document.Fields.Where(f => System.String.Compare(f.Name, EVSystemFields.DcbId, System.StringComparison.OrdinalIgnoreCase) == 0).ToList();
                    dcbLink.OldDocumentId = fieldValues.Any() ? fieldValues.First().Value.Replace("[", "(").Replace("]", ")") : string.Empty;
                    linkList.Add(dcbLink);
                    dcbLink.CollectionId = docIdentifier.CollectionId;
                    dcbLink.DCN          = docIdentifier.DCN;
                    if (docIdentifier.MatterId != null)
                    {
                        dcbLink.MatterId = long.Parse(docIdentifier.MatterId);
                    }

                    count++;
                }
                linkList.SafeForEach(l => dcbLinks.Links.Add(l));
                dcbLinks.UrlApplicationLink = task.LinkBackUrl;

                string        xml         = DocumentFactBusinessObject.GenerateDcbLinksXml(dcbLinks, uuid);
                UTF8Encoding  encoding    = new UTF8Encoding();
                byte[]        content     = encoding.GetBytes(xml);
                StringBuilder nameBuilder = new StringBuilder();
                nameBuilder.Append(Constants.TaskName);
                nameBuilder.Append(Constants.OnDate);
                nameBuilder.Append(startedTime.ConvertToUserTime());
                string requestName = nameBuilder.ToString();

                nameBuilder = new StringBuilder();
                nameBuilder.Append(Constants.TaskName);
                _requestDescription = nameBuilder.ToString();

                string fileType = ApplicationConfigurationManager.GetValue(Constants.FileType);
                _conversionId = CaseMapDAO.SaveConversionResults(jobParameters.JobRunId, requestName, _requestDescription, content, fileType, _createdByUserGuid);
                StatusFlag    = true;
                EvLog.WriteEntry(Constants.JobTypeName + " - " + jobParameters.JobRunId.ToString(CultureInfo.InvariantCulture), Constants.Event_Job_DoAtomicWork_Success, EventLogEntryType.Information);
                TaskLogInfo.AddParameters(Constants.DataSetName, task.DatasetName);
            }
            catch (EVTaskException ex)
            {
                _isJobFailed = true;
                EvLog.WriteEntry(Constants.JobTypeName + MethodInfo.GetCurrentMethod().Name, ex.Message, EventLogEntryType.Error);
                throw;
            }
            catch (Exception ex)
            {
                _isJobFailed = true;
                // Handle exception in Generate Tasks
                EvLog.WriteEntry(Constants.JobTypeName + MethodInfo.GetCurrentMethod().Name, ex.Message, EventLogEntryType.Error);
                EVTaskException jobException = new EVTaskException(ErrorCodes.DoAtomicError, ex);
                TaskLogInfo.StackTrace = ex.Message + Constants.LineBreak + ex.StackTrace;
                TaskLogInfo.AddParameters(Constants.DataSetId, task.DatasetId.ToString(CultureInfo.InvariantCulture));
                TaskLogInfo.AddParameters(Constants.DataSetName, task.DatasetName);
                TaskLogInfo.TaskKey    = Constants.DataSetName + ":" + task.DatasetName;
                jobException.LogMessge = TaskLogInfo;
                throw (jobException);
            }
            return(StatusFlag);
        }
        /// <summary>
        /// Get filtered list of documents from the search context
        /// </summary>
        /// <param name="jobParameters">Input parameters of the job</param>
        /// <param name="isTotalRecall"></param>
        /// <param name="justCount"></param>
        /// <returns>List of filtered documents</returns>
        private DocumentQueryEntity GetSearchContext(BulkTagJobBusinessEntity jobParameters, bool isTotalRecall, bool justCount)
        {
            if (!string.IsNullOrEmpty(jobParameters.JobSource) &&
                jobParameters.JobSource.Equals("reprocessfilterdocuments", StringComparison.InvariantCultureIgnoreCase))
            {
                SetSelectedDocumentsForReprocessTagging(jobParameters);
            }

            var documentQueryEntity = new DocumentQueryEntity
            {
                QueryObject = new SearchQueryEntity
                {
                    ReviewsetId            = jobParameters.DocumentListDetails.SearchContext.ReviewSetId,
                    DatasetId              = jobParameters.DocumentListDetails.SearchContext.DataSetId,
                    MatterId               = jobParameters.DocumentListDetails.SearchContext.MatterId,
                    IsConceptSearchEnabled = jobParameters.DocumentListDetails.SearchContext.IsConceptSearchEnabled,
                },
            };

            #region Initialize Bin filters

            if (!string.IsNullOrEmpty(jobParameters.DocumentListDetails.SearchContext.BinningState))
            {
                var      binquerys    = new List <BinFilter>();
                string[] separator    = { "AND" };
                var      selectedList = jobParameters.DocumentListDetails.SearchContext.BinningState.Trim()
                                        .Split(separator, StringSplitOptions.None);
                foreach (var query in selectedList)
                {
                    var bins = query.Split(':');
                    if (bins.Length > 0)
                    {
                        var binvalue = string.Empty;
                        for (var i = 1; i < bins.Length; i++)
                        {
                            if (binvalue != string.Empty)
                            {
                                binvalue = binvalue + ":";
                            }
                            binvalue = binvalue + bins[i];
                        }

                        binquerys.Add(new BinFilter {
                            BinField = bins[0], BinValue = binvalue
                        });
                        documentQueryEntity.QueryObject.BinFilters.Clear();
                        documentQueryEntity.QueryObject.BinFilters.AddRange(binquerys);
                    }
                }
            }

            #endregion

            documentQueryEntity.DocumentCount = justCount ? 1 : 999999999;

            if (isTotalRecall)
            {
                var outputFields = new List <Field>();
                outputFields.AddRange(new List <Field>
                {
                    new Field {
                        FieldName = DcnField
                    },
                    new Field {
                        FieldName = EVSystemFields.ReviewSetId
                    },
                    new Field {
                        FieldName = EVSystemFields.FamilyId
                    },
                    new Field {
                        FieldName = EVSystemFields.DuplicateId
                    }
                });
                documentQueryEntity.OutputFields.AddRange(outputFields); //Populate fetch duplicates fields

                documentQueryEntity.TotalRecallConfigEntity.IsTotalRecall = true;
            }

            documentQueryEntity.QueryObject.QueryList.Clear();
            documentQueryEntity.QueryObject.QueryList.Add(new Query {
                SearchQuery = ConstructSearchQuery(jobParameters)
            });
            documentQueryEntity.SortFields.Add(new Sort {
                SortBy = Constants.Relevance
            });
            documentQueryEntity.IgnoreDocumentSnippet = true;
            documentQueryEntity.DocumentStartIndex    = 0;
            return(documentQueryEntity);
        }
        /// <summary>
        /// Constructs and returns the document search query entity
        /// </summary>
        /// <param name="jobParameters">The job parameters.</param>
        /// <param name="datasetEntity">The dataset entity.</param>
        /// <returns></returns>
        private DocumentQueryEntity GetQueryEntity(CreateReviewSetJobBEO jobParameters,
                                                   DatasetBEO datasetEntity, int startIndex, int documentCount, List <Field> outputFields)
        {
            DocumentQueryEntity documentQueryEntity = new DocumentQueryEntity
            {
                QueryObject = new SearchQueryEntity
                {
                    MatterId = datasetEntity.Matter.FolderID,
                    IsConceptSearchEnabled = jobParameters.DocumentSelectionContext.SearchContext.IsConceptSearchEnabled,
                    DatasetId = datasetEntity.FolderID
                }
            };

            documentQueryEntity.IgnoreDocumentSnippet = true;
            documentQueryEntity.DocumentStartIndex    = startIndex;
            documentQueryEntity.DocumentCount         = documentCount;
            documentQueryEntity.SortFields.Add(new Sort {
                SortBy = Constants.Relevance
            });

            if (outputFields != null && outputFields.Any())
            {
                documentQueryEntity.OutputFields.AddRange(outputFields);
            }

            var tmpQuery       = string.Empty;
            var selectionQuery = string.Empty;

            if (!string.IsNullOrEmpty(jobParameters.DocumentSelectionContext.SearchContext.Query))
            {
                tmpQuery = string.Format("({0} )", jobParameters.DocumentSelectionContext.SearchContext.Query);
            }
            else
            {
                tmpQuery = string.Format("(NOT ({0}:\"{1}\"))", EVSystemFields.BinderId.ToLowerInvariant(), _binderEntity.BinderId);
            }

            switch (jobParameters.DocumentSelectionContext.GenerateDocumentMode)
            {
            case DocumentSelectMode.UseSelectedDocuments:
            {
                jobParameters.DocumentSelectionContext.SelectedDocuments.ForEach(d =>
                                                                                 selectionQuery += string.Format("{0}:\"{1}\" OR ", EVSystemFields.DocumentKey, d));
                if (!string.IsNullOrEmpty(selectionQuery))
                {
                    selectionQuery = selectionQuery.Substring(0, selectionQuery.LastIndexOf(" OR "));
                    tmpQuery       = string.Format("({0} AND ({1}))", tmpQuery, selectionQuery);
                }

                break;
            }

            case DocumentSelectMode.QueryAndExclude:
            {
                jobParameters.DocumentSelectionContext.DocumentsToExclude.ForEach(d =>
                                                                                  selectionQuery += string.Format("(NOT {0}:\"{1}\") AND ", EVSystemFields.DocumentKey, d));
                if (!string.IsNullOrEmpty(selectionQuery))
                {
                    selectionQuery = selectionQuery.Substring(0, selectionQuery.LastIndexOf(" AND "));
                    tmpQuery       = string.Format("({0} AND ({1}))", tmpQuery, selectionQuery);
                }
                break;
            }
            }

            documentQueryEntity.QueryObject.QueryList.Clear();
            documentQueryEntity.QueryObject.QueryList.Add(new Query {
                SearchQuery = tmpQuery
            });
            return(documentQueryEntity);
        }
        /// <summary>
        /// Constructs and returns the document search query entity
        /// </summary>
        /// <param name="jobParameters">The job parameters.</param>
        /// <param name="datasetEntity">The dataset entity.</param>
        /// <returns></returns>
        private DocumentQueryEntity GetQueryEntity(CreateReviewSetJobBEO jobParameters,
            DatasetBEO datasetEntity, int startIndex, int documentCount, List<Field> outputFields)
        {
            DocumentQueryEntity documentQueryEntity = new DocumentQueryEntity
            {
                QueryObject = new SearchQueryEntity
                {
                    MatterId = datasetEntity.Matter.FolderID,
                    IsConceptSearchEnabled = jobParameters.DocumentSelectionContext.SearchContext.IsConceptSearchEnabled,
                    DatasetId = datasetEntity.FolderID
                }
            };

            documentQueryEntity.IgnoreDocumentSnippet = true;
            documentQueryEntity.DocumentStartIndex = startIndex;
            documentQueryEntity.DocumentCount = documentCount;
            documentQueryEntity.SortFields.Add(new Sort { SortBy = Constants.Relevance });

            if (outputFields != null && outputFields.Any())
            {
                documentQueryEntity.OutputFields.AddRange(outputFields);
            }

            var tmpQuery = string.Empty;
            var selectionQuery = string.Empty;

            if (!string.IsNullOrEmpty(jobParameters.DocumentSelectionContext.SearchContext.Query))
            {
                tmpQuery = string.Format("({0} )", jobParameters.DocumentSelectionContext.SearchContext.Query);
            }
            else
            {
                tmpQuery = string.Format("(NOT ({0}:\"{1}\"))", EVSystemFields.BinderId.ToLowerInvariant(), _binderEntity.BinderId);
            }

            switch (jobParameters.DocumentSelectionContext.GenerateDocumentMode)
            {
                case DocumentSelectMode.UseSelectedDocuments:
                    {
                        jobParameters.DocumentSelectionContext.SelectedDocuments.ForEach(d =>
                            selectionQuery += string.Format("{0}:\"{1}\" OR ", EVSystemFields.DocumentKey, d));
                        if (!string.IsNullOrEmpty(selectionQuery))
                        {
                            selectionQuery = selectionQuery.Substring(0, selectionQuery.LastIndexOf(" OR "));
                            tmpQuery = string.Format("({0} AND ({1}))", tmpQuery, selectionQuery);
                        }

                        break;
                    }
                case DocumentSelectMode.QueryAndExclude:
                    {
                        jobParameters.DocumentSelectionContext.DocumentsToExclude.ForEach(d =>
                            selectionQuery += string.Format("(NOT {0}:\"{1}\") AND ", EVSystemFields.DocumentKey, d));
                        if (!string.IsNullOrEmpty(selectionQuery))
                        {
                            selectionQuery = selectionQuery.Substring(0, selectionQuery.LastIndexOf(" AND "));
                            tmpQuery = string.Format("({0} AND ({1}))", tmpQuery, selectionQuery);
                        }
                        break;
                    }
            }

            documentQueryEntity.QueryObject.QueryList.Clear();
            documentQueryEntity.QueryObject.QueryList.Add(new Query { SearchQuery = tmpQuery });
            return documentQueryEntity;
        }
Example #17
0
        /// <summary>
        /// This method is used to construct the notification message and send the notification for the alert
        /// </summary>
        /// <param name="task"></param>
        /// <param name="originalQuery"></param>
        /// <param name="searchBizEntityObj"></param>
        private void ConstructNotificationMessage(SearchAlertsTaskBEO task, string originalQuery,
                                                  DocumentQueryEntity searchBizEntityObj)
        {
            /* send notification only if
             *        - All result count between prev alert and current alert is changed
             *        - All result count is same but new results found for current alert
             *        - if alert is running for the first time
             *        - if the prev query and current query is not same */
            if ((m_LastResultCount != m_AllResultCount) ||
                ((m_LastResultCount == m_AllResultCount) && m_NewResultCount > 0) ||
                (m_AlertLastRunTimestamp.Equals(DateTime.MinValue) ||
                 m_AlertLastRunTimestamp.Equals(Constants.MSSQL2005_MINDATE)) ||
                (!String.IsNullOrEmpty(m_PrevSearchQuery) && (!m_PrevSearchQuery.Equals(originalQuery))))
            {
                var dataSetName = (searchBizEntityObj != null && searchBizEntityObj.QueryObject.DatasetId > 0)
                    ? FolderBO.GetFolderDetails(searchBizEntityObj.QueryObject.DatasetId.ToString()).FolderName
                    : String.Empty;
                var reviewSetName = (searchBizEntityObj != null && searchBizEntityObj.QueryObject.MatterId > 0 &&
                                     !String.IsNullOrEmpty(searchBizEntityObj.QueryObject.ReviewsetId))
                    ? ReviewSetBO.GetReviewSetDetails(searchBizEntityObj.QueryObject.MatterId.ToString(),
                                                      searchBizEntityObj.QueryObject.ReviewsetId).ReviewSetName
                    : String.Empty;
                // Send notification
                var alertMessage = Constants.ALERT_NOTIFICATION_MESSAGE;
                // modify the notification message if this needs to be sent as part of manual alert
                if (m_ManualAlertNextRunDate != DateTime.MinValue)
                {
                    alertMessage += Constants.MANUAL_ALERT_MESSAGE;
                }
                if (string.IsNullOrEmpty(reviewSetName))
                {
                    alertMessage = m_AllResultCount + alertMessage + Constants.Hyphen +
                                   HttpUtility.HtmlDecode(task.SearchAlert.Name) + Constants.FOR + Constants.DATASET +
                                   HttpUtility.HtmlDecode(dataSetName);
                }
                else
                {
                    alertMessage = m_AllResultCount + alertMessage + Constants.Hyphen +
                                   HttpUtility.HtmlDecode(task.SearchAlert.Name) + Constants.FOR + Constants.DATASET +
                                   HttpUtility.HtmlDecode(dataSetName) + Constants.INREVIEWSET +
                                   HttpUtility.HtmlDecode(reviewSetName);
                }
                if ((((m_LastResultCount == m_AllResultCount) && m_NewResultCount > 0) ||
                     ((m_LastResultCount > m_AllResultCount) && m_NewResultCount == 0)) &&
                    (m_AlertLastRunTimestamp != DateTime.MinValue))
                {
                    alertMessage += Constants.SEARCH_ALERT_RESULTS_CHANGED;
                }
                // this is required to get the details of the person who actually created the alert
                if (!string.IsNullOrEmpty(task.SearchAlert.CreatedBy))
                {
                    m_UserBusinessEntity = UserBO.GetUserUsingGuid(task.SearchAlert.CreatedBy);
                }

                var messageBuilder = new StringBuilder();
                messageBuilder.Append(Constants.Table);
                messageBuilder.Append(Constants.Row);
                messageBuilder.Append(Constants.Column);
                messageBuilder.Append(HttpUtility.HtmlEncode(alertMessage));
                messageBuilder.Append(Constants.CloseColumn);
                messageBuilder.Append(Constants.CloseRow);
                messageBuilder.Append(Constants.Row);
                messageBuilder.Append(Constants.Column);
                messageBuilder.Append(Constants.MessageSearchQuery);
                messageBuilder.Append(HttpUtility.HtmlDecode(originalQuery));
                messageBuilder.Append(Constants.CloseColumn);
                messageBuilder.Append(Constants.CloseRow);
                messageBuilder.Append(Constants.Row);
                messageBuilder.Append(Constants.Column);
                messageBuilder.Append(Constants.MessageDatasetName);
                messageBuilder.Append(HttpUtility.HtmlDecode(dataSetName));
                messageBuilder.Append(Constants.CloseColumn);
                messageBuilder.Append(Constants.CloseRow);
                if (!(string.IsNullOrEmpty(reviewSetName)))
                {
                    messageBuilder.Append(Constants.Row);
                    messageBuilder.Append(Constants.Column);
                    messageBuilder.Append(Constants.MessageReviewsetName);
                    messageBuilder.Append(HttpUtility.HtmlDecode(reviewSetName));
                    messageBuilder.Append(Constants.CloseColumn);
                    messageBuilder.Append(Constants.CloseRow);
                }
                messageBuilder.Append(Constants.CloseTable);
                SendNotification(task.SearchAlert, alertMessage, messageBuilder.ToString());
            }
        }
 /// <summary>
 /// Filter and get the final list of documents required
 /// </summary>
 /// <param name="documentQueryEntity">The document query entity.</param>
 /// <param name="documentListDetails">Object containing filter parameters</param>
 /// <returns>
 /// List of Filtered documents
 /// </returns>
 private List<FilteredDocumentBusinessEntity> GetFilteredListOfDocuments(DocumentQueryEntity documentQueryEntity, DocumentOperationBusinessEntity documentListDetails)
 {
     var filteredDocuments = new List<FilteredDocumentBusinessEntity>();
     if (documentListDetails != null)
     {
         switch (documentListDetails.GenerateDocumentMode)
         {
             case DocumentSelectMode.QueryAndExclude:
                 {
                     filteredDocuments = FetchFilteredSearchResultDocuments(documentQueryEntity,
                         documentListDetails.DocumentsToExclude, true);
                     break;
                 }
             case DocumentSelectMode.UseSelectedDocuments:
                 {
                     filteredDocuments = FetchFilteredSearchResultDocuments(documentQueryEntity,
                         documentListDetails.SelectedDocuments, false);
                     break;
                 }
         }
     }
     return filteredDocuments;
 }
        /// <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);
        }
        /// <summary>
        /// Constructs and returns the document search query entity
        /// </summary>
        /// <param name="jobParameters">The job parameters.</param>
        /// <param name="datasetEntity">The dataset entity.</param>
        /// <returns></returns>
        private DocumentQueryEntity GetQueryEntity(UpdateReviewSetJobBEO jobParameters,
                                                   DatasetBEO datasetEntity, int startIndex, int documentCount, List <Field> outputFields)
        {
            var documentQueryEntity = new DocumentQueryEntity
            {
                QueryObject = new SearchQueryEntity
                {
                    MatterId = datasetEntity.Matter.FolderID,
                    IsConceptSearchEnabled = jobParameters.DocumentSelectionContext.SearchContext.IsConceptSearchEnabled,
                    DatasetId   = datasetEntity.FolderID,
                    ReviewsetId = jobParameters.ReviewSetId
                }
            };

            documentQueryEntity.DocumentStartIndex = startIndex;
            documentQueryEntity.DocumentCount      = documentCount;
            documentQueryEntity.SortFields.Add(new Sort {
                SortBy = Constants.Relevance
            });

            // Include families & duplicates is obsolete...So no need to include families & duplicates as part of search-engine search.. Always set to false;
            documentQueryEntity.IgnoreDocumentSnippet = true;
            documentQueryEntity.IncludeDuplicates     = true;
            documentQueryEntity.IncludeFamilies       = true;
            documentQueryEntity.TotalRecallConfigEntity.IsTotalRecall = true;

            if (outputFields != null && outputFields.Any())
            {
                documentQueryEntity.OutputFields.AddRange(outputFields);
            }

            var tmpQuery       = string.Empty;
            var selectionQuery = string.Empty;

            if (!string.IsNullOrEmpty(jobParameters.DocumentSelectionContext.SearchContext.Query))
            {
                tmpQuery = jobParameters.DocumentSelectionContext.SearchContext.Query;
            }

            switch (jobParameters.DocumentSelectionContext.GenerateDocumentMode)
            {
            case DocumentSelectMode.UseSelectedDocuments:
            {
                jobParameters.DocumentSelectionContext.SelectedDocuments.ForEach(d =>
                                                                                 selectionQuery += string.Format("{0}:\"{1}\" OR ", EVSystemFields.DocumentKey, d));
                if (!string.IsNullOrEmpty(selectionQuery))
                {
                    selectionQuery = selectionQuery.Substring(0, selectionQuery.LastIndexOf(" OR "));
                    tmpQuery       = string.Format("({0} AND {1})", tmpQuery, selectionQuery);
                }

                break;
            }

            case DocumentSelectMode.QueryAndExclude:
            {
                jobParameters.DocumentSelectionContext.DocumentsToExclude.ForEach(d =>
                                                                                  selectionQuery += string.Format("(NOT {0}:\"{1}\") AND ", EVSystemFields.DocumentKey, d));
                if (!string.IsNullOrEmpty(selectionQuery))
                {
                    selectionQuery = selectionQuery.Substring(0, selectionQuery.LastIndexOf(" AND "));
                    tmpQuery       = string.Format("({0} AND {1})", tmpQuery, selectionQuery);
                }
                break;
            }
            }
            documentQueryEntity.QueryObject.QueryList.Clear();
            documentQueryEntity.QueryObject.QueryList.Add(new Query {
                SearchQuery = tmpQuery
            });
            return(documentQueryEntity);
        }
        /// <summary>
        /// Get filtered list of documents from the search context
        /// </summary>
        /// <param name="jobParameters">Input parameters of the job</param>
        /// <param name="isTotalRecall"></param>
        /// <param name="justCount"></param>
        /// <returns>List of filtered documents</returns>
        private DocumentQueryEntity GetSearchContext(BulkTagJobBusinessEntity jobParameters, bool isTotalRecall, bool justCount)
        {
            if (!string.IsNullOrEmpty(jobParameters.JobSource) &&
                jobParameters.JobSource.Equals("reprocessfilterdocuments", StringComparison.InvariantCultureIgnoreCase))
            {
                SetSelectedDocumentsForReprocessTagging(jobParameters);
            }

            var documentQueryEntity = new DocumentQueryEntity
            {
                QueryObject = new SearchQueryEntity
                {
                    ReviewsetId = jobParameters.DocumentListDetails.SearchContext.ReviewSetId,
                    DatasetId = jobParameters.DocumentListDetails.SearchContext.DataSetId,
                    MatterId = jobParameters.DocumentListDetails.SearchContext.MatterId,
                    IsConceptSearchEnabled = jobParameters.DocumentListDetails.SearchContext.IsConceptSearchEnabled,
                },
            };

            #region Initialize Bin filters

            if (!string.IsNullOrEmpty(jobParameters.DocumentListDetails.SearchContext.BinningState))
            {
                var binquerys = new List<BinFilter>();
                string[] separator = { "AND" };
                var selectedList = jobParameters.DocumentListDetails.SearchContext.BinningState.Trim()
                    .Split(separator, StringSplitOptions.None);
                foreach (var query in selectedList)
                {
                    var bins = query.Split(':');
                    if (bins.Length > 0)
                    {
                        var binvalue = string.Empty;
                        for (var i = 1; i < bins.Length; i++)
                        {
                            if (binvalue != string.Empty)
                            {
                                binvalue = binvalue + ":";
                            }
                            binvalue = binvalue + bins[i];
                        }

                        binquerys.Add(new BinFilter { BinField = bins[0], BinValue = binvalue });
                        documentQueryEntity.QueryObject.BinFilters.Clear();
                        documentQueryEntity.QueryObject.BinFilters.AddRange(binquerys);
                    }
                }
            }

            #endregion

            documentQueryEntity.DocumentCount = justCount ? 1 : 999999999;

            if (isTotalRecall)
            {
                var outputFields = new List<Field>();
                outputFields.AddRange(new List<Field>
                {
                    new Field {FieldName = DcnField},
                    new Field {FieldName = EVSystemFields.ReviewSetId},
                    new Field {FieldName = EVSystemFields.FamilyId},
                    new Field {FieldName = EVSystemFields.DuplicateId}
                });
                documentQueryEntity.OutputFields.AddRange(outputFields); //Populate fetch duplicates fields

                documentQueryEntity.TotalRecallConfigEntity.IsTotalRecall = true;
            }

            documentQueryEntity.QueryObject.QueryList.Clear();
            documentQueryEntity.QueryObject.QueryList.Add(new Query { SearchQuery = ConstructSearchQuery(jobParameters) });
            documentQueryEntity.SortFields.Add(new Sort { SortBy = Constants.Relevance });
            documentQueryEntity.IgnoreDocumentSnippet = true;
            documentQueryEntity.DocumentStartIndex = 0;
            return documentQueryEntity;
        }
        /// <summary>
        /// Constructs and returns the document search query entity
        /// </summary>
        /// <param name="jobParameters">The job parameters.</param>
        /// <param name="datasetEntity">The dataset entity.</param>
        /// <returns></returns>
        private DocumentQueryEntity GetQueryEntity(UpdateReviewSetJobBEO jobParameters,
            DatasetBEO datasetEntity, int startIndex, int documentCount, List<Field> outputFields)
        {
            var documentQueryEntity = new DocumentQueryEntity
            {
                QueryObject = new SearchQueryEntity
                {
                    MatterId = datasetEntity.Matter.FolderID,
                    IsConceptSearchEnabled = jobParameters.DocumentSelectionContext.SearchContext.IsConceptSearchEnabled,
                    DatasetId = datasetEntity.FolderID,
                    ReviewsetId = jobParameters.ReviewSetId
                }
            };

            documentQueryEntity.DocumentStartIndex = startIndex;
            documentQueryEntity.DocumentCount = documentCount;
            documentQueryEntity.SortFields.Add(new Sort {SortBy = Constants.Relevance});

            // Include families & duplicates is obsolete...So no need to include families & duplicates as part of search-engine search.. Always set to false;
            documentQueryEntity.IgnoreDocumentSnippet = true;
            documentQueryEntity.IncludeDuplicates = true;
            documentQueryEntity.IncludeFamilies = true;
            documentQueryEntity.TotalRecallConfigEntity.IsTotalRecall = true;

            if (outputFields != null && outputFields.Any())
            {
                documentQueryEntity.OutputFields.AddRange(outputFields);
            }

            var tmpQuery = string.Empty;
            var selectionQuery = string.Empty;

            if (!string.IsNullOrEmpty(jobParameters.DocumentSelectionContext.SearchContext.Query))
            {
                tmpQuery = jobParameters.DocumentSelectionContext.SearchContext.Query;
            }

            switch (jobParameters.DocumentSelectionContext.GenerateDocumentMode)
            {
                case DocumentSelectMode.UseSelectedDocuments:
                {
                    jobParameters.DocumentSelectionContext.SelectedDocuments.ForEach(d =>
                        selectionQuery += string.Format("{0}:\"{1}\" OR ", EVSystemFields.DocumentKey, d));
                    if (!string.IsNullOrEmpty(selectionQuery))
                    {
                        selectionQuery = selectionQuery.Substring(0, selectionQuery.LastIndexOf(" OR "));
                        tmpQuery = string.Format("({0} AND {1})", tmpQuery, selectionQuery);
                    }

                    break;
                }
                case DocumentSelectMode.QueryAndExclude:
                {
                    jobParameters.DocumentSelectionContext.DocumentsToExclude.ForEach(d =>
                        selectionQuery += string.Format("(NOT {0}:\"{1}\") AND ", EVSystemFields.DocumentKey, d));
                    if (!string.IsNullOrEmpty(selectionQuery))
                    {
                        selectionQuery = selectionQuery.Substring(0, selectionQuery.LastIndexOf(" AND "));
                        tmpQuery = string.Format("({0} AND {1})", tmpQuery, selectionQuery);
                    }
                    break;
                }
            }
            documentQueryEntity.QueryObject.QueryList.Clear();
            documentQueryEntity.QueryObject.QueryList.Add(new Query {SearchQuery = tmpQuery});
            return documentQueryEntity;
        }
        /// <summary>
        /// Absorb the boot parameters, deserialize and pass on the messages to the Search Worker
        /// </summary>
        public void DoBeginWork(string bootParameter)
        {
            bootParameter.ShouldNotBeEmpty();
            // Deserialize and determine the boot object
            _bootObject = GetBootObject(bootParameter);

            // Assert condition to check for jobscheduled by
            _bootObject.CreatedByGUID.ShouldNotBeEmpty();

            // Get Dataset Details to know about the Collection id and the Matter ID details
            _datasetEntity = DataSetBO.GetDataSetDetailForDataSetId(_bootObject.datasetId);
            _bootObject.BinderFolderId.ShouldNotBe(0);

            _binderEntity = BinderBO.GetBinderDetails(_bootObject.BinderFolderId.ToString());
            _binderEntity.ShouldNotBe(null);

            //Assert condition to check for dataset details
            _datasetEntity.ShouldNotBe(null);
            _datasetEntity.Matter.ShouldNotBe(null);

            _reviewSetRecord = ConvertToReviewSetRecord(_bootObject, _datasetEntity);


            // Construct the document query entity to determine the total documents
            _docQueryEntity = GetQueryEntity(_bootObject, _datasetEntity, 0, 1, null);
            _docQueryEntity.TransactionName = _docQueryEntity.QueryObject.TransactionName =
                "ReviewsetStartupWorker - DoBeginWork (GetCount)";

            // Mock the user session
            MockSession();


            var reviewSetDetails = ReviewSetBO.GetReviewSetDetails(_datasetEntity.Matter.FolderID.ToString(),
                _bootObject.ReviewSetId);

            if (reviewSetDetails != null)
            {
                reviewSetDetails.Action = _reviewSetRecord.Activity;
                reviewSetDetails.BinderName = _binderEntity.BinderName;
                //Audit Logging for existing review set
                ReviewSetBO.UpdateReviewSet(reviewSetDetails, false, false);
            }
            // Retrieve the total documents qualified
            _totalDocumentCount = ReviewerSearchInstance.GetDocumentCount(_docQueryEntity.QueryObject);


            Tracer.Info("Split Reviewset Startup Worker : {0} matching documents determined for the requested query",
                _totalDocumentCount);
            if (_totalDocumentCount < 1)
            {
                var message = String.Format("Search engine does not return any documents for Reviewset {0}",
                    _reviewSetRecord.ReviewSetName);
                throw new ApplicationException(message);
            }

            // Construct the document query entity to write the resultant documents in xml file
            var outputFields = new List<Field>();
            outputFields.AddRange(new List<Field>
            {
                new Field {FieldName = EVSystemFields.FamilyId},
                new Field {FieldName = EVSystemFields.DocumentKey},
                new Field {FieldName = EVSystemFields.ReviewSetId},
                new Field {FieldName = EVSystemFields.DuplicateId},
                new Field {FieldName = EVSystemFields.Tag.ToLower()},
                new Field {FieldName = _datasetEntity.DocumentControlNumberName}
            });
            _docQueryEntity = GetQueryEntity(_bootObject, _datasetEntity, 0, Convert.ToInt32(_totalDocumentCount),
                outputFields);
        }
        /// <summary>
        /// This method fetch the documents from search engine for the given search context
        /// </summary>
        public List<BulkDocumentInfoBEO> GetDocuments(DocumentQueryEntity searchContext)
        {
            var tagDocuments = new List<BulkDocumentInfoBEO>();
            searchContext.TransactionName = "TagStartupWorker - GetDocuments";
            var watch = new Stopwatch();
            watch.Start();
            var searchResults = SearchBo.Search(searchContext, true);
            watch.Stop();
            Tracer.Info("Total time in retrieving document(s) from Search sub-system is {0} milli seconds",
                watch.Elapsed.TotalMilliseconds);

            if (searchResults.Documents.Any())
            {
                searchResults.Documents.ForEach(r => tagDocuments.Add(ConvertToDocumentIdentityRecord(r)));
            }
            return tagDocuments;
        }
        protected override bool GenerateMessage()
        {
            if (_queryEntity == null)
            {
                _queryEntity = ConstructDocumentQuery();
            }

            _queryEntity.DocumentStartIndex = _pageIndex * _batchSize;

            _endDocumentIndex = _queryEntity.DocumentStartIndex + _batchSize - 1;

            if (_totalDocumentCount < _endDocumentIndex)
            {
                _endDocumentIndex = _totalDocumentCount;
            }
            var isGetDocumentsFromSearch = false;
            var documentIdList           = new List <string>();

            if (_parametersExportLoadFile.ExportLoadFileInfo != null)
            {
                switch (_parametersExportLoadFile.ExportLoadFileInfo.DocumentSelection)
                {
                case DocumentSelection.SavedQuery:
                    isGetDocumentsFromSearch = true;
                    documentIdList           = GetDocumentsBySearch(_queryEntity);
                    break;

                case DocumentSelection.Tag:
                    documentIdList = DocumentBO.GetDocumentsForExportJob(_queryEntity.QueryObject.MatterId,
                                                                         _dataset.CollectionId, _parametersExportLoadFile.ExportLoadFileInfo.TagId,
                                                                         _totalDocumentCount, _documentsRetrievalbatchSize, "tag");
                    break;

                default:
                    documentIdList = DocumentBO.GetDocumentsForExportJob(_queryEntity.QueryObject.MatterId,
                                                                         _dataset.CollectionId, string.Empty, _totalDocumentCount, _documentsRetrievalbatchSize, "all");
                    break;
                }
            }
            #region Assertion

            //Pre condition before send message to next worker
            documentIdList.ShouldNotBe(null);
            documentIdList.LongCount().ShouldBeGreaterThan(0);

            #endregion


            if (isGetDocumentsFromSearch)  //Search use batch retrieval
            {
                Send(documentIdList);
                _pageIndex++;

                if (_pageIndex * _batchSize < _totalDocumentCount)
                {
                    return(false);
                }
            }
            else  //All & Tag options retrieved in bulk batch from DB
            {
                Tracer.Info("Documents retrieved from database for export on All/Tag options - document count {0}", documentIdList.Count);
                Send(documentIdList); //Send all documents by _batchsize
            }

            LogMessage(true, "Export Startup Worker successfully completed.");
            return(true);
        }
 /// <summary>
 /// Gets all documents.
 /// </summary>
 /// <param name="documentQueryEntity">The document query entity.</param>
 /// <returns></returns>
 private ReviewerSearchResults GetAllDocuments(DocumentQueryEntity documentQueryEntity)
 {
     
     using (new EVTransactionScope(TransactionScopeOption.Suppress))
     {
         documentQueryEntity.IgnoreDocumentSnippet = true;
         var outputFields = new List<Field>();
         outputFields.AddRange(new List<Field>
         {
             new Field {FieldName = _dcnField},
             new Field{FieldName = EVSystemFields.PagesNatives},
             new Field{FieldName = EVSystemFields.PagesImages}
         });
         AddProductionFieldsAsOutPutFields(outputFields);
         documentQueryEntity.OutputFields.AddRange(outputFields);//Populate fetch duplicates fields
         documentQueryEntity.DocumentStartIndex = 0;
         documentQueryEntity.DocumentCount = 999999;
         documentQueryEntity.TransactionName = "ProductionStartupWorker - GetAllDocuments";
         documentQueryEntity.TotalRecallConfigEntity.IsTotalRecall = true;
         var rvwReviewerSearchResults = (RvwReviewerSearchResults)SearchBo.Search(documentQueryEntity);
         return ConvertRvwReviewerSearchResultsToReviewerSearchResults(rvwReviewerSearchResults);
     }
 }
Example #27
0
        /// <summary>
        ///     This is the overridden DoAtomicWork() method.
        /// </summary>
        /// <param name="task">A task to be performed.</param>
        /// <param name="jobParameters">Input settings / parameters of the job.</param>
        /// <returns>Status of the operation.</returns>
        protected override bool DoAtomicWork(GlobalReplaceTaskBEO task, GlobalReplaceJobBEO jobParameters)
        {
            bool   isSuccess = false;
            string taskKey   = string.Empty;

            try
            {
                LogMessage(string.Format(Constants.DoAtomicWorkStartMessage, task.TaskNumber), false,
                           LogCategory.Job, null);
                LogMessage(string.Format(Constants.DoAtomicWorkStartMessage, task.TaskNumber), GetType(),
                           Constants.DoAtomicWorkNamespace, EventLogEntryType.Information, jobParameters.JobId,
                           jobParameters.JobRunId);

                var documentQueryEntity = new DocumentQueryEntity
                {
                    DocumentCount      = task.PageSize,
                    DocumentStartIndex = task.PageNumber * task.PageSize,
                    QueryObject        = task.SearchQueryObject
                };
                documentQueryEntity.IgnoreDocumentSnippet = true;
                documentQueryEntity.TransactionName       = "FindAndReplaceJob - DoAtomicWork";
                ReviewerSearchResults reviewerSearchResults = JobSearchHandler.GetSearchResults(documentQueryEntity);

                LogMessage(string.Format(Constants.SearchDoneForTask, task.TaskNumber), false, LogCategory.Job,
                           null);
                LogMessage(string.Format(Constants.SearchDoneForTask, task.TaskNumber), GetType(),
                           Constants.DoAtomicWorkNamespace, EventLogEntryType.Information, jobParameters.JobId,
                           jobParameters.JobRunId);

                if (reviewerSearchResults.ResultDocuments != null && reviewerSearchResults.ResultDocuments.Count > 0)
                {
                    foreach (DocumentResult document in reviewerSearchResults.ResultDocuments)
                    {
                        List <RVWDocumentFieldBEO> documentFieldBeoList = GetFieldValuesToUpdate
                                                                              (document, task.ActualString, task.ReplaceString, jobParameters.JobScheduleCreatedBy);
                        if (documentFieldBeoList != null && documentFieldBeoList.Count > 0)
                        {
                            var documentData = new RVWDocumentBEO
                            {
                                MatterId     = document.MatterID,
                                CollectionId = document.CollectionID
                            };
                            taskKey = Constants.CollectionId + document.CollectionID;
                            documentData.DocumentId = document.DocumentID;
                            taskKey += Constants.DocumentId + document.DocumentID;
                            documentData.ModifiedBy   = jobParameters.JobScheduleCreatedBy;
                            documentData.ModifiedDate = DateTime.UtcNow;
                            documentFieldBeoList.SafeForEach(x => documentData.FieldList.Add(x));

                            _mIsFindTextExist = true;
                            //Update the field value information in vault for the appropriate fields matching
                            isSuccess =
                                DocumentService.UpdateDocumentFields(
                                    document.MatterID.ToString(CultureInfo.InvariantCulture), document.CollectionID,
                                    document.DocumentID, documentData);
                            if (!isSuccess)
                            {
                                break;
                            }
                        }
                    }
                }

                CustomNotificationMessage = !_mIsFindTextExist
                    ? string.Format(Constants.SearchTextNotFound, task.ActualString)
                    : string.Format(Constants.SearchTextFound, _mOccurrences);

                LogMessage(string.Format(Constants.DoAtomicWorkCompletedMessage, task.TaskNumber), false,
                           LogCategory.Job, null);
                LogMessage(string.Format(Constants.DoAtomicWorkCompletedMessage, task.TaskNumber), GetType(),
                           Constants.DoAtomicWorkNamespace, EventLogEntryType.Information, jobParameters.JobId,
                           jobParameters.JobRunId);
            }
            catch (EVException ex)
            {
                EvLog.WriteEntry(Constants.JOB_NAME + Constants.DoAtomicWorkFailMessage,
                                 ex.ToUserString() + Constants.TaskNumber + task.TaskNumber, EventLogEntryType.Error);
                LogException(jobParameters.JobId, ex, string.Empty, LogCategory.Task, taskKey,
                             ErrorCodes.ProblemInDoAtomicWork);
            }
            catch (Exception exp)
            {
                EvLog.WriteEntry(Constants.JOB_NAME + Constants.DoAtomicWorkFailMessage,
                                 exp.Message + Constants.TaskNumber + task.TaskNumber, EventLogEntryType.Error);
                LogException(jobParameters.JobId, exp, string.Empty, LogCategory.Task, taskKey,
                             ErrorCodes.ProblemInDoAtomicWork);
            }
            return(isSuccess);
        }
        ///// <summary>
        ///// Fetch filtered list of search results, given the search context
        ///// </summary>
        ///// <param name="searchContext">Search context to get all search results</param>
        ///// <param name="documentIds">List of document Ids to be excluded from the list</param>
        ///// <param name="exclude">
        ///// true if documentIds contain documents to be excluded, false if documentIds contain only the
        ///// documents to be selected from search results and returned
        ///// </param>
        ///// <returns>Filtered list of documents</returns>
        private List<FilteredDocumentBusinessEntity> FetchFilteredSearchResultDocuments(DocumentQueryEntity documentQueryEntity, List<string> documentIds, bool exclude)
        {
            var filteredDocuments = new List<FilteredDocumentBusinessEntity>();
            //Fetch search results - initially fetches only first 10 documents
            ReviewerSearchResults searchResult = GetAllDocuments(documentQueryEntity);
            if (searchResult != null)
            {
                List<DocumentResult> lstDocuments = searchResult.ResultDocuments;
                //Filter search results
                if (lstDocuments != null && lstDocuments.Any())
                {
                    if (exclude)
                    {
                        //Filter documents - Exclude documents in excludedDocuments from search result documents

                        if (documentIds != null && documentIds.Any())
                        {
                            lstDocuments = searchResult.ResultDocuments.Where(doc => !documentIds.Contains(doc.DocumentID)).ToList();
                        }


                    }
                    else
                    {
                        //Filter documents - Select documents in selectedDocumentIds list from search result documents
                        if (documentIds != null && documentIds.Any())
                        {
                            lstDocuments = searchResult.ResultDocuments.Where(doc => documentIds.Contains(doc.DocumentID)).ToList();
                        }

                    }
                    if (lstDocuments.Any())
                    {
                        lstDocuments.SafeForEach(excludedDoc => filteredDocuments.Add(ConstructFilteredDocument(excludedDoc)));
                    }
                }
            }
            return filteredDocuments;
        }
        /// <summary>
        /// Absorb the boot parameters, deserialize and pass on the messages to the Search Worker
        /// </summary>
        public void DoBeginWork(string bootParameter)
        {
            bootParameter.ShouldNotBeEmpty();
            // Deserialize and determine the boot object
            _bootObject = GetBootObject(bootParameter);

            // Assert condition to check for jobscheduled by
            _bootObject.JobScheduleCreatedBy.ShouldNotBeEmpty();
            _bootObject.BinderFolderId.ShouldNotBe(0);

            // Get Dataset Details to know about the Collection id and the Matter ID details
            _datasetEntity = DataSetBO.GetDataSetDetailForDataSetId(_bootObject.datasetId);
            //Assert condition to check for dataset details
            _datasetEntity.ShouldNotBe(null);

            _binderEntity = BinderBO.GetBinderDetails(_bootObject.BinderFolderId.ToString());
            _binderEntity.ShouldNotBe(null);

            _reviewSetRecord = ConvertToReviewSetRecord(_bootObject);

            // Construct the document query entity to determine the total documents
            _docQueryEntity = GetQueryEntity(_bootObject, _datasetEntity, 0, 1, null);

            // Mock the user session
            MockSession();

            _docQueryEntity.TransactionName = _docQueryEntity.QueryObject.TransactionName = "ReviewsetStartupWorker - DoBeginWork (GetCount)";

            var reviewsetLogic = _reviewSetRecord.ReviewSetLogic.ToLower();
            if (reviewsetLogic == "all" || reviewsetLogic == "tag")
            {
                var searchQuery = !string.IsNullOrEmpty(_bootObject.SearchQuery)? _bootObject.SearchQuery.Replace("\"", ""): string.Empty;
                _totalDocumentCount = DocumentBO.GetDocumentCountForCreateReviewsetJob(_datasetEntity.Matter.FolderID, _datasetEntity.CollectionId,
                    reviewsetLogic, searchQuery);
            }
            else
            {
                // Retrieve the total documents qualified
                _totalDocumentCount = ReviewerSearchInstance.GetDocumentCount(_docQueryEntity.QueryObject);
            }

            Tracer.Info("Reviewset Startup Worker : {0} matching documents determined for the requested query", _totalDocumentCount);
            if (_totalDocumentCount < 1)
            {
                var message = String.Format("Search server does not return any documents for the reviewset '{0}'", _reviewSetRecord.ReviewSetName);
                throw new ApplicationException(message);
            }

            LogMessage(true, string.Format("{0} documents are qualified", _totalDocumentCount));

            // Construct the document query entity to write the resultant documents in xml file
            var outputFields = new List<Field>();
            outputFields.AddRange(new List<Field>()
            {
                    new Field { FieldName = EVSystemFields.DcnField},
                    new Field { FieldName = EVSystemFields.FamilyId},
                    new Field { FieldName = EVSystemFields.DuplicateId}
            });
            _docQueryEntity = GetQueryEntity(_bootObject, _datasetEntity, 0, Convert.ToInt32(_totalDocumentCount), outputFields);
        }
        /// <summary>
        /// Absorb the boot parameters, deserialize and pass on the messages to the Search Worker
        /// </summary>
        public void DoBeginWork(string bootParameter)
        {
            bootParameter.ShouldNotBeEmpty();
            // Deserialize and determine the boot object
            _mBootObject = GetBootObject(bootParameter);
            _mBootObject.ShouldNotBe(null);

            _mBootObject.TagDetails.ShouldNotBe(null);
            _mBootObject.TagDetails.Id.ShouldBeGreaterThan(0);
            _mBootObject.TagDetails.MatterId.ShouldBeGreaterThan(0);
            _mBootObject.TagDetails.CollectionId.ShouldNotBeEmpty();

            _mBootObject.DocumentListDetails.ShouldNotBe(null);
            _mBootObject.DocumentListDetails.SearchContext.ShouldNotBe(null);

            _mBootObject.DocumentListDetails.SearchContext.MatterId.ShouldBeGreaterThan(0);
            _mBootObject.JobScheduleCreatedBy.ShouldNotBeEmpty();
            MockSession(_mBootObject.JobScheduleCreatedBy);

            // Fetch tag details
            _mTagDetails = RvwTagService.GetTag(_mBootObject.TagDetails.Id.ToString(CultureInfo.InvariantCulture),
                _mBootObject.TagDetails.CollectionId,
                _mBootObject.TagDetails.MatterId.ToString(
                    CultureInfo.InvariantCulture));

            if (_mTagDetails == null)
            {
                throw new Exception("Given tag does not exists");
            }

            if (!_mTagDetails.Status)
            {
                throw new Exception(string.Format("Tag {0} does not exists in active state", _mTagDetails.TagDisplayName));
            }

            _mSearchContext = GetSearchContext(_mBootObject, true, false);

            var documents = GetDocuments(_mSearchContext);

            if (!documents.Any())
            {
                LogMessage(true,
                    String.Format("Tag Startup Worker : No document(s) qualified to tag {0} for the job run id : {1}",
                        _mTagDetails.Name, PipelineId));
                return;
            }

            //// Retrieve the total documents qualified
            _mTotalDocumentCount = documents.Count;
            var strMsg = String.Format("{0} documents are qualified to tag {1} for the job run id : {2}",
                _mTotalDocumentCount, _mTagDetails.Name, PipelineId);
            LogMessage(false, strMsg);

            // Group the results and send it in batches
            GroupDocumentsAndSend(documents);
        }
        /// <summary>
        /// Absorb the boot parameters, deserialize and pass on the messages to the Search Worker
        /// </summary>
        public void DoBeginWork(string bootParameter)
        {
            bootParameter.ShouldNotBeEmpty();
            // Deserialize and determine the boot object
            _bootObject = GetBootObject(bootParameter);

            // Assert condition to check for jobscheduled by
            _bootObject.CreatedByGUID.ShouldNotBeEmpty();

            // Get Dataset Details to know about the Collection id and the Matter ID details
            _datasetEntity = DataSetBO.GetDataSetDetailForDataSetId(_bootObject.datasetId);
            _bootObject.BinderFolderId.ShouldNotBe(0);

            _binderEntity = BinderBO.GetBinderDetails(_bootObject.BinderFolderId.ToString());
            _binderEntity.ShouldNotBe(null);

            //Assert condition to check for dataset details
            _datasetEntity.ShouldNotBe(null);
            _datasetEntity.Matter.ShouldNotBe(null);

            _reviewSetRecord = ConvertToReviewSetRecord(_bootObject, _datasetEntity);


            // Construct the document query entity to determine the total documents
            _docQueryEntity = GetQueryEntity(_bootObject, _datasetEntity, 0, 1, null);
            _docQueryEntity.TransactionName = _docQueryEntity.QueryObject.TransactionName =
                "ReviewsetStartupWorker - DoBeginWork (GetCount)";

            // Mock the user session
            MockSession();


            var reviewSetDetails = ReviewSetBO.GetReviewSetDetails(_datasetEntity.Matter.FolderID.ToString(),
                                                                   _bootObject.ReviewSetId);

            if (reviewSetDetails != null)
            {
                reviewSetDetails.Action     = _reviewSetRecord.Activity;
                reviewSetDetails.BinderName = _binderEntity.BinderName;
                //Audit Logging for existing review set
                ReviewSetBO.UpdateReviewSet(reviewSetDetails, false, false);
            }
            // Retrieve the total documents qualified
            _totalDocumentCount = ReviewerSearchInstance.GetDocumentCount(_docQueryEntity.QueryObject);


            Tracer.Info("Split Reviewset Startup Worker : {0} matching documents determined for the requested query",
                        _totalDocumentCount);
            if (_totalDocumentCount < 1)
            {
                var message = String.Format("Search engine does not return any documents for Reviewset {0}",
                                            _reviewSetRecord.ReviewSetName);
                throw new ApplicationException(message);
            }

            // Construct the document query entity to write the resultant documents in xml file
            var outputFields = new List <Field>();

            outputFields.AddRange(new List <Field>
            {
                new Field {
                    FieldName = EVSystemFields.FamilyId
                },
                new Field {
                    FieldName = EVSystemFields.DocumentKey
                },
                new Field {
                    FieldName = EVSystemFields.ReviewSetId
                },
                new Field {
                    FieldName = EVSystemFields.DuplicateId
                },
                new Field {
                    FieldName = EVSystemFields.Tag.ToLower()
                },
                new Field {
                    FieldName = _datasetEntity.DocumentControlNumberName
                }
            });
            _docQueryEntity = GetQueryEntity(_bootObject, _datasetEntity, 0, Convert.ToInt32(_totalDocumentCount),
                                             outputFields);
        }
Example #32
0
        /// <summary>
        /// Atomic work 1) Search 2) Notify 3) Update task details back to database.
        /// </summary>
        /// <param name="task"></param>
        /// <param name="jobParameters"></param>
        /// <returns></returns>
        protected override bool DoAtomicWork(SearchAlertsTaskBEO task, SearchAlertsJobBEO jobParameters)
        {
            var statusFlag   = Constants.FAILURE; // Function return status.
            var queryTostore = string.Empty;
            DocumentQueryEntity searchBizEntityObj = null;

            try
            {
                //Get Previous Run Details
                var prevAlertRunDetails = m_Helper.GetPreviousAlertRunDetails(task.SearchAlert.AlertId);
                if (prevAlertRunDetails.Count > 0 && prevAlertRunDetails.Count == 7)
                {
                    m_AlertLastRunTimestamp  = Convert.ToDateTime(prevAlertRunDetails[0]);
                    m_LastResultCount        = Convert.ToInt32(prevAlertRunDetails[1]);
                    m_ManualAlertNextRunDate = Convert.ToDateTime(prevAlertRunDetails[2]);
                    var searchQuery = prevAlertRunDetails[3];
                    if (!string.IsNullOrEmpty(searchQuery))
                    {
                        searchBizEntityObj =
                            (DocumentQueryEntity)
                            XmlUtility.DeserializeObject(searchQuery, typeof(DocumentQueryEntity));
                        if (searchBizEntityObj != null)
                        {
                            m_PrevSearchQuery =
                                HttpUtility.HtmlDecode(
                                    (searchBizEntityObj.QueryObject.DisplayQuery.Split(new[] { Constants.ThreeTilde },
                                                                                       StringSplitOptions.None))[0]);
                        }
                    }
                    var createdBy = prevAlertRunDetails[6];

                    //the below block of code is required to pass the user details who has actually created or updated the alert so that search can use the same
                    // to check various business rules.
                    var adminUserSession = EVSessionManager.Get <UserSessionBEO>(Constants.UserSessionInfo);
                    var currentAlertUser = UserBO.GetUserUsingGuid(createdBy);
                    if (currentAlertUser != null)
                    {
                        SetContext(adminUserSession, currentAlertUser, true);
                    }
                    var originalQuery  = HttpUtility.HtmlDecode(task.SearchAlert.DocumentQuery.QueryObject.DisplayQuery);
                    var generatedQuery = PopulateQuery(task, originalQuery, currentAlertUser.Timezone);

                    //now modify the query in order to distinguish between all results and new results. This will be used in the UI.
                    queryTostore = originalQuery + Constants.QUERY_DELIMETER + generatedQuery.Item3;


                    // 1st time both will be the same so execute search only once.
                    if (generatedQuery.Item1)
                    {
                        // Get only the all doc result count. This will be executed only for 1st time.
                        m_AllResultCount = GetAlertResultCount(searchBizEntityObj, originalQuery);
                        m_NewResultCount = m_AllResultCount;
                    }
                    else
                    {
                        // Get the new result count
                        m_NewResultCount = GetAlertResultCount(searchBizEntityObj, generatedQuery.Item2);
                        // Get the all docs result count
                        m_AllResultCount = GetAlertResultCount(searchBizEntityObj, originalQuery);
                    }

                    ConstructNotificationMessage(task, originalQuery, searchBizEntityObj);
                    statusFlag = Constants.SUCCESS;
                }
            }
            catch (EVException ex)
            {
                HandleEVException(ex, MethodBase.GetCurrentMethod().Name, task);
                statusFlag = Constants.FAILURE;
                var taskException = new EVTaskException(ex.GetErrorCode(), ex, TaskLogInfo);
                throw (taskException);
            }
            catch (Exception ex)
            {
                // Handle exception in initialize
                LogMessage(ex.Message, MethodBase.GetCurrentMethod().Name, EventLogEntryType.Error, task);
                statusFlag = Constants.FAILURE;
                var taskException = new EVTaskException(ErrorCodes.ProblemInDoAtomicWork, ex, TaskLogInfo);
                throw (taskException);
            }
            finally
            {
                try
                {
                    task.SearchAlert.ActualOccurrenceCount = task.SearchAlert.ActualOccurrenceCount + 1;
                    task.SearchAlert.DocumentQuery.QueryObject.QueryList.Clear();
                    task.SearchAlert.DocumentQuery.QueryObject.QueryList.AddRange(new List <Query>
                    {
                        new Query
                        {
                            SearchQuery = queryTostore,
                            Precedence  = 1
                        }
                    });

                    // 3. Update alert details back to database
                    m_Helper.UpdateAlertPostNotification(task.SearchAlert.ActualOccurrenceCount,
                                                         DateTime.UtcNow,
                                                         m_NewResultCount,
                                                         m_AllResultCount,
                                                         m_ManualAlertNextRunDate != DateTime.MinValue
                            ? m_ManualAlertNextRunDate
                            : m_Helper.CalculateNextRunTimeStampForAlert(
                                                             task.SearchAlert.Duration, task.SearchAlert.NextRunDate),
                                                         task.SearchAlert.AlertId,
                                                         task.SearchAlert.NotificationId,
                                                         jobParameters.JobRunId,
                                                         XmlUtility.SerializeObject(task.SearchAlert.DocumentQuery));
                }
                catch (EVException ex)
                {
                    HandleEVException(ex, MethodBase.GetCurrentMethod().Name, task);
                    statusFlag = Constants.FAILURE;
                }
                catch (Exception ex)
                {
                    // Handle exception in initialize
                    LogMessage(Constants.FAILED_MESSAGE + ex.Message, MethodBase.GetCurrentMethod().Name,
                               EventLogEntryType.Error, task);
                    statusFlag = Constants.FAILURE;
                }
            }
            return(statusFlag); // function return status.
        }
 /// <summary>
 /// Get filtered list of documents from the search context
 /// </summary>
 /// <param name="documentSelectionContext">The document selection context.</param>
 /// <param name="documentIndex">Index of the document.</param>
 /// <param name="filteredDocuments">The filtered documents.</param>
 /// <returns>
 /// List of filtered documents
 /// </returns>
 private int GetQualifiedDocuments(DocumentOperationBusinessEntity documentSelectionContext, int documentIndex, out List<FilteredDocumentBusinessEntity> filteredDocuments)
 {
     filteredDocuments = new List<FilteredDocumentBusinessEntity>();
     try
     {
         var documentQueryEntity = new DocumentQueryEntity
         {
             QueryObject = new SearchQueryEntity
             {
                 ReviewsetId = documentSelectionContext.SearchContext.ReviewSetId,
                 DatasetId = documentSelectionContext.SearchContext.DataSetId,
                 MatterId = documentSelectionContext.SearchContext.MatterId,
                 IsConceptSearchEnabled = documentSelectionContext.SearchContext.IsConceptSearchEnabled
             },
             DocumentStartIndex = documentIndex
         };
         documentQueryEntity.IgnoreDocumentSnippet = true;
         documentQueryEntity.QueryObject.QueryList.Add(new Query(documentSelectionContext.SearchContext.Query));
         //documentQueryEntity.SortFields.Add(new Sort { SortBy = "Relevance" });
         filteredDocuments = GetFilteredListOfDocuments(documentQueryEntity, documentSelectionContext);
     }
     catch (Exception ex)
     {
         if (ex.GetType() == typeof(EVException))
         {
             var evEx = (EVException)ex;
             if (!string.IsNullOrEmpty(evEx.GetErrorCode()))
             {
                 ex.Data[Constants.ErrorCode] = evEx.GetErrorCode();
                 ex.Data[Constants.Message] = evEx.ToUserString();
                 ex.Trace();
             }
             else
             {
                 Tracer.Error(string.Format("ProductionStartupWorker - {0}", Constants.ErrorInGetQualifiedDocuments));
             }
         }
         else
         {
             Tracer.Error(string.Format("ProductionStartupWorker - {0}", Constants.ErrorInGetQualifiedDocuments));
         }
     }
     return filteredDocuments.Count();
 }
        /// <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);
        }