Ejemplo n.º 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);
        }
Ejemplo n.º 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);
        }