示例#1
0
        /// <summary>
        /// Performs all the necessary operations on the EditableKeywordModifier
        /// Removes will not affect updates or adds.
        /// Meaning a request to update the old value of a keyword will not be affected by a request to remove the old value
        /// Similarly a request to update a keyword that is in the add request collection, will not succeed.
        /// the method also handles expansion of autofill keysets if requested, and using defaults to satisfy
        /// retuired keywords if requested.
        /// </summary>
        /// <param name="aModifier">EditableKeywordModifier on which to operate</param>
        /// <param name="aDocument">Document on which modifications will take place</param>
        /// <param name="aUpdateRequest">Collection of keyword update requests</param>
        /// <param name="aAddRequest">Collection of keyword addition requests</param>
        /// <param name="aRemoveRequest">Collection of keyword removal requests</param>
        /// <param name="aExpandKeyset">If true, autofill keysets will be expanded</param>
        /// <param name="aUseDefaultForRequiredKeys">If true, default keyword values will be used to satisfy any missing required keywords</param>
        private void EditKeywords(EditableKeywordModifier aModifier, Document aDocument,
                                  IEnumerable <KeywordUpdate> aUpdateRequest, IEnumerable <Keyword> aAddRequest, IEnumerable <Keyword> aRemoveRequest,
                                  bool aExpandKeyset, bool aUseDefaultForRequiredKeys)
        {
            if (aUpdateRequest == null)
            {
                aUpdateRequest = new List <KeywordUpdate>();
            }
            if (aAddRequest == null)
            {
                aAddRequest = new List <Keyword>();
            }
            if (aRemoveRequest == null)
            {
                aRemoveRequest = new List <Keyword>();
            }
            DocumentType      lDocumentType = aDocument.DocumentType;
            KeywordRecordType lStandaloneKeywordRecordType = lDocumentType.KeywordRecordTypes.Find(STANDALONE_KEYWORD_RECORD_TYPE);
            KeywordRecord     lStandaloneKeywordRecord     = aDocument.KeywordRecords.Find(lStandaloneKeywordRecordType);

            List <Keyword>             lExpectedUnmodified    = new List <Keyword>();
            List <Keyword>             lExpectedRemoved       = new List <Keyword>();
            List <Keyword>             lExpectedAddedByUpdate = new List <Keyword>();
            ILookup <Keyword, Keyword> lLookupUpdate          = aUpdateRequest.ToLookup(x => x.OldValue, y => y.NewValue);

            foreach (Keyword lExistingKeyword in lStandaloneKeywordRecord.Keywords)
            {
                IEnumerable <Keyword> lNewValues = lLookupUpdate[lExistingKeyword];
                if (lNewValues.Any())
                {
                    lExpectedAddedByUpdate.AddRange(lNewValues);
                }
                else if (aRemoveRequest.Contains(lExistingKeyword))
                {
                    lExpectedRemoved.Add(lExistingKeyword);
                }
                else
                {
                    lExpectedUnmodified.Add(lExistingKeyword);
                }
            }
            IEnumerable <Keyword> lUpdateAndAdd    = lExpectedAddedByUpdate.Concat(aAddRequest);
            IEnumerable <Keyword> lExpanded        = (aExpandKeyset) ? ExpandAutoFillKeyset(lUpdateAndAdd, lDocumentType, aUseDefaultForRequiredKeys) : new List <Keyword>();
            IEnumerable <Keyword> lExpectedResult  = lExpectedUnmodified.Concat(lUpdateAndAdd).Concat(lExpanded);
            IEnumerable <Keyword> lRequiredDefault = VerifyRequiredKeyword(lExpectedResult, lDocumentType.KeywordTypesRequiredForArchival, aUseDefaultForRequiredKeys);

            foreach (Keyword lKeyword in lExpectedRemoved)
            {
                aModifier.RemoveKeyword(lKeyword);
            }
            foreach (KeywordUpdate lUpdate in aUpdateRequest)
            {
                aModifier.UpdateKeyword(lUpdate.OldValue, lUpdate.NewValue);
            }
            AddKeywords(aModifier, aAddRequest);
            AddKeywords(aModifier, lExpanded);
            AddKeywords(aModifier, lRequiredDefault);
        }
