Exemplo n.º 1
0
        protected override void ProcessMessage(PipeMessageEnvelope envelope)
        {
            var bulkTagRecord = (BulkTagRecord)envelope.Body;

            try
            {
                // Mock http context
                bulkTagRecord.CreatedByUserGuid.ShouldNotBeEmpty();
                MockSession(bulkTagRecord.CreatedByUserGuid);

                bulkTagRecord.Documents.ShouldNotBe(null);
                bulkTagRecord.TagDetails.ShouldNotBe(null);

                if (!bulkTagRecord.Documents.Any())
                {
                    return;
                }

                bulkTagRecord.Originator = Guid.NewGuid().ToString();

                //var bootObject = GetBootObject<BulkTagJobBusinessEntity>(BootParameters);

                // Dictionary to hold list of documents to update
                var documentList = bulkTagRecord.Documents.
                                   ToDictionary(a => a.DocumentId, a => a);

                //get Effective Tags for the give tag
                var effectiveTagList =
                    BulkTagBO.GetEfectiveTags(bulkTagRecord.MatterId.ToString(CultureInfo.InvariantCulture),
                                              new Guid(bulkTagRecord.CollectionId), bulkTagRecord.BinderId, bulkTagRecord.TagDetails.Id,
                                              byte.Parse((bulkTagRecord.TagDetails.IsOperationTagging ? "1" : "3"))).ToList();

                List <DocumentTagBEO> currentState;
                var newState =
                    BulkTagBO.ArriveNewTagState(bulkTagRecord.MatterId.ToString(CultureInfo.InvariantCulture),
                                                new Guid(bulkTagRecord.CollectionId), documentList, effectiveTagList,
                                                (bulkTagRecord.TagDetails.IsTagAllDuplicates ||
                                                 bulkTagRecord.TagDetails.TagBehaviors.Exists(
                                                     x => string.Compare(x.BehaviorName, Constants.TagAllDuplicatesBehaviorName, true,
                                                                         CultureInfo.InvariantCulture) == 0)),
                                                (bulkTagRecord.TagDetails.IsTagAllFamily || (
                                                     bulkTagRecord.TagDetails.TagBehaviors.Exists(
                                                         x =>
                                                         string.Compare(x.BehaviorName, Constants.TagAllFamilyBehaviorName, true,
                                                                        CultureInfo.InvariantCulture) == 0) ||
                                                     bulkTagRecord.TagDetails.TagBehaviors.Exists(
                                                         x =>
                                                         string.Compare(x.BehaviorName, Constants.TagAllThreadBehaviorName, true,
                                                                        CultureInfo.InvariantCulture) == 0))
                                                ), out currentState);

                bulkTagRecord.CurrentState = currentState;
                bulkTagRecord.NewState     = newState;


                var watch = new Stopwatch();
                watch.Start();
                Parallel.Invoke(
                    () =>
                {
                    MockSession(bulkTagRecord.CreatedByUserGuid);
                    List <DocumentTagBEO> vaultState;
                    var notification =
                        BulkTagBO.VaultTagUpdate(bulkTagRecord.MatterId.ToString(CultureInfo.InvariantCulture),
                                                 new Guid(bulkTagRecord.CollectionId), bulkTagRecord.BinderId,
                                                 bulkTagRecord.CurrentState, bulkTagRecord.NewState, bulkTagRecord.CreatedByUserGuid,
                                                 out vaultState);

                    BulkTagBO.ArriveNotificationStatistics(
                        bulkTagRecord.MatterId.ToString(CultureInfo.InvariantCulture),
                        bulkTagRecord.TagDetails.Id, bulkTagRecord.CurrentState, bulkTagRecord.NewState, vaultState,
                        notification);

                    notification.ShouldNotBe(null);
                    bulkTagRecord.Notification = notification;
                    bulkTagRecord.VaultState   = vaultState;
                    bulkTagRecord.TagTimeStamp = DateTime.UtcNow;
                },

                    () =>
                {
                    MockSession(bulkTagRecord.CreatedByUserGuid);
                    BulkTagBO.IndexTagUpdate
                        (bulkTagRecord.MatterId.ToString(CultureInfo.InvariantCulture),
                        bulkTagRecord.CollectionId,
                        bulkTagRecord.CurrentState, bulkTagRecord.NewState);
                    Tracer.Info("{0} Documents queueued for indexing for JobRunId : {1} against the tag : {2}",
                                bulkTagRecord.Documents.Count, PipelineId, bulkTagRecord.TagDetails.Name);
                }

                    //TODO: Search Engine Replacement - Search Sub System - Update Tag details in search index
                    );
                watch.Stop();
                Tracer.Info("Total time in parallel update in vault & search subsystem is {0} milli seconds",
                            watch.Elapsed.TotalMilliseconds);
                Send(bulkTagRecord);
            }
            catch (Exception ex)
            {
                LogMessage(true, string.Format("Error in TagLogicWorker - Exception: {0}", ex.ToUserString()),
                           bulkTagRecord.CreatedByUserGuid);
                ReportToDirector(ex);
                ex.Trace().Swallow();
            }
        }
        /// <summary>
        /// Tag the documents with not reviewed tag
        /// </summary>
        /// <param name="reviewsetRecord">Reviewset Record</param>
        /// <param name="tempList">List of documents added to reviewset</param>
        private void TagDocumentsNotReviewed(DocumentRecordCollection reviewsetRecord,
                                             List <ReviewsetDocumentBEO> tempList)
        {
            reviewsetRecord.ShouldNotBe(null);
            tempList.ShouldNotBe(null);
            var matterId     = reviewsetRecord.ReviewsetDetails.MatterId.ToString(CultureInfo.InvariantCulture);
            var collectionId = reviewsetRecord.ReviewsetDetails.CollectionId;

            //var currentUser = EVSessionManager.Get<UserSessionBEO>(Constants.UserSessionInfo);
            var documentTagObjects = new List <DocumentTagBEO>();

            var _binderDetail = BinderVaultManagerInstance.GetBinderSpecificDetails(matterId,
                                                                                    reviewsetRecord.ReviewsetDetails.BinderId);

            _binderDetail.ShouldNotBe(null);
            _binderDetail.NotReviewedTagId.ShouldBeGreaterThan(0);
            _binderDetail.ReviewedTagId.ShouldBeGreaterThan(0);
            reviewsetRecord.ReviewsetDetails.NotReviewedTagId = _binderDetail.NotReviewedTagId;
            reviewsetRecord.ReviewsetDetails.ReviewedTagId    = _binderDetail.ReviewedTagId;


            var docsInfo = ConvertToBulkDocumentInfoBEO(tempList);

            //dictionary to hold list of documents to update
            var documentList = docsInfo.ToDictionary(a => a.DocumentId, a => a);

            //get Effective Tags for the give tag
            var effectiveTagList =
                BulkTagBO.GetEfectiveTags(matterId, new Guid(collectionId), _binderDetail.BinderId,
                                          _binderDetail.NotReviewedTagId, Constants.One).ToList();

            var currentState = new List <DocumentTagBEO>();
            var newState     = new List <DocumentTagBEO>();

            //get the list of tags with current status for the documents to be tagged
            currentState.AddRange(DocumentVaultManager.GetDocumentTags(matterId, new Guid(collectionId),
                                                                       documentList.Keys.ToList()));
            //for every tag from the effective list of tags to be updated
            foreach (var tag in effectiveTagList)
            {
                newState.AddRange(
                    documentList.Values.Select(
                        x =>
                        new DocumentTagBEO
                {
                    TagId            = tag.TagId,
                    Status           = tag.TagState,
                    DocumentId       = x.DocumentId,
                    DCN              = x.DCN,
                    TagTypeSpecifier = tag.type,
                    TagName          = tag.TagName
                }));
            }

            //get all the documents that is not part of current documents list and update to vault
            var vaultChanges = newState.Except(currentState, new DocumentTagComparer()).Distinct().ToList();

            //Remove the entries that are already untagged but are marked for untagging
            vaultChanges.RemoveAll(document => document.Status == Constants.Untagged &&
                                   currentState.Exists(
                                       y =>
                                       y.TagId == document.TagId &&
                                       String.Compare(y.DocumentId, document.DocumentId,
                                                      StringComparison.OrdinalIgnoreCase) == 0) == false);

            /* The following statement will take the untagged documents in the new state and
             * make it as list of tagged documents so that except operator in the next statement
             * remove all the tagged documents in the current state that have
             * been untagged now.*/
            var newstateUntaggedDocuments = newState.Where(t => t.Status != Constants.Tagged).Select(t =>
                                                                                                     new DocumentTagBEO {
                TagId = t.TagId, DocumentId = t.DocumentId, Status = Constants.Tagged
            }).ToList();

            //Determine Tag changes to update in search index..This has to be supplied for IndexTaggerWorker to take care in search-engine
            var indexChanges = reviewsetRecord.DocumentTags = currentState.FindAll(currentStateOfDocument =>
                                                                                   (newstateUntaggedDocuments.Find(newStateOfDocument =>
                                                                                                                   currentStateOfDocument.TagId == newStateOfDocument.TagId &&
                                                                                                                   currentStateOfDocument.DocumentId == newStateOfDocument.DocumentId &&
                                                                                                                   currentStateOfDocument.Status == newStateOfDocument.Status) == null)).Union(newState).
                                                              Distinct(new DocumentTagBEO()).ToList();

            DocumentVaultManager.UpdateDocumentTags(matterId, new Guid(collectionId), _binderDetail.BinderId,
                                                    vaultChanges, indexChanges, _createdBy);
            Send(reviewsetRecord);
        }