Пример #1
0
        private bool DumpTextToFile(RVWDocumentBEO rVwDocumentBEO, string contentText, JobWorkerLog <DcbParserLogInfo> dcbParserLogEntry)
        {
            TextFileFolder.ShouldNotBe(null);
            if (string.IsNullOrEmpty(contentText))
            {
                return(true);
            }

            string filePath = Path.Combine(TextFileFolder, rVwDocumentBEO.DocumentId + Constants.FileExtension);

            File.AppendAllText(filePath, contentText);

            if (rVwDocumentBEO.DocumentBinary == null)
            {
                rVwDocumentBEO.DocumentBinary = new RVWDocumentBinaryBEO();
            }
            RVWExternalFileBEO textFile = new RVWExternalFileBEO
            {
                Type = TEXT_FILE_TYPE,
                Path = filePath
            };

            rVwDocumentBEO.DocumentBinary.FileList.Add(textFile);
            return(true);
        }
Пример #2
0
 /// <summary>
 /// Creates the and update external file entity for native set.
 /// </summary>
 /// <param name="document">The document.</param>
 private static void CreateAndUpdateExternalFileEntityForNativeSet(RVWDocumentBEO document)
 {
     try
     {
         //Insert document binary, if any -- to do: Should we need call this @ this place
         if (document != null && !StringUtility.IsNullOrWhiteSpace(document.NativeFilePath))
         {
             RVWExternalFileBEO externalFile = new RVWExternalFileBEO();
             externalFile.Type = "Native";
             externalFile.Path = document.NativeFilePath;
             document.DocumentBinary.FileList.Add(externalFile);
         }
         else
         {
             throw new EVException().AddErrorCode(ErrorCodes.EDLoaderExtractionWorker_NativeFileNotAvailable);
         }
     }
     catch (Exception ex)
     {
         ex.Trace().Swallow();
     }
 }
Пример #3
0
        /// <summary>
        /// Construct Nativeset & ImageSet
        /// </summary>
        private List <DocumentDetail> ConstructNativeImageSet(bool isNewRecord, bool isNewImageSet, DocumentDetail docDetail, List <string> misMatchedFields, List <string> misMatchedFieldsMessage)
        {
            List <DocumentDetail> documentDetailList = new List <DocumentDetail>();
            //1) Construct Native Set
            var nativeSetDocument = GetDocumentForNativeSet(docDetail.document, misMatchedFields, misMatchedFieldsMessage);
            var doc = new DocumentDetail();

            doc.CorrelationId        = docDetail.CorrelationId;
            doc.docType              = DocumentsetType.NativeSet;
            doc.document             = nativeSetDocument;
            doc.ParentDocId          = docDetail.ParentDocId;
            doc.IsNewDocument        = isNewRecord;
            doc.ConversationIndex    = docDetail.ConversationIndex;
            doc.OverlayReImportField = docDetail.OverlayReImportField;
            doc.Reviewsets           = docDetail.Reviewsets;
            #region Check Same Content File
            string existingContentFilePath = GetExistingContentFile(nativeSetDocument.CollectionId, nativeSetDocument.DocumentId);
            string contentFilePath         = string.Empty;
            if (nativeSetDocument.DocumentBinary.FileList != null && nativeSetDocument.DocumentBinary.FileList.Where(f => f.Type == Constants.TEXT_FILE_TYPE).FirstOrDefault() != null)
            {
                contentFilePath = (!string.IsNullOrEmpty(nativeSetDocument.DocumentBinary.FileList.Where(f => f.Type == Constants.TEXT_FILE_TYPE).FirstOrDefault().Path) ? nativeSetDocument.DocumentBinary.FileList.Where(f => f.Type == Constants.TEXT_FILE_TYPE).FirstOrDefault().Path : string.Empty);
            }
            if (!string.IsNullOrEmpty(existingContentFilePath)) //If text File is exist during Append
            {
                if (!string.IsNullOrEmpty(contentFilePath))
                {
                    if (existingContentFilePath.Trim().ToLower() != contentFilePath.Trim().ToLower()) //New Content File Used in Overlay
                    {
                        doc.OverlayIsNewContentFile = true;
                    }
                }
                else  //If there is no text File during overlay , Need to maintain old content File
                {
                    doc.OverlayIsNewContentFile = false;
                    RVWExternalFileBEO file = new RVWExternalFileBEO
                    {
                        Type = Constants.TEXT_FILE_TYPE,
                        Path = existingContentFilePath
                    };
                    doc.document.DocumentBinary.FileList.Add(file);
                }
            }
            else if (string.IsNullOrEmpty(nativeSetDocument.CustomFieldToPopulateText) && !string.IsNullOrEmpty(contentFilePath)) //If there is no text File during Append
            {
                doc.OverlayIsNewContentFile = true;
            }
            else if (!string.IsNullOrEmpty(contentFilePath))
            {
                doc.OverlayIsNewContentFile = false;
            }
            #endregion

            doc.SystemTags = m_JobParameter.SystemTags;
            doc.document.DocumentControlNumber = docDetail.document.DocumentControlNumber;

            documentDetailList.Add(doc);

            //2) Construct Image Set
            if (m_JobParameter.IsImportImages && !string.IsNullOrEmpty(m_JobParameter.ImageSetId))
            {
                var imageSetDocument = GetDocumentForImageSet(docDetail.document, m_JobParameter.ImageSetId);
                var docImg           = new DocumentDetail();
                docImg.CorrelationId = docDetail.CorrelationId;
                docImg.docType       = DocumentsetType.ImageSet;
                docImg.document      = imageSetDocument;
                docImg.IsNewDocument = isNewImageSet;
                documentDetailList.Add(docImg);
            }
            return(documentDetailList);
        }
Пример #4
0
        /// <summary>
        /// Method to import document images
        /// </summary>
        /// <param name="currentDocumentId">current DocumentId</param>
        /// <param name="currentDcbDocument">current Dcb Document</param>
        /// <returns>RVWDocumentBEO entity</returns>
        private RVWDocumentBEO ImportDocumentImages(string currentDocumentId, Document currentDcbDocument)
        {
            RVWDocumentBEO evImageDocument = new RVWDocumentBEO();

            try
            {
                if ((currentDcbDocument.Images != null) && (currentDcbDocument.Images.Count > 0))
                {
                    int imageSize = 0;
                    evImageDocument = new RVWDocumentBEO
                    {
                        DocumentId   = currentDocumentId,
                        CollectionId = ImageSetId,
                        MatterId     = DcbOpticonJobBEO.MatterId
                    };


                    foreach (DcbImage imageObj in currentDcbDocument.Images)
                    {
                        RVWExternalFileBEO rvwExternalfilebeo = new RVWExternalFileBEO
                        {
                            Path = imageObj.ImageData.FullImagePath,
                            Type = Constants.Image
                        };
                        evImageDocument.DocumentBinary.FileList.Add(rvwExternalfilebeo);
                        if (File.Exists(rvwExternalfilebeo.Path))
                        {
                            //Calculating size of file in KB
                            FileInfo fileInfo = new FileInfo(rvwExternalfilebeo.Path);
                            if (fileInfo != null)
                            {
                                imageSize += (int)Math.Ceiling(fileInfo.Length / Constants.KBConversionConstant);
                            }
                        }
                    }

                    #region Assertion
                    evImageDocument.DocumentBinary.FileList.ShouldNotBe(null);
                    evImageDocument.DocumentBinary.FileList.Count.ShouldBeGreaterThan(0);
                    #endregion

                    string createdByGuid = String.Empty;
                    if (null != ProfileBEO && null != ProfileBEO.CreatedBy)
                    {
                        createdByGuid = ProfileBEO.CreatedBy;
                    }
                    evImageDocument.CreatedBy      = createdByGuid;
                    evImageDocument.ModifiedBy     = createdByGuid;
                    evImageDocument.MimeType       = string.Empty;
                    evImageDocument.FileName       = string.Empty;
                    evImageDocument.NativeFilePath = string.Empty;
                    evImageDocument.FileExtension  = string.Empty;
                    evImageDocument.FileSize       = imageSize;
                    return(evImageDocument);
                }
            }
            catch (Exception ex)
            {
                ex.Trace().Swallow();
            }
            return(null);
        }