示例#2
0
        private void EditKeywords(EditableKeywordModifier aModifier, Document aDocument, DocumentType aNewDocumentType, IEnumerable <Keyword> aKeywords, bool aExpandKeyset, bool aUseDefaultForRequiredKeys)
        {
            if (aKeywords == null)
            {
                aKeywords = new List <Keyword>();
            }

            DocumentType      lDocumentType = aDocument.DocumentType;
            KeywordRecordType lStandaloneKeywordRecordType = aNewDocumentType.KeywordRecordTypes.Find(STANDALONE_KEYWORD_RECORD_TYPE);

            IEnumerable <Keyword>          lDefinedRequestedKeywords = aKeywords.Where(x => aNewDocumentType.IsDefined(x));
            IEnumerable <Keyword>          lExpansion             = (aExpandKeyset) ? ExpandAutoFillKeyset(lDefinedRequestedKeywords, aNewDocumentType, aUseDefaultForRequiredKeys) : new List <Keyword>();
            IEnumerable <Keyword>          lFullRequest           = aKeywords.Concat(lExpansion);
            ILookup <KeywordType, Keyword> lNewKeywordLookup      = lFullRequest.ToLookup(x => x.KeywordType);
            ILookup <KeywordType, Keyword> lExistingKeywordLookup = aDocument.GetStandaloneKeywords().ToLookup(x => x.KeywordType);
            List <Keyword> lExpectedUnmodified = new List <Keyword>();
            List <Keyword> lExpectedRemoved    = new List <Keyword>();


            foreach (IGrouping <KeywordType, Keyword> lGroup in lExistingKeywordLookup)
            {
                if (!aNewDocumentType.IsDefined(lGroup.Key) || lNewKeywordLookup.Contains(lGroup.Key))
                {
                    lExpectedRemoved.AddRange(lGroup);
                }
                else
                {
                    lExpectedUnmodified.AddRange(lGroup);
                }
            }

            IEnumerable <Keyword> lRequestedAndUnmodified = lFullRequest.Concat(lExpectedUnmodified);
            IEnumerable <Keyword> lRequiredDefault        = VerifyRequiredKeyword(lRequestedAndUnmodified, lDocumentType.KeywordTypesRequiredForArchival, aUseDefaultForRequiredKeys);

            foreach (Keyword lKeyword in lExpectedRemoved)
            {
                aModifier.RemoveKeyword(lKeyword);
            }

            AddKeywords(aModifier, lFullRequest);
            AddKeywords(aModifier, lRequiredDefault);
        }
示例#3
0
        public KeywordRecordType GetKeywordRecordType(long aKeywordRecordType, DocumentType aDocumentType = null)
        {
            KeywordRecordTypeList lKeywordRecordTypeList;

            if (aDocumentType == null)
            {
                lKeywordRecordTypeList = Application.Core.KeywordRecordTypes;
            }
            else
            {
                lKeywordRecordTypeList = aDocumentType.KeywordRecordTypes;
            }

            KeywordRecordType lType = lKeywordRecordTypeList.Find(aKeywordRecordType);

            if (lType == null)
            {
                throw new ArgumentOutOfRangeException("Invalid Keyword Record Type: " + aKeywordRecordType);
            }

            return(lType);
        }
