Exemple #1
0
        protected override void ProcessMessage(PipeMessageEnvelope envelope)
        {
            var reviewsetRecord = (DocumentRecordCollection)envelope.Body;

            splitReviewsetId   = reviewsetRecord.ReviewsetDetails.ReviewSetId;
            splitReviewsetName = reviewsetRecord.ReviewsetDetails.ReviewSetName;

            try
            {
                if (EVHttpContext.CurrentContext == null)
                {
                    MockSession();
                }
                //get all the documents from all the instances
                m_TotalDocumentCount = reviewsetRecord.TotalDocumentCount;
                m_TotalDocumentCount.ShouldBeGreaterThan(0);
                reviewsetRecord.Documents.ShouldNotBe(null);
                //get all the documents from all the search worker instances
                m_ReceivedDocuments.AddRange(reviewsetRecord.Documents);


                //Review set(s) will be created only during first times and documents will be associated to created review sets
                //once review sets are created, do not create again
                if (m_AllReviewsets.Count.Equals(0))
                {
                    using (new EVTransactionScope(TransactionScopeOption.Suppress))
                    {
                        // Babugx : To do - Replace ReviewsetBO call with BinderBO call, once current VaultID empty issue resolved
                        // m_AllReviewSetinBinder = BinderBO.GetAllReviewSetsForBinder(reviewsetRecord.ReviewsetDetails.BinderFolderId.ToString());
                        //this.m_AllReviewSetinBinder = ReviewSetBO.GetAllReviewSetForDataSet(reviewsetRecord.ReviewsetDetails.DatasetId.ToString());
                        this.m_AllReviewSetinBinder = BinderBO.GetAllReviewSetsForBinder(reviewsetRecord.ReviewsetDetails.BinderFolderId.ToString(),
                                                                                         reviewsetRecord.ReviewsetDetails.BinderId,
                                                                                         reviewsetRecord.ReviewsetDetails.DatasetId.ToString(),
                                                                                         reviewsetRecord.ReviewsetDetails.MatterId.ToString()).ToList();
                    }

                    if (m_AllReviewSetinBinder.Any() && reviewsetRecord.ReviewsetDetails.Activity == Constants.SplitActivity)
                    {
                        if (m_AllReviewSetinBinder.Exists(rs => rs.ReviewSetId.Equals(splitReviewsetId)))
                        {
                            m_TotalDocumentsInSplitReviewSet =
                                Convert.ToInt32(
                                    m_AllReviewSetinBinder.FirstOrDefault(rs => rs.ReviewSetId.Equals(splitReviewsetId))
                                    .NumberOfDocuments);
                        }
                        iSetStartNo = GetReviewSetStartingNumber(m_AllReviewSetinBinder, splitReviewsetName);
                    }

                    //check for reviewset splitting logic
                    //1. Single Review set
                    //If the splitting option is "Single" reviewset then no property need to be changed
                    //Keep Family and Keep duplicates also need not be considered

                    if (reviewsetRecord.ReviewsetDetails.Activity != Constants.SplitActivity && reviewsetRecord.ReviewsetDetails.SplittingOption.ToLower().Equals("single"))
                    {
                        //only one reviewset will be created
                        CreateSingleReviewset(reviewsetRecord);
                    }
                    //2. Distribute evenly
                    //if splitting option is "Distribute", based on the options reviewset name must be changed
                    //Keep family and Keep duplicates together need to be considered
                    //Considers documents in a family and duplicates are sent in one batch from search worker

                    /*
                     * Conditions to check
                     * ===================
                     * 1. If total documents is greater than or equal to number of documents per set, then only one reviewset will
                     *    be created and the reviewset name will not have any number
                     * 2. If number of review set is one, then only one reviewset will be created and the reviewset name will not have any number
                     * 3. If number of documents per set is specified and if number of documents is odd and have remaining documents then add one more
                     *    reviewset and add remaining documents to that. But this will not have exact number of documents that was set originally
                     * 4. If number of reviewset is specified and if number of documents cannot be divided equally, then reminder document will be
                     *    added to the last one. But this will not have exact number of documents that was set originally
                     * 5. Say, if there are 30 documents and every 3 documents are duplicates. Say user inputs to create reviewset with 2 docs per set, originally
                     *    it will create 15 reviewsets but documents will be assigned to only 10 reviewsets and rest of the other 5 reviewsets will be having
                     *    document count as "0".
                     * 6. Say, if there are 30 documents and every 3 documents are in a family. Say user inputs to create reviewset with 2 docs per set, originally
                     *    it will create 15 reviewsets but documents will be assigned to only 10 reviewsets and rest of the other 5 reviewsets will be having
                     *    document count as "0".
                     * 7. Do not remove any reviewset that needs to hold "0"    documents // todo: confirm with Paul
                     */

                    //calculate total number of documents in a reviewset based on splitting options
                    if (reviewsetRecord.ReviewsetDetails.Activity == Constants.SplitActivity || reviewsetRecord.ReviewsetDetails.SplittingOption.ToLower().Equals("distribute"))
                    {
                        //get the user values from reviewset details
                        m_KeepDuplicates = reviewsetRecord.ReviewsetDetails.KeepDuplicatesTogether;
                        m_KeepFamilies   = reviewsetRecord.ReviewsetDetails.KeepFamilyTogether;

                        //check what is the condition
                        //  a. documents per set
                        if (!reviewsetRecord.ReviewsetDetails.NumberOfDocumentsPerSet.Equals(0))
                        {
                            //Condition 1 from above list
                            if (m_TotalDocumentCount <= reviewsetRecord.ReviewsetDetails.NumberOfDocumentsPerSet)
                            {
                                //only one reviewset will be created
                                CreateSingleReviewset(reviewsetRecord);
                            }
                            else
                            {
                                //do not process till all the documents are collected
                                if (m_ReceivedDocuments.Count.Equals(m_TotalDocumentCount) ||
                                    (m_ReceivedDocuments.Count > m_TotalDocumentCount && reviewsetRecord.ReviewsetDetails.Activity == Constants.SplitActivity))
                                {
                                    //split the documents and create reviewsets based on the number of documents per set
                                    SplitReviewsetOnNumberofDocs(reviewsetRecord);
                                }
                            }
                        }

                        //  b. total number of review sets
                        if (!reviewsetRecord.ReviewsetDetails.NumberOfReviewSets.Equals(0))
                        {
                            //Condition 2 from above list
                            if (reviewsetRecord.ReviewsetDetails.NumberOfReviewSets.Equals(1))
                            {
                                //only one reviewset will be created
                                CreateSingleReviewset(reviewsetRecord);
                            }
                            else
                            {
                                //do not process till all the documents are collected
                                if (m_ReceivedDocuments.Count.Equals(m_TotalDocumentCount) ||
                                    (m_ReceivedDocuments.Count > m_TotalDocumentCount && reviewsetRecord.ReviewsetDetails.Activity == Constants.SplitActivity))
                                {
                                    //split documents and create reviewset based on number of reviewset
                                    SplitDocumentsOnNumberofReviewsets(reviewsetRecord);
                                }
                            }
                        }
                    }
                }

                //send to vault worker after creating reviewset
                foreach (KeyValuePair <string, ReviewsetDetails> reviewset in m_AllReviewsets)
                {
                    if (!string.IsNullOrEmpty(reviewset.Key))
                    {
                        if (m_ReceivedDocuments.Count > 0)
                        {
                            //if calculated document count is already filled then move on to next reviewset in the list
                            if (reviewset.Value.FilledDocs.Equals(reviewset.Value.CalculatedNoOfDocs))
                            {
                                continue;
                            }


                            if (reviewsetRecord.ReviewsetDetails.Activity == Constants.SplitActivity)
                            {
                                reviewsetRecord.ReviewsetDetails.SplitReviewSetId      = splitReviewsetId;
                                reviewsetRecord.ReviewsetDetails.SplitReviewSetName    = splitReviewsetName;
                                reviewsetRecord.ReviewsetDetails.SplitPreDocumentCount = m_TotalDocumentsInSplitReviewSet;
                            }

                            reviewsetRecord.ReviewsetDetails.ReviewSetName = reviewset.Value.ReviewsetName;

                            //if there are any documents to send in last batch then add 1
                            int batchCount = ((reviewset.Value.CalculatedNoOfDocs % m_BatchSize) > 0) ? (reviewset.Value.CalculatedNoOfDocs / m_BatchSize) + 1 : (reviewset.Value.CalculatedNoOfDocs / m_BatchSize);
                            reviewsetRecord.ReviewsetDetails.NumberOfBatches = batchCount;

                            reviewsetRecord.ReviewsetDetails.NumberOfDocuments = reviewset.Value.CalculatedNoOfDocs;

                            reviewsetRecord.ReviewsetDetails.ReviewSetId = reviewset.Key;
                            SendtoVaultWorker(reviewsetRecord);
                            if (string.IsNullOrEmpty(m_splitReviewsetNames))
                            {
                                m_splitReviewsetNames = reviewset.Value.ReviewsetName;
                            }
                            else
                            {
                                m_splitReviewsetNames = string.Format("{0},{1}", m_splitReviewsetNames, reviewset.Value.ReviewsetName);
                            }


                            //if this reviewset itself is not complete then do not execute for other reviewsets
                            if (!reviewset.Value.FilledDocs.Equals(reviewset.Value.CalculatedNoOfDocs))
                            {
                                break;
                            }
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                ReportToDirector(ex);
                ex.Trace().Swallow();
                LogMessage(false, string.Format("Error in ReviewsetLogicWorker - Exception: {0}", ex.ToUserString()),
                           reviewsetRecord.ReviewsetDetails.CreatedBy, reviewsetRecord.ReviewsetDetails.ReviewSetName);
            }
        }
        /// <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>
        /// 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);
        }