Пример #5
0
        protected void FetchDocumentFromDCB(int documentNumber,
                                            List <DocumentDetail> documentDetailList, FamiliesInfo familiesInfo, JobWorkerLog <DcbParserLogInfo> dcbParserLogEntry)
        {
            #region Precondition asserts
            documentDetailList.ShouldNotBe(null);
            dcbParserLogEntry.ShouldNotBe(null);
            #endregion
            RVWDocumentBEO evDocument = new RVWDocumentBEO();
            try
            {
                //Get the document from DcbFacade
                Document currentDcbDocument = DcbFacade.GetDocument(documentNumber);

                //Throw exception if GetDocument fails
                currentDcbDocument.ShouldNotBe(null);

                //Create the target EV document
                evDocument.DocumentId = Guid.NewGuid().ToString().Replace("-", "").ToUpper();
                dcbParserLogEntry.LogInfo.DocumentId = evDocument.DocumentId;
                evDocument.CollectionId = DcbOpticonJobBEO.TargetDatasetId;
                evDocument.MatterId     = DcbOpticonJobBEO.MatterId;

                //Add the fields required for casemap
                RVWDocumentFieldBEO evDocumentAccessionNumField = new RVWDocumentFieldBEO
                {
                    FieldId       = Convert.ToInt32(DcbOpticonJobBEO.SysDocId),
                    FieldName     = EVSystemFields.DcbId,
                    IsSystemField = true,
                    IsRequired    = true,
                    FieldValue    = Convert.ToString(currentDcbDocument.UUID, CultureInfo.InvariantCulture)
                };
                evDocument.FieldList.Add(evDocumentAccessionNumField);
                evDocument.FieldList.Add(_evDocumentSysImportTypeField);

                //Set the fields from field mapping except content field
                foreach (FieldMapBEO fieldMap in DcbOpticonJobBEO.FieldMappings)
                {
                    Field dcbField = currentDcbDocument.FieldItems.Find(o => (o.Code == fieldMap.SourceFieldID));

                    //Profile fieldmapping has duplicates
                    RVWDocumentFieldBEO evDocumentFieldBEO = evDocument.FieldList.Find(o => o.FieldId.Equals(fieldMap.DatasetFieldID));
                    if ((null != dcbField) && (evDocumentFieldBEO == null) && (fieldMap.DatasetFieldID != _contentFieldId))
                    {
                        RVWDocumentFieldBEO evDocuemtnField = new RVWDocumentFieldBEO
                        {
                            FieldId   = fieldMap.DatasetFieldID,
                            FieldName = fieldMap.DatasetFieldName
                        };


                        FieldBEO evfieldDef = _dataset.DatasetFieldList.Find(o => o.ID == evDocuemtnField.FieldId);
                        evDocuemtnField.FieldValue = evfieldDef.FieldType.DataTypeId == Constants.DateDataType
                                                         ? GetDateFiedlValue(dcbField, dcbParserLogEntry)
                                                         : Regex.Replace(dcbField.Value, "\r\n", "\n");
                        evDocument.FieldList.Add(evDocuemtnField);
                    }
                }

                //Separate logic for content
                StringBuilder sbContent = new StringBuilder();
                if (DcbOpticonJobBEO.ContentFields != null)
                {
                    foreach (string contentfield in DcbOpticonJobBEO.ContentFields.Field)
                    {
                        Field dcbContentField = currentDcbDocument.FieldItems.Find(o => (o.Name.Equals(contentfield)));
                        if (null != dcbContentField)
                        {
                            sbContent.Append(dcbContentField.Value);
                        }
                    }
                }
                string text = sbContent.ToString().Replace("\r\n", "\n");
                //evDocument.DocumentBinary.Content = Regex.Replace(sbContent.ToString(), "\r\n", "\n");

                if (!DumpTextToFile(evDocument, text, dcbParserLogEntry))
                {
                    return;
                }

                //Set the native file path if selected
                evDocument.NativeFilePath = GetNativeFilePath(currentDcbDocument);

                if (!String.IsNullOrEmpty(evDocument.NativeFilePath) && File.Exists(evDocument.NativeFilePath))
                {
                    FileInfo fileInfo = new FileInfo(evDocument.NativeFilePath);
                    //Tracer.Trace("DcbParcer located native document {0} for DocumentId = {1} and the file length is {2}",
                    //    evDocument.NativeFilePath, evDocument.DocumentId, fileInfo.Length);
                    if (fileInfo.Length > 0)
                    {
                        evDocument.FileSize = (int)Math.Ceiling(fileInfo.Length / 1024.0);
                    }
                    else
                    {
                        evDocument.FileSize = 0;
                    }

                    evDocument.MD5HashValue = DocumentHashHelper.GetMD5HashValue(evDocument.NativeFilePath);
                    evDocument.SHAHashValue = DocumentHashHelper.GetSHAHashValue(evDocument.NativeFilePath);
                }

                //Set the MIME type
                string extn    = string.Empty;
                string newExtn = string.Empty;
                extn = Path.GetExtension(evDocument.NativeFilePath);
                if (!String.IsNullOrEmpty(extn))
                {
                    newExtn = extn.Remove(0, 1);
                }
                evDocument.MimeType      = GetMimeType(newExtn);
                evDocument.FileExtension = extn;

                string createdByGuid = String.Empty;
                if (null != ProfileBEO && null != ProfileBEO.CreatedBy)
                {
                    createdByGuid = ProfileBEO.CreatedBy;
                }
                evDocument.CreatedBy  = createdByGuid;
                evDocument.ModifiedBy = createdByGuid;

                if (File.Exists(evDocument.NativeFilePath))
                {
                    //Calculating size of file in KB
                    FileInfo fileInfo = new FileInfo(evDocument.NativeFilePath);
                    evDocument.FileSize = (int)Math.Ceiling(fileInfo.Length / Constants.KBConversionConstant);

                    if (evDocument.DocumentBinary == null)
                    {
                        evDocument.DocumentBinary = new RVWDocumentBinaryBEO();
                    }
                    RVWExternalFileBEO nativeFile = new RVWExternalFileBEO
                    {
                        Type = NATIVE_FILE_TYPE,
                        Path = evDocument.NativeFilePath
                    };
                    evDocument.DocumentBinary.FileList.Add(nativeFile);
                }

                DocumentDetail documentDetail = new DocumentDetail
                {
                    // CorrId is the same as TaskId and it is 1 based.
                    CorrelationId = checked (documentNumber + 1).ToString(CultureInfo.InvariantCulture),
                    IsNewDocument = true,
                    docType       = DocumentsetType.NativeSet,
                    document      = evDocument
                };
                documentDetailList.Add(documentDetail);

                //Add Tags
                if (DcbOpticonJobBEO.IncludeTags && null != currentDcbDocument.TagItems && currentDcbDocument.TagItems.Count > 0)
                {
                    if (null == documentDetail.DcbTags)
                    {
                        documentDetail.DcbTags = new List <DcbTags>();
                    }
                    DcbDocumentTags dcbDocumentTags = new DcbDocumentTags
                    {
                        compositeTagNames = currentDcbDocument.TagItems,
                        DatasetId         = DcbOpticonJobBEO.TargetDatasetId,
                        MatterId          = DcbOpticonJobBEO.MatterId,
                        DocumentId        = evDocument.DocumentId
                    };
                    documentDetail.DcbTags.Add(dcbDocumentTags);
                }

                // Add notes
                AddComments(documentDetail, evDocument, currentDcbDocument);

                //Add Images
                if (DcbOpticonJobBEO.ImportImages)
                {
                    RVWDocumentBEO images = ImportDocumentImages(evDocument.DocumentId, currentDcbDocument);
                    if (null != images)
                    {
                        DocumentDetail imageDocumentDetail = new DocumentDetail
                        {
                            // CorrId is the same as TaskId and it is 1 based.
                            CorrelationId = checked (documentNumber + 1).ToString(CultureInfo.InvariantCulture),
                            IsNewDocument = true,
                            docType       = DocumentsetType.ImageSet,
                            document      = images
                        };
                        documentDetailList.Add(imageDocumentDetail);
                        dcbParserLogEntry.LogInfo.AddedImages = images.DocumentBinary.FileList.Count;
                    }

                    //Add Redlines
                    //ImportDocumentRedlines();
                }

                //Add Document Relation
                if (DcbOpticonJobBEO.IsImportFamilies)
                {
                    ImportDocumentRelationship(evDocument.DocumentId, currentDcbDocument, familiesInfo);
                }
                #region Postcondition asserts
                documentDetailList.ShouldNotBe(null);
                #endregion
            }
            catch (Exception ex)
            {
                //TaskLogInfo.AddParameters(Constants.ErrorDoAtomicWork + "<br/>" + ex.Message);
                //TaskLogInfo.StackTrace = ex.Source + "<br/>" + ex.Message + "<br/>" + ex.StackTrace;
                //TaskLogInfo.IsError = true;

                ex.Trace().Swallow();
                dcbParserLogEntry.Success = false;
                if (ex.ToUserString().Contains(Constants.DiskFullErrorMessage))
                {
                    dcbParserLogEntry.LogInfo.Message = "There is not enough space on the disk";
                    throw;
                }
                else
                {
                    dcbParserLogEntry.LogInfo.Message = ex.ToUserString();
                }
            }
        }
