示例#1
0
        public Document ChangeDocumentType(
            Document aDocument, DocumentType aNewDocumentType,
            IEnumerable <Keyword> aKeywords = null,
            bool aExpandKeyset = true, bool aUseDefaultForRequiredKeys = true)
        {
            if (aNewDocumentType == null || aNewDocumentType.Equals(aDocument.DocumentType))
            {
                return(UpdateDocumentKeywords(aDocument, aKeywords, aExpandKeyset, aUseDefaultForRequiredKeys));
            }

            using (DocumentLock lDocumentLock = aDocument.LockDocument())
            {
                if (lDocumentLock.Status == DocumentLockStatus.AlreadyLocked)
                {
                    throw new DocumentLockedException(aDocument, lDocumentLock);
                }

                ReindexProperties lReindexProperties = Application.Core.Storage.CreateReindexProperties(aDocument, aNewDocumentType);
                EditKeywords(lReindexProperties, aDocument, aNewDocumentType, aKeywords, aExpandKeyset, aUseDefaultForRequiredKeys);
                return(Application.Core.Storage.ReindexDocument(lReindexProperties));
            }
        }
示例#2
0
        private bool RunCQ(Application app, WorkflowEventArgs args, string strBusinessUnit, string strAGMeetingMonth, string strAGMeetingYear, string strAGAddendum, string strDocType, string strLicenseType, string strApplicationNumber, long lngDocHandle, string strCameraReady, string lngMstrDocHandle, bool bOkayToProcessWithoutError)

        {
            const long CIU_APPLICATION_MSTR_DTID              = 773;
            const long CIU_CRIMINAL_RESULTS_MSTR_DTID         = 771;
            const long CIU_SUPPORTING_DOCS_MSTR_DTID          = 770;
            const long CIU_CORRESPONDENCE_MSTR_DTID           = 772;
            const long CIU_CR_CAMERA_READY_DOCUMENT_MSTR_DTID = 2343;

            //String to hold output information
            string output = string.Empty;

            WriteLog(app, string.Format("[{0}][{1}][{2}][{3}][{4}][{5}][{6}][{7}]", strBusinessUnit, strAGMeetingYear, strAGMeetingMonth, strAGAddendum, strDocType, strLicenseType, strApplicationNumber, lngDocHandle.ToString(), strCameraReady));

            long gDocTypeID;
            long lngCurrentMSTRDTID;

            switch (strDocType)
            {
            case "CAMERA READY DOCUMENT":
            {
                gDocTypeID         = PCIU_CR_CAMERA_READY_DOCUMENT_DTID;
                lngCurrentMSTRDTID = CIU_CR_CAMERA_READY_DOCUMENT_MSTR_DTID;
                break;
            }

            case "APPLICATION":
            {
                gDocTypeID         = PCIU_APPLICATIONS_CR_DTID;
                lngCurrentMSTRDTID = CIU_APPLICATION_MSTR_DTID;
                break;
            }

            case "CRIMINAL RESULTS":
            {
                gDocTypeID         = PCIU_CRIMINAL_RESULTS_CR_DTID;
                lngCurrentMSTRDTID = CIU_CRIMINAL_RESULTS_MSTR_DTID;
                break;
            }

            case "SUPPORTING DOCS":
            {
                gDocTypeID         = PCIU_SUPPORTING_DOCS_CR_DTID;
                lngCurrentMSTRDTID = CIU_SUPPORTING_DOCS_MSTR_DTID;
                break;
            }

            case "CORRESPONDENCE":
            {
                gDocTypeID         = PCIU_CORRESPONDENCE_CR_DTID;
                lngCurrentMSTRDTID = CIU_CORRESPONDENCE_MSTR_DTID;
                break;
            }

            default:
            {
                gDocTypeID         = 0;
                lngCurrentMSTRDTID = 0;
                break;
            }
            }


            // Create document query
            WriteLog(app, string.Format("Setting up Document Query [{0} - {1}]", strDocType, gDocTypeID.ToString()));
            DocumentQuery documentQuery = app.Core.CreateDocumentQuery();

            // Ensure custom query was found
            if (documentQuery == null)
            {
                throw new Exception("Unable to create document query");
            }

            // Add custom query to document query
            DocumentType docType = app.Core.DocumentTypes.Find(gDocTypeID);

            if (docType == null)
            {
                throw new Exception(string.Format("Could not find document type with ID: {0}", gDocTypeID.ToString()));
            }
            documentQuery.AddDocumentType(docType);

            KeywordType kwdType = app.Core.KeywordTypes.Find(PAPPNUMBERKWID);

            if (kwdType == null)
            {
                throw new Exception(string.Format("Could not find keyword type with ID: {0}", PAPPNUMBERKWID.ToString()));
            }
            documentQuery.AddKeyword(kwdType.Name, Convert.ToInt64(strApplicationNumber));

            kwdType = app.Core.KeywordTypes.Find(PLICTYPEKWID);
            if (kwdType == null)
            {
                throw new Exception(string.Format("Could not find keyword type with ID: {0}", PLICTYPEKWID.ToString()));
            }
            documentQuery.AddKeyword(kwdType.Name, strLicenseType);

            kwdType = app.Core.KeywordTypes.Find(PDOCNUMBERCONSTKWID);
            if (kwdType == null)
            {
                throw new Exception(string.Format("Could not find keyword type with ID: {0}", PDOCNUMBERCONSTKWID.ToString()));
            }
            documentQuery.AddKeyword(kwdType.Name, Convert.ToInt64(lngMstrDocHandle));

            documentQuery.AddSort(DocumentQuery.SortAttribute.DocumentID, true);

            WriteLog(app, string.Format("Running Document Query - Search KW [{0} = {1}]", PAPPNUMBERKWID.ToString(), strApplicationNumber));
            WriteLog(app, string.Format("Running Document Query - Search KW [{0} = {1}]", KNLICTYPE, strLicenseType));
            WriteLog(app, string.Format("Running Document Query - Search KW [{0} = {1}]", KNDOCNUMBERCONSTKWID, lngMstrDocHandle.ToString()));

            // Execute query
            const int    MAX_DOCUMENTS = 1000;
            DocumentList documentList  = documentQuery.Execute(MAX_DOCUMENTS);

            if (documentList.Count == 0)
            {
                if (!bOkayToProcessWithoutError)
                {
                    WriteLog(app, "  ");
                    WriteLog(app, "*************** ERROR: NO DOCUMENTS FOUND IN SEARCH **************");
                    WriteLog(app, "  ");
                    strProcessingErrors = string.Format("{0}{1}  Failed to locate any documents of type - {2}.  AN: {3} - LT: {4}", strProcessingErrors, DateTime.Now, strDocType, strApplicationNumber, strLicenseType);

                    return(false);
                }
                else
                {
                    WriteLog(app, "  ");
                    WriteLog(app, "*************** ERROR BYPASSED: USER STATED TO PROCESS WITH MISSING DOCUMENTS **************");
                    WriteLog(app, "  ");
                    WriteLog(app, "TEST CAMERA READY");
                    WriteLog(app, "  ");
                    return(true);
                }
            }
            // Line 298 from VB script.
            // Iterate through documents returned from query
            bool   bIsFirstDocument = true;
            string ProcessedDocIDs  = "";
            //string ProcessedDoc = "";
            //string strDocID = "";
            string laststrPrimaryDocID = "0";

            //int intNumDocsProcessed = 0;
            //int gDocCount = 0;

            foreach (Document document in documentList)
            {
                if (bIsFirstDocument)
                {
                    DocumentType objDocType = document.DocumentType;
                    WriteLog(app, "  ");
                    WriteLog(app, "*************** SETTING DOCUMENT TYPE TO IT MASTER EQUIVALENT **************");
                    WriteLog(app, "  ");
                    WriteLog(app, String.Format("*************** CURRENT DOCUMENT TYPE : {0} **************", objDocType.Name.ToString().Trim()));
                    WriteLog(app, String.Format("*************** CURRENT DOCUMENT TYPE : {0} **************", objDocType.ID.ToString().Trim()));

                    DocumentType newdoctype = app.Core.DocumentTypes.Find(lngCurrentMSTRDTID);

                    if (newdoctype == null)
                    {
                        throw new ApplicationException(string.Format("Document Type {0} does not exist", lngCurrentMSTRDTID));
                    }
                    Storage           storage           = app.Core.Storage;
                    ReindexProperties reindexProperties = storage.CreateReindexProperties(document, newdoctype);
                    Document          newDocument       = storage.ReindexDocument(reindexProperties);

                    WriteLog(app, String.Format("*************** UPDATED DOCUMENT TYPE : {0} **************", newdoctype.Name));
                    WriteLog(app, String.Format("*************** UPDATED DOCUMENT TYPE ID (Should be: {0} : {1} **************", lngCurrentMSTRDTID.ToString(), document.ID.ToString()));

                    // Update the document AutoName
                    //WriteLog(app,"*************** UPDATED DOCUMENT AUTO NAME: " & Trim(CStr(objDoc.Name)) & " **************")
                    //objDoc.AutoName
                }
                app.Diagnostics.Write(string.Format("Document ID: {0} Document Name: {1}{2}", document.ID, document.Name, Environment.NewLine));
                //Line 349
                //int x = 1;
                // If there are multiple instances of a KW value on a document, we do not want to output the same doc again
                // as the result set will contain an document entry for each unique KW value of the same type.
                if (ProcessedDocIDs.Contains(document.ID.ToString().Trim()) || (document.ID.ToString() == laststrPrimaryDocID.Trim()))
                {
                    app.Diagnostics.Write("Made it into odd logic fork");
                }
                else
                {
                    //intNumDocsProcessed++;
                    ProcessedDocIDs = string.Format("{0}{1}", ProcessedDocIDs, document.ID.ToString().Trim());
                    //gDocCount++;
                    string fileTypeExt = "";

                    long      fileTypeID       = 2;
                    Rendition objFormRendition = document.DefaultRenditionOfLatestRevision;
                    fileTypeID = objFormRendition.FileType.ID;

                    switch (fileTypeID)
                    {
                    case 1:
                        fileTypeExt = "txt";
                        break;

                    case 2:
                        fileTypeExt = "tif";
                        break;

                    case 16:
                        fileTypeExt = "pdf";
                        break;

                    case 17:
                        fileTypeExt = "htm";
                        break;

                    case 13:
                        fileTypeExt = "xls";
                        break;

                    case 12:
                        fileTypeExt = "doc";
                        break;

                    case 14:
                        fileTypeExt = "ppt";
                        break;

                    case 15:
                        fileTypeExt = "rtf";
                        break;

                    case 24:
                        fileTypeExt = "htm";
                        break;

                    case 32:
                        fileTypeExt = "xml";
                        break;

                    default:
                        fileTypeExt = "unknown";
                        break;
                    }

                    KeywordType kwtDocConversionStatus = null;
                    Keyword     kwdDocConversionStatus = null;
                    if (fileTypeExt == "tif")
                    {
                        kwtDocConversionStatus = app.Core.KeywordTypes.Find(DOCUMENTCONVERSIONSTATUS);
                        if (kwtDocConversionStatus == null)
                        {
                            throw new Exception(String.Format("Keyword Type '{0}' not found", DOCUMENTCONVERSIONSTATUS));
                        }
                        kwdDocConversionStatus = CreateKeywordHelper(kwtDocConversionStatus, "CONV OK");
                        WriteLog(app, "Document file format is TIFF");
                    }
                    else
                    {
                        kwtDocConversionStatus = app.Core.KeywordTypes.Find(DOCUMENTCONVERSIONSTATUS);
                        if (kwtDocConversionStatus == null)
                        {
                            throw new Exception(String.Format("Keyword Type '{0}' not found", DOCUMENTCONVERSIONSTATUS));
                        }
                        kwdDocConversionStatus = CreateKeywordHelper(kwtDocConversionStatus, "NOT IMAGE FORMAT");
                        WriteLog(app, "Document file format is NOT TIFF - need to add logic to convert to TIFF");
                        strProcessingErrors = string.Format("{0}{1}{2}   " +
                                                            "Document is not Image File Format - {3}.  AN: {4} - LT: {5}", strProcessingErrors, Environment.NewLine, DateTime.Now.ToString(DateTimeFormat), strDocType, strApplicationNumber, strLicenseType);
                    }

                    using (DocumentLock documentLock = document.LockDocument())
                    {
                        // Ensure lock was obtained
                        if (documentLock.Status != DocumentLockStatus.LockObtained)
                        {
                            throw new Exception("Document lock not obtained");
                        }
                        // Create keyword modifier object to hold keyword changes
                        KeywordModifier keyModifier = document.CreateKeywordModifier();

                        //Add update keyword call to keyword modifier object
                        //Note Overloads available for use
                        //(I.E.): keyModifier.AddKeyword(keywordTypeName,keywordValue)
                        keyModifier.AddKeyword(kwdDocConversionStatus);

                        // Apply keyword change to the document
                        keyModifier.ApplyChanges();

                        WriteLog(app, string.Format("Keyword: '{0}' added to Document .", DOCUMENTCONVERSIONSTATUS));
                    }
                    if (fileTypeExt != "tif")
                    {
                        return(false);
                    }

                    WriteLog(app, string.Format("  Processing DocID [{0}]", document.ID.ToString()));
                    // Set property bag for use by OnBase DocDataProvider object
                    args.PropertyBag.Set("docID", document.ID.ToString());

                    sourceDocHandle = document.ID;

                    // If the source file format is not image, we need to save it out and append to the current document.
                    // Otherwise, we need to append the current image file in the diskgroup
                    // If currentDocumentFileFormatIsImage Then
                    if (bIsFirstDocument)
                    {
                        app.Diagnostics.Write("in first doc logic");
                        destinationDocHandle = sourceDocHandle;
                        bIsFirstDocument     = false;
                    }
                    else
                    {
                        app.Diagnostics.Write("Made it in");
                        AppendToDocument(app, args, sourceDocHandle, destinationDocHandle);
                    }
                }
                laststrPrimaryDocID = document.ID.ToString();
            }
            return(true);
        }