예제 #1
0
        /// <summary>
        /// Implementation of <see cref="IWorkflowScript.OnWorkflowScriptExecute" />.
        /// <seealso cref="IWorkflowScript" />
        /// </summary>
        /// <param name="app"></param>
        /// <param name="args"></param>
        public void OnWorkflowScriptExecute(Hyland.Unity.Application app, Hyland.Unity.WorkflowEventArgs args)
        {
            args.SessionPropertyBag.TryGetValue("propPriKey", out priKey);
            args.SessionPropertyBag.TryGetValue("propSecKey", out secKey);
            Document     doc     = args.Document;
            DocumentType docType = doc.DocumentType;

            SetKeywordValues(doc);
            DocumentQuery docQuery = app.Core.CreateDocumentQuery();

            docQuery.AddDocumentType(docType);

            KeywordType keyType    = app.Core.KeywordTypes.Find(priKey);
            Keyword     priKeyword = keyType.CreateKeyword(priVal);

            docQuery.AddKeyword(priKeyword);

            DocumentList docList = docQuery.Execute(10000);

            Keyword secKeyword = keyType.CreateKeyword(secVal);

            foreach (Document newDoc in docList)
            {
                foreach (KeywordRecord keywordRecord in newDoc.KeywordRecords)
                {
                    foreach (Keyword keyword in keywordRecord.Keywords)
                    {
                        if (keyword.KeywordType.Name == priKey)
                        {
                            string priGetValToCompare = keyword.IsBlank?string.Empty:keyword.Value.ToString();
                            if (priGetValToCompare.Trim() == priVal.Trim())
                            {
                                using (DocumentLock documentLock = newDoc.LockDocument())
                                {
                                    if (documentLock.Status == DocumentLockStatus.LockObtained)
                                    {
                                        KeywordModifier keymod = newDoc.CreateKeywordModifier();
                                        keymod.UpdateKeyword(priKeyword, secKeyword);
                                        keymod.ApplyChanges();
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
예제 #2
0
        public static List <long> QueryDocuments(Application app, string documentsDir)
        {
            logger.Info("Execute document query...");
            List <long> documentIdList = new List <long>();
            string      filePath       = documentsDir + "\\query.json";

            if (File.Exists(filePath))
            {
                logger.Info("Query File found: " + filePath);
                string inputJSON = File.ReadAllText(filePath);

                IList <JToken> jTokens = JToken.Parse(inputJSON)["contents"].Children().ToList();
                foreach (JToken jToken in jTokens)
                {
                    Content content = jToken.ToObject <Content>();

                    DocumentType documentType = app.Core.DocumentTypes.Find(content.documentType);

                    if (documentType == null)
                    {
                        throw new Exception("Document type was not found");
                    }

                    DocumentQuery documentQuery = app.Core.CreateDocumentQuery();
                    documentQuery.AddDisplayColumn(DisplayColumnType.AuthorName);
                    documentQuery.AddDisplayColumn(DisplayColumnType.DocumentDate);
                    documentQuery.AddDisplayColumn(DisplayColumnType.ArchivalDate);
                    documentQuery.AddDocumentType(documentType);

                    KeywordRecordType keywordRecordType = documentType.KeywordRecordTypes[0];

                    foreach (var kt in keywordRecordType.KeywordTypes)
                    {
                        if (content.keywords.ContainsKey(kt.Name))
                        {
                            switch (kt.DataType)
                            {
                            case KeywordDataType.AlphaNumeric:
                                documentQuery.AddKeyword(kt.CreateKeyword(content.keywords[kt.Name]));
                                break;

                            case KeywordDataType.Currency:
                            case KeywordDataType.SpecificCurrency:
                            case KeywordDataType.Numeric20:
                                documentQuery.AddKeyword(kt.CreateKeyword(decimal.Parse(content.keywords[kt.Name])));
                                break;

                            case KeywordDataType.Date:
                            case KeywordDataType.DateTime:
                                documentQuery.AddKeyword(kt.CreateKeyword(DateTime.Parse(content.keywords[kt.Name])));
                                break;

                            case KeywordDataType.FloatingPoint:
                                documentQuery.AddKeyword(kt.CreateKeyword(double.Parse(content.keywords[kt.Name])));
                                break;

                            case KeywordDataType.Numeric9:
                                documentQuery.AddKeyword(kt.CreateKeyword(long.Parse(content.keywords[kt.Name])));
                                break;
                            }
                        }
                    }

                    using (QueryResult queryResults = documentQuery.ExecuteQueryResults(long.MaxValue))
                    {
                        logger.Info("Number of " + content.documentType + " Documents Found: " + queryResults.QueryResultItems.Count().ToString());
                        foreach (QueryResultItem queryResultItem in queryResults.QueryResultItems)
                        {
                            if (!documentIdList.Contains(queryResultItem.Document.ID))
                            {
                                documentIdList.Add(queryResultItem.Document.ID);
                            }

                            logger.Info(string.Format("Document ID: {0}", queryResultItem.Document.ID.ToString()));
                            logger.Info(string.Format("Author: {0}, Document Date: {1}, Archival Date: {2}", queryResultItem.DisplayColumns[0].Value.ToString(), DateTime.Parse(queryResultItem.DisplayColumns[1].Value.ToString()).ToShortDateString(), DateTime.Parse(queryResultItem.DisplayColumns[2].Value.ToString()).ToShortDateString()));

                            foreach (var keyword in queryResultItem.Document.KeywordRecords[0].Keywords)
                            {
                                logger.Info(keyword.KeywordType.Name + " : " + keyword.Value.ToString());
                            }
                            logger.Info("");
                        }
                    }
                }
            }
            logger.Info("");
            return(documentIdList);
        }
예제 #3
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);
        }