Пример #6
0
        /// <summary>
        /// Transform "EDRM document entity" to EV's Document BEO
        /// This function doesn't set field data
        /// Field data is set separately as there are two variances of this operation. </summary>
        /// 1) set all fields available in the EDRM file<param name="rvwDocumentBEO"></param>
        /// 2) set mapped fields only.
        /// </summary>
        /// <param name="rvwDocumentBEO"> Document Business Entity, by reference so that the transformed data is updated in this object. </param>
        /// <param name="edrmDocument"> EDRM document entity which is going tobe transformed to EV Document Business Entity. </param>
        protected virtual void TransformEDRMDocumentEntityToDocumentBusinessEntity(ref RVWDocumentBEO rvwDocumentBEO, DocumentEntity edrmDocument)
        {
            // Initialize if the object is not created
            if (rvwDocumentBEO == null)
                rvwDocumentBEO = new RVWDocumentBEO();

            // Document ID is MD5 hash of EDRM file + EDRM Document ID.
            // This makes document unique in the system and identifies if same EDRM file attempted to be imported twice.
            // Special character to 
            rvwDocumentBEO.DocumentId = GetDocumentId(edrmDocument);

            // Set MIME type
            rvwDocumentBEO.MimeType = edrmDocument.MIMEType;

            #region Add associate file details/names from EDRM file

            // NOTES: 
            // Binary and text is set later by the consuming module. This is to reduce weight of objects
            // Binary and text could increase memory by great extent.

            foreach (FileEntity fileEntity in edrmDocument.Files)
            {
                // Check if type is native
                if (fileEntity.FileType.ToLower().Equals(Constants.EDRMAttributeNativeFileType.ToLower()))
                {
                    // Set file path for native file types.
                    // Condition - check if native file entity has external file entities in it or not.
                    if (fileEntity.ExternalFile != null)
                    {
                        // Checks in below statement 1) null check on "file path" and 2) are there any external files
                        rvwDocumentBEO.FileName = (fileEntity.ExternalFile.Count > 0) ? fileEntity.ExternalFile[0].FileName : string.Empty;
                        rvwDocumentBEO.NativeFilePath = (fileEntity.ExternalFile.Count > 0) ? CreateFileURI(fileEntity.ExternalFile[0].FilePath, fileEntity.ExternalFile[0].FileName) : string.Empty;
                        rvwDocumentBEO.FileExtension = (fileEntity.ExternalFile.Count > 0) ? fileEntity.ExternalFile[0].FileName.Substring(fileEntity.ExternalFile[0].FileName.LastIndexOf(".")) : string.Empty;

                        if (!string.IsNullOrEmpty(rvwDocumentBEO.NativeFilePath) && File.Exists(rvwDocumentBEO.NativeFilePath))
                        {
                            //Calculating size of file in KB
                            FileInfo fileInfo = new FileInfo(rvwDocumentBEO.NativeFilePath);
                            rvwDocumentBEO.FileSize = (int)Math.Ceiling(fileInfo.Length / Constants.KBConversionConstant);
                        }
                    }
                }

                // Check if the type is Text.
                if (fileEntity.FileType.ToLower().Equals(Constants.EDRMAttributeTextFileType.ToLower()))
                {
                    if (fileEntity.ExternalFile != null)
                    {
                        // For text set file details in TextContent property. Set the real text just before import.
                        // This is to help reduce weight of the object.

                        // Checks in below statement 1) null check on "file path" and 2) are there any external files
                        if (rvwDocumentBEO.DocumentBinary == null) { rvwDocumentBEO.DocumentBinary = new RVWDocumentBinaryBEO(); }

                        RVWExternalFileBEO textFile = new RVWExternalFileBEO
                        {
                            Type = Constants.EDRMAttributeTextFileType,
                            Path = (fileEntity.ExternalFile.Count > 0) ? CreateFileURI(fileEntity.ExternalFile[0].FilePath, fileEntity.ExternalFile[0].FileName) : string.Empty
                        };

                        rvwDocumentBEO.DocumentBinary.FileList.Add(textFile);
                    }
                }
            }

            #endregion
        }
        /// <summary>
        /// Construct Nativeset & ImageSet
        /// </summary>
        private List <DocumentDetail> ConstructNativeImageSet(bool isNewRecord, bool isNewImageSet, DocumentDetail docDetail, List <string> misMatchedFields, List <string> misMatchedFieldsMessage)
        {
            var documentDetailList = new List <DocumentDetail>();
            //1) Construct Native Set
            var nativeSetDocument = GetDocumentForNativeSet(docDetail.document, misMatchedFields, misMatchedFieldsMessage);
            var doc = new DocumentDetail
            {
                CorrelationId        = docDetail.CorrelationId,
                docType              = DocumentsetType.NativeSet,
                document             = nativeSetDocument,
                ParentDocId          = docDetail.ParentDocId,
                IsNewDocument        = isNewRecord,
                ConversationIndex    = docDetail.ConversationIndex,
                OverlayReImportField = docDetail.OverlayReImportField
            };

            #region Check Same Content File

            var existingContentFilePath = GetExistingContentFile(nativeSetDocument.CollectionId, nativeSetDocument.DocumentId);
            var contentFilePath         = string.Empty;
            if (nativeSetDocument.DocumentBinary.FileList != null && nativeSetDocument.DocumentBinary.FileList.FirstOrDefault(f => f.Type == Constants.TEXT_FILE_TYPE) != null)
            {
                var rvwExternalFileBEO = nativeSetDocument.DocumentBinary.FileList.FirstOrDefault(f => f.Type == Constants.TEXT_FILE_TYPE);
                contentFilePath = (rvwExternalFileBEO != null && !string.IsNullOrEmpty(rvwExternalFileBEO.Path) ? rvwExternalFileBEO.Path : string.Empty);
            }
            if (!string.IsNullOrEmpty(existingContentFilePath)) //If text File is exist during Append
            {
                if (!string.IsNullOrEmpty(contentFilePath))
                {
                    if (existingContentFilePath.Trim().ToLower() != contentFilePath.Trim().ToLower()) //New Content File Used in Overlay
                    {
                        doc.OverlayIsNewContentFile = true;
                    }
                }
                else  //If there is no text File during overlay , Need to maintain old content File
                {
                    doc.OverlayIsNewContentFile = false;
                    var file = new RVWExternalFileBEO
                    {
                        Type = Constants.TEXT_FILE_TYPE,
                        Path = existingContentFilePath
                    };
                    doc.document.DocumentBinary.FileList.Add(file);
                }
            }
            else if (string.IsNullOrEmpty(nativeSetDocument.CustomFieldToPopulateText) && !string.IsNullOrEmpty(contentFilePath)) //If there is no text File during Append
            {
                doc.OverlayIsNewContentFile = true;
            }
            else if (!string.IsNullOrEmpty(contentFilePath))
            {
                doc.OverlayIsNewContentFile = false;
            }
            #endregion

            documentDetailList.Add(doc);

            //2) Construct Image Set
            if (_jobParams.IsImportImages && !string.IsNullOrEmpty(_jobParams.ImageSetId))
            {
                var imageSetDocument = GetDocumentForImageSet(docDetail.document, _jobParams.ImageSetId);
                var docImg           = new DocumentDetail
                {
                    CorrelationId = docDetail.CorrelationId,
                    docType       = DocumentsetType.ImageSet,
                    document      = imageSetDocument,
                    IsNewDocument = isNewImageSet
                };
                documentDetailList.Add(docImg);
            }
            return(documentDetailList);
        }
