public virtual ValueSetValidationResult Validate(ValueSet valueSet)
        {
            if (ValidIndexCategories != null && !ValidIndexCategories.InvariantContains(valueSet.Category))
            {
                return(new ValueSetValidationResult(ValueSetValidationStatus.Failed, valueSet));
            }

            //check if this document is of a correct type of node type alias
            if (IncludeItemTypes != null && !IncludeItemTypes.InvariantContains(valueSet.ItemType))
            {
                return(new ValueSetValidationResult(ValueSetValidationStatus.Failed, valueSet));
            }

            //if this node type is part of our exclusion list
            if (ExcludeItemTypes != null && ExcludeItemTypes.InvariantContains(valueSet.ItemType))
            {
                return(new ValueSetValidationResult(ValueSetValidationStatus.Failed, valueSet));
            }

            var isFiltered = false;

            var filteredValues = valueSet.Values.ToDictionary(x => x.Key, x => x.Value.ToList());

            //filter based on the fields provided (if any)
            if (IncludeFields != null || ExcludeFields != null)
            {
                foreach (var key in valueSet.Values.Keys.ToList())
                {
                    if (IncludeFields != null && !IncludeFields.InvariantContains(key))
                    {
                        filteredValues.Remove(key); //remove any value with a key that doesn't match the inclusion list
                        isFiltered = true;
                    }

                    if (ExcludeFields != null && ExcludeFields.InvariantContains(key))
                    {
                        filteredValues.Remove(key); //remove any value with a key that matches the exclusion list
                        isFiltered = true;
                    }
                }
            }

            var filteredValueSet = new ValueSet(valueSet.Id, valueSet.Category, valueSet.ItemType, filteredValues.ToDictionary(x => x.Key, x => (IEnumerable <object>)x.Value));

            return(new ValueSetValidationResult(isFiltered ? ValueSetValidationStatus.Filtered : ValueSetValidationStatus.Valid, filteredValueSet));
        }
예제 #2
0
        public virtual ValueSetValidationResult Validate(ValueSet valueSet)
        {
            if (ValidIndexCategories != null && !ValidIndexCategories.InvariantContains(valueSet.Category))
            {
                return(ValueSetValidationResult.Failed);
            }

            //check if this document is of a correct type of node type alias
            if (IncludeItemTypes != null && !IncludeItemTypes.InvariantContains(valueSet.ItemType))
            {
                return(ValueSetValidationResult.Failed);
            }

            //if this node type is part of our exclusion list
            if (ExcludeItemTypes != null && ExcludeItemTypes.InvariantContains(valueSet.ItemType))
            {
                return(ValueSetValidationResult.Failed);
            }

            var isFiltered = false;

            //filter based on the fields provided (if any)
            if (IncludeFields != null || ExcludeFields != null)
            {
                foreach (var key in valueSet.Values.Keys.ToList())
                {
                    if (IncludeFields != null && !IncludeFields.InvariantContains(key))
                    {
                        valueSet.Values.Remove(key); //remove any value with a key that doesn't match the inclusion list
                        isFiltered = true;
                    }

                    if (ExcludeFields != null && ExcludeFields.InvariantContains(key))
                    {
                        valueSet.Values.Remove(key); //remove any value with a key that matches the exclusion list
                        isFiltered = true;
                    }
                }
            }

            return(isFiltered ? ValueSetValidationResult.Filtered : ValueSetValidationResult.Valid);
        }