/// <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);
        }
Esempio n. 2
0
 /// <summary>
 /// Add Tag value to the html
 /// </summary>
 /// <param name="sb">StringBuilder</param>
 /// <param name="alt">row count</param>
 /// <param name="tag">Tag Information Object</param>
 /// <returns>String Builder</returns>
 private static StringBuilder AddTags(StringBuilder sb, ref int alt, RVWTagBEO tag)
 {
     if ((++alt) % 2 > 0)
     {
         // Append tag related information to string builder
         sb.Append(String.Format("{0}{1}{2}", Constants.HtmlContentForTagNameStart, tag.TagDisplayName,
                                 Constants.HtmlContentForTagNameEnd));
     }
     else
     {
         // Append tag related information to string builder but with difference for odd and even rows we add extra css calss to alternate row
         sb.Append(String.Format("{0}{1}{2}", Constants.HtmlContentForTagNameStartAlternate, tag.TagDisplayName,
                                 Constants.HtmlContentForTagNameEnd));
     }
     return(sb);
 }
 private int CreateDocumentTag(RVWTagBEO tag)
 {
     try
     {
         var tagService = new RVWTagService(_session);
         var tagId      = tagService.AddTag(tag);
         return(tagId);
     }
     catch (Exception)
     {
         //LogJobException(ErrorCodes.ErrorDcbImportCreateEVDocumentTag, String.Format(Constants.ErrorCreateDocumentTag, tag.Name),
         //                                                                                                    false,
         //                                                                                                    exp.Message);
         Tracer.Error("Unable to create document tag.");
         return(Constants.InternalTagReturnErrorCode);
     }
 }
        /// <summary>
        /// To create dataset tags that are selected for law imprort
        /// </summary>
        private void CreateSelectedLawTags()
        {
            if (_jobParams == null)
            {
                _jobParams = GetJobParams(BootParameters);
            }
            if (_jobParams.MappingTags == null)
            {
                return;
            }
            _selectedTags = _jobParams.MappingTags;

            var allDatasetTags = RVWTagBO.GetTagDefinitions(_jobParams.MatterId.ToString(CultureInfo.InvariantCulture), _jobParams.CollectionId, "All", false, null);

            allDatasetTags = allDatasetTags ?? new List <RVWTagBEO>();

            foreach (var lawTag in _selectedTags.FindAll(x => string.IsNullOrEmpty(x.MappingTagId)))
            {
                var mappedDsTag = allDatasetTags.FirstOrDefault(
                    dsTag => string.IsNullOrEmpty(dsTag.Name) && dsTag.Name.ToLower().Equals(lawTag.MappingTagName));
                if (mappedDsTag != null)
                {
                    //If the tag is already created then continue
                    lawTag.MappingTagId = mappedDsTag.Id.ToString(CultureInfo.InvariantCulture);
                    continue;
                }
                var tag = new RVWTagBEO
                {
                    Name         = lawTag.MappingTagName,
                    IsSystemTag  = lawTag.IsSystemTag,
                    IsPrivateTag = false,
                    Scope        = TagScope.Document,
                    Type         = TagType.Tag,
                    MatterId     = _jobParams.MatterId,
                    CollectionId = _jobParams.CollectionId
                };
                lawTag.MappingTagId = RVWTagBO.CreateTag(tag).ToString(CultureInfo.InvariantCulture);
            }
        }
        private IEnumerable <RVWTagBEO> GetWellFormedTags(string tagname, string collectionid, long matterId)
        {
            var tagBEOs     = new List <RVWTagBEO>();
            var newTagBEOs  = new List <RVWTagBEO>();
            var parentTagId = 0;

            if (String.IsNullOrEmpty(tagname))
            {
                return(tagBEOs);
            }
            var tagnamelist    = tagname.Split('»');
            var actualTagIndex = tagnamelist.Length - 1;

            for (var i = 0; i < tagnamelist.Length; i++)
            {
                var rvwTag = new RVWTagBEO
                {
                    CollectionId = collectionid,
                    MatterId     = matterId,
                    CreatedBy    = _createdBy,
                    ModifiedBy   = _modifiedBy,
                    Type         = i == actualTagIndex ? TagType.Tag : TagType.TagFolder,
                    ParentTagId  = parentTagId,
                    Scope        = TagScope.Document,
                    IsHiddenTag  = false,
                    IsPrivateTag = false,
                    IsSystemTag  = false,
                    Name         = tagnamelist[i],
                    SearchToken  = tagnamelist[i]
                };

                var tagBEO = IsTagAlreadyExists(tagnamelist, i);
                if (tagBEO != null)
                {
                    parentTagId = tagBEO.Id;
                    tagBEOs.Add(tagBEO);
                    continue;
                }

                var nTagId = GetDocumentTag(rvwTag.Name, rvwTag.ParentTagId.ToString(), "Document",
                                            matterId: matterId.ToString(), collectionId: collectionid);
                switch (nTagId)
                {
                case Constants.TagNotAvailable:
                    nTagId = CreateDocumentTag(rvwTag);
                    break;

                case Constants.InternalTagReturnErrorCode:
                    return(tagBEOs);
                }

                if (Constants.InternalTagReturnErrorCode == nTagId)
                {
                    PersistInternalTagKeys(tagnamelist, newTagBEOs);
                    return(tagBEOs);
                }
                rvwTag.Id   = nTagId;
                parentTagId = rvwTag.Id;
                newTagBEOs.Add(rvwTag);
                tagBEOs.Add(rvwTag);
            }
            if (newTagBEOs.Count > 0)
            {
                PersistInternalTagKeys(tagnamelist, newTagBEOs);
            }
            return(tagBEOs);
        }
        /// <summary>
        /// To create dataset tags that are selected for law imprort 
        /// </summary>
        private void CreateSelectedLawTags()
        {
            if (_jobParams == null) _jobParams = GetJobParams(BootParameters);
            if (_jobParams.MappingTags == null) return;
            _selectedTags = _jobParams.MappingTags;
              
           var allDatasetTags=  RVWTagBO.GetTagDefinitions(_jobParams.MatterId.ToString(CultureInfo.InvariantCulture), _jobParams.CollectionId,"All",false, null);

            allDatasetTags = allDatasetTags ?? new List<RVWTagBEO>();

            foreach (var lawTag in _selectedTags.FindAll(x => string.IsNullOrEmpty(x.MappingTagId)))
            {

                var mappedDsTag= allDatasetTags.FirstOrDefault(
                    dsTag => string.IsNullOrEmpty(dsTag.Name) && dsTag.Name.ToLower().Equals(lawTag.MappingTagName));
                if (mappedDsTag != null)
                {
                    //If the tag is already created then continue 
                    lawTag.MappingTagId = mappedDsTag.Id.ToString(CultureInfo.InvariantCulture);
                    continue;
                }
                var tag = new RVWTagBEO
                {
                    Name = lawTag.MappingTagName,
                    IsSystemTag = lawTag.IsSystemTag,
                    IsPrivateTag = false,
                    Scope = TagScope.Document,
                    Type = TagType.Tag,
                    MatterId = _jobParams.MatterId,
                    CollectionId = _jobParams.CollectionId
                };
                lawTag.MappingTagId = RVWTagBO.CreateTag(tag).ToString(CultureInfo.InvariantCulture);
            }
        }
        /// <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>
 /// Add Tag value to the html
 /// </summary>
 /// <param name="sb">StringBuilder</param>
 /// <param name="alt">row count</param>
 /// <param name="tag">Tag Information Object</param>
 /// <returns>String Builder</returns>
 private static StringBuilder AddTags(StringBuilder sb, ref int alt, RVWTagBEO tag)
 {
     if ((++alt)%2 > 0)
     {
         // Append tag related information to string builder
         sb.Append(String.Format("{0}{1}{2}", Constants.HtmlContentForTagNameStart, tag.TagDisplayName,
             Constants.HtmlContentForTagNameEnd));
     }
     else
     {
         // Append tag related information to string builder but with difference for odd and even rows we add extra css calss to alternate row
         sb.Append(String.Format("{0}{1}{2}", Constants.HtmlContentForTagNameStartAlternate, tag.TagDisplayName,
             Constants.HtmlContentForTagNameEnd));
     }
     return sb;
 }
 private int CreateDocumentTag(RVWTagBEO tag)
 {
     try
     {
         var tagService = new RVWTagService(_session);
         var tagId = tagService.AddTag(tag);
         return tagId;
     }
     catch (Exception)
     {
         //LogJobException(ErrorCodes.ErrorDcbImportCreateEVDocumentTag, String.Format(Constants.ErrorCreateDocumentTag, tag.Name),
         //                                                                                                    false,
         //                                                                                                    exp.Message);
         Tracer.Error("Unable to create document tag.");
         return Constants.InternalTagReturnErrorCode;
     }
 }
        private IEnumerable<RVWTagBEO> GetWellFormedTags(string tagname, string collectionid, long matterId)
        {
            var tagBEOs = new List<RVWTagBEO>();
            var newTagBEOs = new List<RVWTagBEO>();
            var parentTagId = 0;
            if (String.IsNullOrEmpty(tagname))
            {
                return tagBEOs;
            }
            var tagnamelist = tagname.Split('»');
            var actualTagIndex = tagnamelist.Length - 1;
            for (var i = 0; i < tagnamelist.Length; i++)
            {
                var rvwTag = new RVWTagBEO
                                 {
                                     CollectionId = collectionid,
                                     MatterId = matterId,
                                     CreatedBy = _createdBy,
                                     ModifiedBy = _modifiedBy,
                                     Type = i == actualTagIndex ? TagType.Tag : TagType.TagFolder,
                                     ParentTagId = parentTagId,
                                     Scope = TagScope.Document,
                                     IsHiddenTag = false,
                                     IsPrivateTag = false,
                                     IsSystemTag = false,
                                     Name = tagnamelist[i],
                                     SearchToken = tagnamelist[i]
                                 };

                var tagBEO = IsTagAlreadyExists(tagnamelist, i);
                if (tagBEO != null)
                {
                    parentTagId = tagBEO.Id;
                    tagBEOs.Add(tagBEO);
                    continue;
                }

                var nTagId = GetDocumentTag(rvwTag.Name, rvwTag.ParentTagId.ToString(), "Document",
                                            matterId: matterId.ToString(), collectionId: collectionid);
                switch (nTagId)
                {
                    case Constants.TagNotAvailable:
                        nTagId = CreateDocumentTag(rvwTag);
                        break;
                    case Constants.InternalTagReturnErrorCode:
                        return tagBEOs;
                }

                if (Constants.InternalTagReturnErrorCode == nTagId)
                {
                    PersistInternalTagKeys(tagnamelist, newTagBEOs);
                    return tagBEOs;
                }
                rvwTag.Id = nTagId;
                parentTagId = rvwTag.Id;
                newTagBEOs.Add(rvwTag);
                tagBEOs.Add(rvwTag);
            }
            if (newTagBEOs.Count > 0)
                PersistInternalTagKeys(tagnamelist, newTagBEOs);
            return tagBEOs;
        }