Пример #8
0
        /// <summary>
        /// Method to import document images
        /// </summary>
        /// <param name="currentDocumentId">current DocumentId</param>
        /// <param name="currentDcbDocument">current Dcb Document</param>
        /// <returns>RVWDocumentBEO entity</returns>
        private RVWDocumentBEO ImportDocumentImages(string currentDocumentId, Document currentDcbDocument)
        {
            RVWDocumentBEO evImageDocument = new RVWDocumentBEO();
            try
            {
                if ((currentDcbDocument.Images != null) && (currentDcbDocument.Images.Count > 0))
                {
                    int imageSize = 0;
                    evImageDocument = new RVWDocumentBEO
                                          {
                                              DocumentId = currentDocumentId,
                                              CollectionId = ImageSetId,
                                              MatterId = DcbOpticonJobBEO.MatterId
                                          };


                    foreach (DcbImage imageObj in currentDcbDocument.Images)
                    {
                        RVWExternalFileBEO rvwExternalfilebeo = new RVWExternalFileBEO
                                                                    {
                                                                        Path = imageObj.ImageData.FullImagePath,
                                                                        Type = Constants.Image
                                                                    };
                        evImageDocument.DocumentBinary.FileList.Add(rvwExternalfilebeo);
                        if (File.Exists(rvwExternalfilebeo.Path))
                        {
                            //Calculating size of file in KB
                            FileInfo fileInfo = new FileInfo(rvwExternalfilebeo.Path);
                            if (fileInfo != null)
                            {
                                imageSize += (int) Math.Ceiling(fileInfo.Length/Constants.KBConversionConstant);
                            }
                        }
                    }

                    #region Assertion
                    evImageDocument.DocumentBinary.FileList.ShouldNotBe(null);
                    evImageDocument.DocumentBinary.FileList.Count.ShouldBeGreaterThan(0); 
                    #endregion

                    string createdByGuid = String.Empty;
                    if (null != ProfileBEO && null != ProfileBEO.CreatedBy)
                    {
                        createdByGuid = ProfileBEO.CreatedBy;
                    }                    
                    evImageDocument.CreatedBy = createdByGuid;
                    evImageDocument.ModifiedBy = createdByGuid;
                    evImageDocument.MimeType = string.Empty;
                    evImageDocument.FileName = string.Empty;
                    evImageDocument.NativeFilePath = string.Empty;
                    evImageDocument.FileExtension = string.Empty;
                    evImageDocument.FileSize = imageSize;
                    return evImageDocument;
                }
            }
            catch (Exception ex)
            {
                ex.Trace().Swallow();
            }
            return null;
        }
Пример #9
0
        private bool DumpTextToFile(RVWDocumentBEO rVwDocumentBEO, string contentText, JobWorkerLog<DcbParserLogInfo> dcbParserLogEntry)
        {
            TextFileFolder.ShouldNotBe(null);
            if (string.IsNullOrEmpty(contentText)) return true;

            string filePath = Path.Combine(TextFileFolder, rVwDocumentBEO.DocumentId + Constants.FileExtension);
            File.AppendAllText(filePath, contentText);

            if (rVwDocumentBEO.DocumentBinary == null) { rVwDocumentBEO.DocumentBinary = new RVWDocumentBinaryBEO(); }
            RVWExternalFileBEO textFile = new RVWExternalFileBEO
            {
                Type = TEXT_FILE_TYPE,
                Path = filePath
            };
            rVwDocumentBEO.DocumentBinary.FileList.Add(textFile);
            return true;
        }