示例#4
0
        private void ModifyKeywordInCurrentDocument(Document doc, string keywordType, string keywordValue)
        {
            using (DocumentLock documentLock = doc.LockDocument())
            {
                if (documentLock.Status == DocumentLockStatus.LockObtained)
                {
                    KeywordModifier keymod  = doc.CreateKeywordModifier();
                    KeywordType     keyType = _app.Core.KeywordTypes.Find(keywordType);
                    if (keyType == null)
                    {
                        keymod.AddKeyword(keywordType, keywordValue);
                    }
                    else
                    {
                        KeywordRecord     keyRec     = doc.KeywordRecords.Find(keyType);
                        KeywordRecordType keyRecType = keyRec.KeywordRecordType;

                        Keyword newKeyword = keyType.CreateKeyword(keywordValue);

                        if (keyRecType.RecordType == RecordType.MultiInstance)
                        {
                            EditableKeywordRecord editKeyRec = keyRec.CreateEditableKeywordRecord();
                            Keyword keyword = editKeyRec.Keywords.Find(keywordType);
                            editKeyRec.UpdateKeyword(keyword, newKeyword);
                            keymod.AddKeywordRecord(editKeyRec);
                        }
                        else
                        {
                            Keyword keyword = keyRec.Keywords.Find(keywordType);
                            keymod.UpdateKeyword(keyword, newKeyword);
                        }
                    }
                    keymod.ApplyChanges();
                }
            }
        }
示例#5
0
        public static void ArchiveDocument(Application app, string documentsDir, string documentTypeGroup)
        {
            logger.Info("Archive (upload) documents...");
            try
            {
                string filePath = documentsDir + "\\archive.json";
                if (File.Exists(filePath))
                {
                    logger.Info("Archive config file found: " + filePath);
                    string inputJSON = File.ReadAllText(filePath);

                    logger.Info("Get Document Type Group: " + documentTypeGroup);
                    DocumentTypeGroup docTypeGroup = app.Core.DocumentTypeGroups.Find(documentTypeGroup);
                    if (docTypeGroup == null)
                    {
                        throw new Exception("Document Type Group not found: " + documentTypeGroup);
                    }
                    logger.Info("Document Type Group found: " + documentTypeGroup);

                    IList <JToken> jTokens = JToken.Parse(inputJSON)["contents"].Children().ToList();
                    foreach (JToken jToken in jTokens)
                    {
                        Content content = jToken.ToObject <Content>();
                        logger.Info("");
                        logger.Info("Get Document Type: " + content.documentType);
                        DocumentType docType = docTypeGroup.DocumentTypes.Find(content.documentType);
                        if (docType == null)
                        {
                            throw new Exception("Document type was not found");
                        }

                        logger.Info("Get File Type: " + content.fileTypes[0]);
                        FileType fType = app.Core.FileTypes.Find(content.fileTypes[0]);
                        if (fType == null)
                        {
                            throw new Exception("File type was not found");
                        }

                        KeywordRecordType keywordRecordType = docType.KeywordRecordTypes[0];

                        string fileUploadPath = documentsDir + "\\" + content.file;
                        if (File.Exists(fileUploadPath))
                        {
                            logger.Info("Archive document found: " + fileUploadPath);
                            List <string> fileList = new List <string>();
                            fileList.Add(fileUploadPath);

                            StoreNewDocumentProperties storeDocumentProperties = app.Core.Storage.CreateStoreNewDocumentProperties(docType, fType);
                            foreach (var kt in keywordRecordType.KeywordTypes)
                            {
                                if (content.keywords.ContainsKey(kt.Name))
                                {
                                    logger.Info("Add Keyword: " + kt.Name + " = " + content.keywords[kt.Name]);

                                    switch (kt.DataType)
                                    {
                                    case KeywordDataType.AlphaNumeric:
                                        storeDocumentProperties.AddKeyword(kt.CreateKeyword(content.keywords[kt.Name]));
                                        break;

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

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

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

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

                            storeDocumentProperties.DocumentDate = DateTime.Now;
                            storeDocumentProperties.Comment      = "RSI OnBase Unity Application";
                            storeDocumentProperties.Options      = StoreDocumentOptions.SkipWorkflow;

                            Document newDocument = app.Core.Storage.StoreNewDocument(fileList, storeDocumentProperties);

                            logger.Info(string.Format("Document Archive was successful. New Document ID: {0}", newDocument.ID.ToString()));
                        }
                        else
                        {
                            logger.Info("Archive document file not found: " + fileUploadPath);
                        }
                    }
                }
                else
                {
                    logger.Info("Archive config file not found: " + filePath);
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex.Message, ex);
            }

            logger.Info("");
        }
示例#6
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);
        }