Пример #10
0
        protected void FetchDocumentFromDCB(int documentNumber,
            List<DocumentDetail> documentDetailList, FamiliesInfo familiesInfo, JobWorkerLog<DcbParserLogInfo> dcbParserLogEntry)
        {
            #region Precondition asserts
            documentDetailList.ShouldNotBe(null);
            dcbParserLogEntry.ShouldNotBe(null);
            #endregion
            RVWDocumentBEO evDocument = new RVWDocumentBEO();
            try
            {
                //Get the document from DcbFacade
                Document currentDcbDocument = DcbFacade.GetDocument(documentNumber);

                //Throw exception if GetDocument fails
                currentDcbDocument.ShouldNotBe(null);

                //Create the target EV document
                evDocument.DocumentId = Guid.NewGuid().ToString().Replace("-", "").ToUpper();
                dcbParserLogEntry.LogInfo.DocumentId = evDocument.DocumentId;
                evDocument.CollectionId = DcbOpticonJobBEO.TargetDatasetId;
                evDocument.MatterId = DcbOpticonJobBEO.MatterId;

                //Add the fields required for casemap
                RVWDocumentFieldBEO evDocumentAccessionNumField = new RVWDocumentFieldBEO
                                                   {
                                                       FieldId = Convert.ToInt32(DcbOpticonJobBEO.SysDocId),
                                                       FieldName = EVSystemFields.DcbId,
                                                       IsSystemField = true,
                                                       IsRequired = true,
                                                       FieldValue = Convert.ToString(currentDcbDocument.UUID, CultureInfo.InvariantCulture)
                                                   };
                evDocument.FieldList.Add(evDocumentAccessionNumField);
                evDocument.FieldList.Add(_evDocumentSysImportTypeField);

                //Set the fields from field mapping except content field
                foreach (FieldMapBEO fieldMap in DcbOpticonJobBEO.FieldMappings)
                {
                    Field dcbField = currentDcbDocument.FieldItems.Find(o => (o.Code == fieldMap.SourceFieldID));

                    //Profile fieldmapping has duplicates
                    RVWDocumentFieldBEO evDocumentFieldBEO = evDocument.FieldList.Find(o => o.FieldId.Equals(fieldMap.DatasetFieldID));
                    if ((null != dcbField) && (evDocumentFieldBEO == null) && (fieldMap.DatasetFieldID != _contentFieldId))
                    {
                        RVWDocumentFieldBEO evDocuemtnField = new RVWDocumentFieldBEO
                                                                  {
                                                                      FieldId = fieldMap.DatasetFieldID,
                                                                      FieldName = fieldMap.DatasetFieldName
                                                                  };


                        FieldBEO evfieldDef = _dataset.DatasetFieldList.Find(o => o.ID == evDocuemtnField.FieldId);
                        evDocuemtnField.FieldValue = evfieldDef.FieldType.DataTypeId == Constants.DateDataType
                                                         ? GetDateFiedlValue(dcbField, dcbParserLogEntry)
                                                         : Regex.Replace(dcbField.Value, "\r\n", "\n");
                        evDocument.FieldList.Add(evDocuemtnField);
                    }
                }

                //Separate logic for content
                StringBuilder sbContent = new StringBuilder();
                if (DcbOpticonJobBEO.ContentFields != null)
                {
                    foreach (string contentfield in DcbOpticonJobBEO.ContentFields.Field)
                    {
                        Field dcbContentField = currentDcbDocument.FieldItems.Find(o => (o.Name.Equals(contentfield)));
                        if (null != dcbContentField)
                        {
                            sbContent.Append(dcbContentField.Value);
                        }
                    }
                }
                string text = sbContent.ToString().Replace("\r\n", "\n");
                //evDocument.DocumentBinary.Content = Regex.Replace(sbContent.ToString(), "\r\n", "\n");

                if (!DumpTextToFile(evDocument, text, dcbParserLogEntry))
                {
                    return;
                }

                //Set the native file path if selected
                evDocument.NativeFilePath = GetNativeFilePath(currentDcbDocument);

                if (!String.IsNullOrEmpty(evDocument.NativeFilePath) && File.Exists(evDocument.NativeFilePath))
                {
                    FileInfo fileInfo = new FileInfo(evDocument.NativeFilePath);
                    //Tracer.Trace("DcbParcer located native document {0} for DocumentId = {1} and the file length is {2}",
                    //    evDocument.NativeFilePath, evDocument.DocumentId, fileInfo.Length);
                    if (fileInfo.Length > 0)
                    {
                        evDocument.FileSize = (int)Math.Ceiling(fileInfo.Length / 1024.0);
                    }
                    else
                    {
                        evDocument.FileSize = 0;
                    }

                    evDocument.MD5HashValue = DocumentHashHelper.GetMD5HashValue(evDocument.NativeFilePath);
                    evDocument.SHAHashValue = DocumentHashHelper.GetSHAHashValue(evDocument.NativeFilePath);
                }

                //Set the MIME type
                string extn = string.Empty;
                string newExtn = string.Empty;
                extn = Path.GetExtension(evDocument.NativeFilePath);
                if (!String.IsNullOrEmpty(extn))
                    newExtn = extn.Remove(0, 1);
                evDocument.MimeType = GetMimeType(newExtn);
                evDocument.FileExtension = extn;

                string createdByGuid = String.Empty;
                if (null != ProfileBEO && null != ProfileBEO.CreatedBy)
                {
                    createdByGuid = ProfileBEO.CreatedBy;
                }
                evDocument.CreatedBy = createdByGuid;
                evDocument.ModifiedBy = createdByGuid;

                if (File.Exists(evDocument.NativeFilePath))
                {
                    //Calculating size of file in KB
                    FileInfo fileInfo = new FileInfo(evDocument.NativeFilePath);
                    evDocument.FileSize = (int)Math.Ceiling(fileInfo.Length / Constants.KBConversionConstant);

                    if (evDocument.DocumentBinary == null) { evDocument.DocumentBinary = new RVWDocumentBinaryBEO(); }
                    RVWExternalFileBEO nativeFile = new RVWExternalFileBEO
                    {
                        Type = NATIVE_FILE_TYPE,
                        Path = evDocument.NativeFilePath
                    };
                    evDocument.DocumentBinary.FileList.Add(nativeFile);
                }

                DocumentDetail documentDetail = new DocumentDetail
                                                    {
                                                        // CorrId is the same as TaskId and it is 1 based.
                                                        CorrelationId = checked(documentNumber + 1).ToString(CultureInfo.InvariantCulture),
                                                        IsNewDocument = true,
                                                        docType = DocumentsetType.NativeSet,
                                                        document = evDocument
                                                    };
                documentDetailList.Add(documentDetail);

                //Add Tags
                if (DcbOpticonJobBEO.IncludeTags && null != currentDcbDocument.TagItems && currentDcbDocument.TagItems.Count > 0)
                {
                    if (null == documentDetail.DcbTags)
                    {
                        documentDetail.DcbTags = new List<DcbTags>();
                    }
                    DcbDocumentTags dcbDocumentTags = new DcbDocumentTags
                                                          {
                        compositeTagNames = currentDcbDocument.TagItems,
                        DatasetId = DcbOpticonJobBEO.TargetDatasetId,
                        MatterId = DcbOpticonJobBEO.MatterId,
                        DocumentId = evDocument.DocumentId
                    };
                    documentDetail.DcbTags.Add(dcbDocumentTags);
                }

                // Add notes
                AddComments(documentDetail, evDocument, currentDcbDocument);

                //Add Images
                if (DcbOpticonJobBEO.ImportImages)
                {
                    RVWDocumentBEO images = ImportDocumentImages(evDocument.DocumentId, currentDcbDocument);
                    if (null != images)
                    {
                        DocumentDetail imageDocumentDetail = new DocumentDetail
                                                                 {
                                                                     // CorrId is the same as TaskId and it is 1 based.
                                                                     CorrelationId = checked(documentNumber + 1).ToString(CultureInfo.InvariantCulture),
                                                                     IsNewDocument = true,
                                                                     docType = DocumentsetType.ImageSet,
                                                                     document = images
                                                                 };
                        documentDetailList.Add(imageDocumentDetail);
                        dcbParserLogEntry.LogInfo.AddedImages = images.DocumentBinary.FileList.Count;
                    }

                    //Add Redlines
                    //ImportDocumentRedlines();
                }

                //Add Document Relation
                if (DcbOpticonJobBEO.IsImportFamilies)
                {
                    ImportDocumentRelationship(evDocument.DocumentId, currentDcbDocument, familiesInfo);
                }
                #region Postcondition asserts
                documentDetailList.ShouldNotBe(null);
                #endregion
            }
            catch (Exception ex)
            {
                //TaskLogInfo.AddParameters(Constants.ErrorDoAtomicWork + "<br/>" + ex.Message);
                //TaskLogInfo.StackTrace = ex.Source + "<br/>" + ex.Message + "<br/>" + ex.StackTrace;
                //TaskLogInfo.IsError = true;

                ex.Trace().Swallow();
                dcbParserLogEntry.Success = false;
                if (ex.ToUserString().Contains(Constants.DiskFullErrorMessage))
                {
                    dcbParserLogEntry.LogInfo.Message = "There is not enough space on the disk";
                    throw;
                }
                else
                {
                    dcbParserLogEntry.LogInfo.Message = ex.ToUserString();
                }
            }
        }
 /// <summary>
 /// Creates the and update external file entity for native set.
 /// </summary>
 /// <param name="document">The document.</param>
 private static void CreateAndUpdateExternalFileEntityForNativeSet(RVWDocumentBEO document)
 {
     try
     {
         //Insert document binary, if any -- to do: Should we need call this @ this place
         if (document != null && !StringUtility.IsNullOrWhiteSpace(document.NativeFilePath))
         {
             RVWExternalFileBEO externalFile = new RVWExternalFileBEO();
             externalFile.Type = "Native";
             externalFile.Path = document.NativeFilePath;
             document.DocumentBinary.FileList.Add(externalFile);
         }
         else
         {
             throw new EVException().AddErrorCode(ErrorCodes.EDLoaderExtractionWorker_NativeFileNotAvailable);
         }
     }
     catch (Exception ex)
     {
         ex.Trace().Swallow();
     }
 }
        /// <summary>
        /// Construct Nativeset & ImageSet
        /// </summary>        
        private List<DocumentDetail> ConstructNativeImageSet(bool isNewRecord, bool isNewImageSet, DocumentDetail docDetail, List<string> misMatchedFields, List<string> misMatchedFieldsMessage)
        {
            List<DocumentDetail> documentDetailList = new List<DocumentDetail>();
            //1) Construct Native Set
            var nativeSetDocument = GetDocumentForNativeSet(docDetail.document, misMatchedFields, misMatchedFieldsMessage);
            var doc = new DocumentDetail();
            doc.CorrelationId = docDetail.CorrelationId;
            doc.docType = DocumentsetType.NativeSet;
            doc.document = nativeSetDocument;
            doc.ParentDocId = docDetail.ParentDocId;
            doc.IsNewDocument = isNewRecord;
            doc.ConversationIndex = docDetail.ConversationIndex;
            doc.OverlayReImportField = docDetail.OverlayReImportField;
            doc.Reviewsets = docDetail.Reviewsets;
            #region Check Same Content File
            string existingContentFilePath = GetExistingContentFile(nativeSetDocument.CollectionId, nativeSetDocument.DocumentId);
            string contentFilePath = string.Empty;
            if (nativeSetDocument.DocumentBinary.FileList != null && nativeSetDocument.DocumentBinary.FileList.Where(f => f.Type == Constants.TEXT_FILE_TYPE).FirstOrDefault() != null)
            {
                contentFilePath = (!string.IsNullOrEmpty(nativeSetDocument.DocumentBinary.FileList.Where(f => f.Type == Constants.TEXT_FILE_TYPE).FirstOrDefault().Path) ? nativeSetDocument.DocumentBinary.FileList.Where(f => f.Type == Constants.TEXT_FILE_TYPE).FirstOrDefault().Path : string.Empty);
            }
            if (!string.IsNullOrEmpty(existingContentFilePath)) //If text File is exist during Append 
            {

                if (!string.IsNullOrEmpty(contentFilePath))
                {
                    if (existingContentFilePath.Trim().ToLower() != contentFilePath.Trim().ToLower()) //New Content File Used in Overlay
                    {
                        doc.OverlayIsNewContentFile = true;
                    }
                }
                else  //If there is no text File during overlay , Need to maintain old content File
                {
                    doc.OverlayIsNewContentFile = false;
                    RVWExternalFileBEO file = new RVWExternalFileBEO
                                {
                                    Type = Constants.TEXT_FILE_TYPE,
                                    Path = existingContentFilePath
                                };
                    doc.document.DocumentBinary.FileList.Add(file);
                }
            }
            else if (string.IsNullOrEmpty(nativeSetDocument.CustomFieldToPopulateText) && !string.IsNullOrEmpty(contentFilePath)) //If there is no text File during Append 
            {
                doc.OverlayIsNewContentFile = true;
            }
            else if (!string.IsNullOrEmpty(contentFilePath))
            {
                doc.OverlayIsNewContentFile = false;
            }
            #endregion

            doc.SystemTags = m_JobParameter.SystemTags;
            doc.document.DocumentControlNumber = docDetail.document.DocumentControlNumber;

            documentDetailList.Add(doc);

            //2) Construct Image Set                       
            if (m_JobParameter.IsImportImages && !string.IsNullOrEmpty(m_JobParameter.ImageSetId))
            {
                var imageSetDocument = GetDocumentForImageSet(docDetail.document, m_JobParameter.ImageSetId);
                var docImg = new DocumentDetail();
                docImg.CorrelationId = docDetail.CorrelationId;
                docImg.docType = DocumentsetType.ImageSet;
                docImg.document = imageSetDocument;
                docImg.IsNewDocument = isNewImageSet;
                documentDetailList.Add(docImg);
            }
            return documentDetailList;
        }
        public RVWDocumentBEO ConsturctDocument(string correlationId, string[] fields,
            List<string> textFileList,
            ref List<RVWDocumentFieldBEO> matchingKeyField,
            out string missingNativeFile, List<string> missingImageFiles,
            out bool isMissingContent, List<string> missingContentFiles,
            List<string> misMatchedFields, List<string> misMatchedFieldsMessage, out int importedImagesCount)
        {
            var document = new RVWDocumentBEO();
            missingNativeFile = null;
            isMissingContent = false;
            document.CollectionId = m_JobParameter.CollectionId;
            document.MatterId = m_JobParameter.MatterId;
            document.CreatedBy = m_JobParameter.CreatedBy;
            document.ImportDescription = m_ImportDescription;
            importedImagesCount = 0;

            document.DocumentId = GetDocumentId();
            SetLoadFileRelationShipInformation(fields, m_FieldRowDelimiter, document);

            if (m_JobParameter.FamilyRelations != null && m_JobParameter.IsMapEmailThread)
            {
                document.ConversationIndex = GetConversionIndex(fields, m_FieldRowDelimiter);
            }

            if (m_JobParameter.LoadFile != null && m_JobParameter.LoadFile.CrossReferenceField > -1)
            {
                document.CrossReferenceFieldValue = GetCrossReferecneField(fields, m_FieldRowDelimiter);
            }
            if (m_JobParameter.LoadFile != null && m_JobParameter.LoadFile.ContentFile != null)
            {
                if (!m_Dataset.DatasetFieldList.Any(f => f.FieldType.DataTypeId == 2000 && f.Name == m_JobParameter.LoadFile.ContentFile.FieldNameToPopulateText))
                {
                    document.CustomFieldToPopulateText = m_JobParameter.LoadFile.ContentFile.FieldNameToPopulateText;
                }
            }
            #region Native File
            string nativeFilePath = string.Empty;
            if ((m_JobParameter.IsImportNativeFiles) && (m_JobParameter.LoadFile.NativeFile.LoadfileNativeField != string.Empty))
            {
                if (fields.Count() > Convert.ToInt32(m_JobParameter.LoadFile.NativeFile.LoadfileNativeField))
                    nativeFilePath = fields[Convert.ToInt32(m_JobParameter.LoadFile.NativeFile.LoadfileNativeField)];
                if (CheckValidFilePathFormat(nativeFilePath))
                {

                    if (m_JobParameter.LoadFile.NativeFile.NativePathSubstitution != null)
                    {
                        FilePathSubstitutionBEO nativePathSubstitution = m_JobParameter.LoadFile.NativeFile.NativePathSubstitution;

                        if (nativePathSubstitution.StringToMatch != string.Empty && nativePathSubstitution.StringToReplace != string.Empty)
                        {
                            nativeFilePath = PathSubstituion(nativeFilePath, nativePathSubstitution);
                        }
                        else
                        {
                            //Construct Absolute Path for Relative Path
                            nativeFilePath = ConstructAbsolutePath(nativeFilePath, m_SourceFile.OriginalString);
                        }
                    }
                    else
                    {
                        //Construct Absolute Path for Relative Path
                        nativeFilePath = ConstructAbsolutePath(nativeFilePath, m_SourceFile.OriginalString);
                    }
                    document.MimeType = GetMimeType(Path.GetExtension(nativeFilePath).Replace(".", "")); // Remove MimeType
                    document.FileName = Path.GetFileNameWithoutExtension(nativeFilePath);
                    document.NativeFilePath = nativeFilePath;

                    #region Update native file information in document binary object as well...
                    if (document.DocumentBinary == null) { document.DocumentBinary = new RVWDocumentBinaryBEO(); }
                    RVWExternalFileBEO externalFile = new RVWExternalFileBEO();
                    externalFile.Type = Constants.NATIVE_FILE_TYPE;
                    externalFile.Path = document.NativeFilePath;
                    document.DocumentBinary.FileList.Add(externalFile);
                    #endregion Update native file information in document binary object as well...

                    document.FileExtension = Path.GetExtension(nativeFilePath);
                    if (File.Exists(nativeFilePath))
                    {
                        //Calculating size of file in KB
                        FileInfo fileInfo = new FileInfo(nativeFilePath);
                        document.FileSize = (int)Math.Ceiling(fileInfo.Length / Constants.KBConversionConstant);

                        document.MD5HashValue = DocumentHashHelper.GetMD5HashValue(nativeFilePath);
                        document.SHAHashValue = DocumentHashHelper.GetSHAHashValue(nativeFilePath);
                    }
                    else //Missing Native File
                    {
                        missingNativeFile = nativeFilePath;
                    }
                }
                else //Missing Native File
                {
                    missingNativeFile = nativeFilePath;
                }
            }
            #endregion

            #region Image File
            if (m_JobParameter.IsImportImages)
            {
                if (m_JobParameter.LoadFile.ImageFile != null)
                {
                    
                    #region "Image File Type"
                    string fileType = (!string.IsNullOrEmpty(m_JobParameter.LoadFile.ImageFile.ImageType.ToString())) ?
                        m_JobParameter.LoadFile.ImageFile.ImageType.ToString() : string.Empty;
                    #endregion
                
                    var lsImageFilePath = GetImageFilePaths(fields, _JobId);
                   
                    if (document.DocumentBinary == null) { document.DocumentBinary = new RVWDocumentBinaryBEO(); }
                    if (lsImageFilePath.Any())
                    {
                        //Int64 ImportedImagesCount = 0;
                        bool isAllFiles = false;
                        isAllFiles = (fileType.ToLower().Equals(Constants.ALL_FILE_TYPE.ToLower())) ? true : false;
                        foreach (string path in lsImageFilePath)
                        {
                            RVWExternalFileBEO textFile = null;
                            if (CheckValidFilePathFormat(path))
                            {
                                if ((isAllFiles) || (fileType.ToLower().Contains(Path.GetExtension(path).Replace(Constants.STR_DOT, string.Empty).ToLower())))  // Allows the user to select the type of images to import
                                {
                                    textFile = new RVWExternalFileBEO
                                    {
                                        Type = Constants.IMAGE_FILE_TYPE,
                                        Path = path
                                    };
                                    document.DocumentBinary.FileList.Add(textFile);
                                    #region Missing Images
                                    if (!File.Exists(path)) //Missing Image File
                                    {
                                        missingImageFiles.Add(path);
                                    }
                                    #endregion
                                }
                            }
                            else //Missing Image File
                            {
                                missingImageFiles.Add(path);
                            }
                        }
                        importedImagesCount = lsImageFilePath.Count - missingImageFiles.Count;
                    }
                    
                }
            }
            #endregion

            #region Text File (Content File)
            if (m_JobParameter.LoadFile.ContentFile != null)
            {
                string txtFilePath = string.Empty;
                string contentFilePath = string.Empty;
                if (m_JobParameter.LoadFile.ContentFile.TextExtractionOption != LoadFileTextExtractionOption.NoTextImport)
                {
                    if (m_JobParameter.LoadFile.ContentFile.TextExtractionOption == LoadFileTextExtractionOption.LoadFileField)
                    {
                        if (fields.Count() > Convert.ToInt32(m_JobParameter.LoadFile.ContentFile.LoadFileContentField))
                            txtFilePath = (fields[Convert.ToInt32(m_JobParameter.LoadFile.ContentFile.LoadFileContentField)] != string.Empty) ? fields[Convert.ToInt32(m_JobParameter.LoadFile.ContentFile.LoadFileContentField)] : string.Empty;
                        if (!string.IsNullOrEmpty(txtFilePath) && txtFilePath.IndexOfAny(Path.GetInvalidPathChars()) == -1) //Check Valid file path
                        {
                            if (CheckValidFilePathFormat(txtFilePath)) //Check its a file or not 
                            {
                                if (!string.IsNullOrEmpty(m_JobParameter.LoadFile.ContentFile.FolderLocation))
                                {
                                    txtFilePath = m_JobParameter.LoadFile.ContentFile.FolderLocation + Constants.BackSlash + txtFilePath;
                                }

                                if (m_JobParameter.LoadFile.ContentFile.TextFilePathSubstitution != null)
                                {
                                    FilePathSubstitutionBEO txtFilePathSubstitution = m_JobParameter.LoadFile.ContentFile.TextFilePathSubstitution;
                                    contentFilePath = PathSubstituion(txtFilePath, txtFilePathSubstitution);
                                }
                                else
                                {
                                    //Construct Absolute Path for Relative Path
                                    contentFilePath = ConstructAbsolutePath(txtFilePath, m_SourceFile.OriginalString);
                                }
                            }
                            else
                            {
                                if (missingContentFiles != null)
                                {
                                    missingContentFiles.Add(txtFilePath);
                                }
                                isMissingContent = true;
                            }
                        }
                        else
                        {
                            if (missingContentFiles != null)
                            {
                                missingContentFiles.Add(txtFilePath);
                            }
                            isMissingContent = true;
                        }
                    }
                    else if (m_JobParameter.LoadFile.ContentFile.TextExtractionOption == LoadFileTextExtractionOption.HelperFile)
                    {
                        if (textFileList != null && textFileList.Count > 0)
                        {
                            if (textFileList.Count == 1)
                                contentFilePath = textFileList.First();
                            else
                            {
                                //Create single text file after fetch content from multiple text file       
                                StringBuilder sbFilePath = new StringBuilder();
                                if (m_DatasetPath.EndsWith(Constants.BackSlash))
                                {
                                    sbFilePath.Append(m_DatasetPath);
                                }
                                else
                                {
                                    sbFilePath.Append(m_DatasetPath);
                                    sbFilePath.Append(Constants.BackSlash);
                                }
                                sbFilePath.Append(Guid.NewGuid().ToString().Replace("-", "").ToUpper());
                                sbFilePath.Append(DateTime.UtcNow.ToString(Constants.DateFormat));
                                sbFilePath.Append(Constants.TextFileExtension);
                                string filePath = sbFilePath.ToString();
                                CreateSingleContentFile(textFileList, filePath, missingContentFiles);
                                contentFilePath = filePath;
                                if (missingContentFiles != null && missingContentFiles.Count > 0)  //Capture log for missing content file.
                                {
                                    isMissingContent = true;
                                }
                            }
                        }
                    }
                    else if (m_JobParameter.LoadFile.ContentFile.TextExtractionOption == LoadFileTextExtractionOption.BodyTextField)
                    {
                        if (null != textFileList && textFileList.Any())
                        {
                            contentFilePath = textFileList[0];
                        }
                    }
                    else if (m_JobParameter.LoadFile.ContentFile.TextExtractionOption == LoadFileTextExtractionOption.TextFromFolderLocation)
                    {
                        string filename = string.Empty;
                        string fieldValueToSearchFile = string.Empty;
                        if (m_JobParameter.LoadFile != null && m_JobParameter.LoadFile.ContentFile.MatchingFieldIdForFileName > -1)
                        {
                            fieldValueToSearchFile = GetFieldValues(fields, m_FieldRowDelimiter, m_JobParameter.LoadFile.ContentFile.MatchingFieldIdForFileName);
                        }
                        if (!string.IsNullOrEmpty(m_JobParameter.LoadFile.ContentFile.FolderLocation) && !string.IsNullOrEmpty(fieldValueToSearchFile))
                        {
                            filename = string.Format("{0}.txt", fieldValueToSearchFile);
                            var files = Directory.GetFiles(m_JobParameter.LoadFile.ContentFile.FolderLocation, filename, SearchOption.AllDirectories);
                            if (files.Any())
                            {
                                contentFilePath = files.LastOrDefault();
                            }
                            else
                            {
                                if (missingContentFiles != null && !string.IsNullOrEmpty(filename))
                                {
                                    missingContentFiles.Add(filename);
                                }
                                isMissingContent = true;
                            }
                        }
                        else
                        {
                            isMissingContent = true;
                        }
                    }
                    // Checks in below statement 1) null check on "file path" and 2) are there any external files
                    if (document.DocumentBinary == null) { document.DocumentBinary = new RVWDocumentBinaryBEO(); }
                    if (!string.IsNullOrEmpty(contentFilePath))
                    {
                        if (CheckValidFilePathFormat(contentFilePath) && File.Exists(contentFilePath))
                        {
                            RVWExternalFileBEO textFile = new RVWExternalFileBEO
                            {
                                Type = Constants.TEXT_FILE_TYPE,
                                Path = contentFilePath
                            };
                            document.DocumentBinary.FileList.Add(textFile);
                        }
                        else
                        {
                            missingContentFiles.Add(contentFilePath);
                            isMissingContent = true;
                        }
                    }
                }
            }
            #endregion

            #region Field Mapping
            if (m_JobParameter.FieldMapping != null)
            {
                List<FieldMapBEO> mappedFields = m_JobParameter.FieldMapping;
                foreach (FieldMapBEO mappedField in mappedFields)
                {
                    string fieldValue = string.Empty;
                    FieldBEO field = m_Dataset.DatasetFieldList.FirstOrDefault(f => f.ID.Equals(mappedField.DatasetFieldID));
                    if (null == field)
                    {
                        continue;
                    }
                    var dataTypeId = (field.FieldType != null) ? field.FieldType.DataTypeId : 0;

                    if (fields.Count() > mappedField.SourceFieldID && fields.Length > mappedField.SourceFieldID)
                        fieldValue = (fields[mappedField.SourceFieldID] != string.Empty) ? fields[mappedField.SourceFieldID].Replace(m_FieldRowDelimiter.ToString(), m_ConcordanceFieldSplitter) : string.Empty;

                    // To maintain Equiset value as unique within a collection. Will append unique identifier with Equiset Value
                    // E.g : Equiset value in .DAT file :126
                    //       Imported in EV : UniqueIdentifier_126
                    if (!string.IsNullOrEmpty(mappedField.DatasetFieldName) && mappedField.DatasetFieldName.ToLower() == EVSystemFields.ND_FamilyID.ToLower() && !string.IsNullOrEmpty(fieldValue))
                    {
                        fieldValue = string.Format("{0}_{1}", m_ThreadingConstraint, fieldValue);
                    }

                    if (dataTypeId == Constants.DateFieldTypeId)
                    {
                        DateTime dateFieldValue;
                        DateTime.TryParse(fieldValue, out dateFieldValue);
                        if (dateFieldValue == DateTime.MinValue || dateFieldValue == DateTime.MaxValue)
                        {
                            misMatchedFields.Add(string.Format(Constants.MisMatchedToWrongData, field.Name));
                            misMatchedFieldsMessage.Add(string.Format(Constants.MsgMismatchedFile, field.Name));
                        }
                    }

                    // Create a Field Business Entity for each mapped field
                    RVWDocumentFieldBEO fieldBeo = new RVWDocumentFieldBEO()
                    {
                        // set required properties / field data
                        FieldId = mappedField.DatasetFieldID,
                        FieldName = mappedField.DatasetFieldName,
                        FieldValue = fieldValue,
                        FieldType = new FieldDataTypeBusinessEntity() { DataTypeId = dataTypeId }
                    };

                    // Add Field to the document
                    document.FieldList.Add(fieldBeo);

                } // End of loop through fields in a document.   

            }
            #endregion

            #region Overlay Matching Condition
            // Assign Field value.
            if (!m_JobParameter.IsAppend && m_JobParameter.OverlayKeys != null)
            {
                List<FieldMapBEO> overlayMatchingKeyFields = m_JobParameter.OverlayKeys;
                matchingKeyField = new List<RVWDocumentFieldBEO>();
                foreach (FieldMapBEO mappedField in overlayMatchingKeyFields)
                {
                    string fieldValue = string.Empty;
                    if (fields.Count() > mappedField.SourceFieldID)
                        fieldValue = (fields[mappedField.SourceFieldID] != string.Empty) ? fields[mappedField.SourceFieldID] : string.Empty;
                    // Create a Field Business Entity for each mapped field
                    RVWDocumentFieldBEO fieldBEO = new RVWDocumentFieldBEO()
                    {
                        // set required properties / field data
                        FieldId = mappedField.DatasetFieldID,
                        FieldName = mappedField.DatasetFieldName,
                        FieldValue = fieldValue

                    };
                    // Add Field to the document
                    matchingKeyField.Add(fieldBEO);

                }
            }

            #endregion
            return document;
        }
Пример #14
0
        /// <summary>
        /// Transform "EDRM document entity" to EV's Document BEO
        /// This function doesn't set field data
        /// Field data is set separately as there are two variances of this operation. </summary>
        /// 1) set all fields available in the EDRM file<param name="rvwDocumentBEO"></param>
        /// 2) set mapped fields only.
        /// </summary>
        /// <param name="rvwDocumentBEO"> Document Business Entity, by reference so that the transformed data is updated in this object. </param>
        /// <param name="edrmDocument"> EDRM document entity which is going tobe transformed to EV Document Business Entity. </param>
        protected virtual void TransformEDRMDocumentEntityToDocumentBusinessEntity(ref RVWDocumentBEO rvwDocumentBEO, DocumentEntity edrmDocument)
        {
            // Initialize if the object is not created
            if (rvwDocumentBEO == null)
            {
                rvwDocumentBEO = new RVWDocumentBEO();
            }

            // Document ID is MD5 hash of EDRM file + EDRM Document ID.
            // This makes document unique in the system and identifies if same EDRM file attempted to be imported twice.
            // Special character to
            rvwDocumentBEO.DocumentId = GetDocumentId(edrmDocument);

            // Set MIME type
            rvwDocumentBEO.MimeType = edrmDocument.MIMEType;

            #region Add associate file details/names from EDRM file

            // NOTES:
            // Binary and text is set later by the consuming module. This is to reduce weight of objects
            // Binary and text could increase memory by great extent.

            foreach (FileEntity fileEntity in edrmDocument.Files)
            {
                // Check if type is native
                if (fileEntity.FileType.ToLower().Equals(Constants.EDRMAttributeNativeFileType.ToLower()))
                {
                    // Set file path for native file types.
                    // Condition - check if native file entity has external file entities in it or not.
                    if (fileEntity.ExternalFile != null)
                    {
                        // Checks in below statement 1) null check on "file path" and 2) are there any external files
                        rvwDocumentBEO.FileName       = (fileEntity.ExternalFile.Count > 0) ? fileEntity.ExternalFile[0].FileName : string.Empty;
                        rvwDocumentBEO.NativeFilePath = (fileEntity.ExternalFile.Count > 0) ? CreateFileURI(fileEntity.ExternalFile[0].FilePath, fileEntity.ExternalFile[0].FileName) : string.Empty;
                        rvwDocumentBEO.FileExtension  = (fileEntity.ExternalFile.Count > 0) ? fileEntity.ExternalFile[0].FileName.Substring(fileEntity.ExternalFile[0].FileName.LastIndexOf(".")) : string.Empty;

                        if (!string.IsNullOrEmpty(rvwDocumentBEO.NativeFilePath) && File.Exists(rvwDocumentBEO.NativeFilePath))
                        {
                            //Calculating size of file in KB
                            FileInfo fileInfo = new FileInfo(rvwDocumentBEO.NativeFilePath);
                            rvwDocumentBEO.FileSize = (int)Math.Ceiling(fileInfo.Length / Constants.KBConversionConstant);
                        }
                    }
                }

                // Check if the type is Text.
                if (fileEntity.FileType.ToLower().Equals(Constants.EDRMAttributeTextFileType.ToLower()))
                {
                    if (fileEntity.ExternalFile != null)
                    {
                        // For text set file details in TextContent property. Set the real text just before import.
                        // This is to help reduce weight of the object.

                        // Checks in below statement 1) null check on "file path" and 2) are there any external files
                        if (rvwDocumentBEO.DocumentBinary == null)
                        {
                            rvwDocumentBEO.DocumentBinary = new RVWDocumentBinaryBEO();
                        }

                        RVWExternalFileBEO textFile = new RVWExternalFileBEO
                        {
                            Type = Constants.EDRMAttributeTextFileType,
                            Path = (fileEntity.ExternalFile.Count > 0) ? CreateFileURI(fileEntity.ExternalFile[0].FilePath, fileEntity.ExternalFile[0].FileName) : string.Empty
                        };

                        rvwDocumentBEO.DocumentBinary.FileList.Add(textFile);
                    }
                }
            }

            #endregion
        }