GetElementsByCategory(
            [NotNull] IEnumerable <QualitySpecificationElement> qualitySpecificationElements,
            [NotNull] out List <QualitySpecificationElement> elementsWithNoCategory)
        {
            elementsWithNoCategory = new List <QualitySpecificationElement>();
            var result =
                new Dictionary <DataQualityCategory, List <QualitySpecificationElement> >();

            foreach (QualitySpecificationElement element in qualitySpecificationElements)
            {
                QualityCondition condition = element.QualityCondition;

                DataQualityCategory category = condition.Category;
                if (category == null)
                {
                    elementsWithNoCategory.Add(element);
                }
                else
                {
                    List <QualitySpecificationElement> elements;
                    if (!result.TryGetValue(category, out elements))
                    {
                        elements = new List <QualitySpecificationElement>();
                        result.Add(category, elements);
                    }

                    elements.Add(element);
                }
            }

            return(result);
        }
        internal HtmlDataQualityCategory(
            [CanBeNull] DataQualityCategory category,
            [CanBeNull] HtmlDataQualityCategoryOptions options,
            [NotNull] HtmlDataQualityCategoryComparer categoryComparer,
            [NotNull] HtmlQualitySpecificationElementComparer elementComparer)
        {
            Assert.ArgumentNotNull(categoryComparer, nameof(categoryComparer));
            Assert.ArgumentNotNull(elementComparer, nameof(elementComparer));

            _category         = category;
            _categoryComparer = categoryComparer;
            _elementComparer  = elementComparer;

            if (category == null)
            {
                _isUndefinedCategory = true;
                _uniqueName          = "<nocategory>";

                _name         = string.Empty;
                _abbreviation = string.Empty;
            }
            else
            {
                _isUndefinedCategory = false;
                _uniqueName          = category.GetQualifiedName("||");

                _name         = GetDisplayName(category, options);
                _abbreviation = category.Abbreviation ?? string.Empty;
            }
        }
        public IList <QualitySpecification> Get(
            DataQualityCategory category,
            bool includeSubCategories = false)
        {
            if (category != null && !category.IsPersistent)
            {
                return(new List <QualitySpecification>());
            }

            if (category == null && includeSubCategories)
            {
                return(GetAll());
            }

            using (ISession session = OpenSession(true))
            {
                List <QualitySpecification> result = Get(category, session).ToList();

                if (!includeSubCategories)
                {
                    return(result);
                }

                AddSubCategoryQualitySpecifications(category, result, session);

                return(result);
            }
        }
示例#4
0
        private static IList <QualityCondition> Get(
            [CanBeNull] DataQualityCategory category,
            [NotNull] ISession session,
            bool includeQualityConditionsBasedOnDeletedDatasets = true)
        {
            ICriteria criteria = session.CreateCriteria(typeof(QualityCondition));

            const string categoryProperty = "Category";

            ICriterion filterCriterion =
                category == null
                                        ? (ICriterion) new NullExpression(categoryProperty)
                                        : Restrictions.Eq(categoryProperty, category);

            IList <QualityCondition> all = criteria.Add(filterCriterion)
                                           .List <QualityCondition>();

            if (all.Count == 0 || includeQualityConditionsBasedOnDeletedDatasets)
            {
                return(all);
            }

            HashSet <int> excludedIds = GetQualityConditionIdsInvolvingDeletedDatasets(session);

            return(all.Where(qc => !excludedIds.Contains(qc.Id))
                   .ToList());
        }
示例#5
0
        GetWithDatasetParameterValues(DataQualityCategory category = null)
        {
            var result = new Dictionary <QualityCondition, IList <DatasetTestParameterValue> >();

            if (category != null && !category.IsPersistent)
            {
                return(result);
            }

            using (ISession session = OpenSession(true))
            {
                Dictionary <int, QualityCondition> conditionsById =
                    Get(category, session)
                    .ToDictionary(qcon => qcon.Id);

                foreach (KeyValuePair <int, List <DatasetTestParameterValue> > pair in
                         GetDatasetValuesByConditionId(category, session))
                {
                    int conditionId = pair.Key;
                    List <DatasetTestParameterValue> values = pair.Value;

                    result.Add(conditionsById[conditionId], values);
                }

                return(result);
            }
        }
示例#6
0
        private static DataQualityCategoryItem GetDataQualityCategoryItem(
            [NotNull] Dictionary <DataQualityCategory, DataQualityCategoryItem> itemsByCategory,
            [NotNull] DataQualityCategory category)
        {
            Assert.ArgumentNotNull(itemsByCategory, nameof(itemsByCategory));
            Assert.ArgumentNotNull(category, nameof(category));

            DataQualityCategoryItem item;

            if (itemsByCategory.TryGetValue(category, out item))
            {
                return(item);
            }

            item = new DataQualityCategoryItem(category);
            itemsByCategory.Add(category, item);

            if (category.ParentCategory != null)
            {
                DataQualityCategoryItem parentItem = GetDataQualityCategoryItem(itemsByCategory,
                                                                                category
                                                                                .ParentCategory);
                parentItem.SubCategories.Add(item);
            }

            return(item);
        }
        private XmlVerifiedCategory GetVerifiedCategory(
            [NotNull] DataQualityCategory category)
        {
            string key = Assert.NotNull(category.Uuid);

            XmlVerifiedCategory xmlCategory;

            if (!_categoriesByUuid.TryGetValue(key, out xmlCategory))
            {
                xmlCategory = new XmlVerifiedCategory(category.Name,
                                                      category.Abbreviation,
                                                      category.Uuid,
                                                      category.Description,
                                                      category.ListOrder);

                _categoriesByUuid.Add(key, xmlCategory);

                if (category.ParentCategory == null)
                {
                    _rootCategories.Add(xmlCategory);
                }
                else
                {
                    // ensure that parent category is added also
                    XmlVerifiedCategory parentVerifiedCategory =
                        GetVerifiedCategory(category.ParentCategory);

                    parentVerifiedCategory.AddSubCategory(xmlCategory);
                }

                _sortOrderDirty = true;
            }

            return(xmlCategory);
        }
        public void CanGetCategoryHierarchy()
        {
            var cat1     = new DataQualityCategory("1", "1");
            var cat2     = new DataQualityCategory("2", "2");
            var cat1_1   = new DataQualityCategory("1", "1.1");
            var cat1_2   = new DataQualityCategory("2", "1.2");
            var cat1_1_1 = new DataQualityCategory("1", "1.1.1");

            cat1.AddSubCategory(cat1_1);
            cat1.AddSubCategory(cat1_2);
            cat1_1.AddSubCategory(cat1_1_1);

            var qspecA = new QualitySpecification("qspec A")
            {
                Category = cat1_1
            };
            var qspecB = new QualitySpecification("qspec B")
            {
                Category = cat1_1
            };
            var qspecC = new QualitySpecification("qspec C")
            {
                Category = cat1_1_1
            };
            var qspec1 = new QualitySpecification("qspec X");
            var qspec2 = new QualitySpecification("qspec Y");

            CreateSchema(cat1, cat2, cat1_1, cat1_2, cat1_1_1,
                         qspecA, qspecB, qspecC, qspec1, qspec2);

            UnitOfWork.NewTransaction(
                delegate
            {
                IList <DataQualityCategory> categories =
                    Repository.GetTopLevelCategories();
                var qspecRepository = Resolve <IQualitySpecificationRepository>();
                Assert.AreEqual(2, categories.Count);

                Assert.IsTrue(categories.Contains(cat1));
                Assert.IsTrue(categories.Contains(cat2));

                string hierarchy = FormatHierarchy(qspecRepository, categories);

                const string expected = @"* qspec X
* qspec Y
> 1
  > 1
    * qspec A
    * qspec B
    > 1
      * qspec C
  > 2
> 2
";
                Console.WriteLine(hierarchy);

                Assert.AreEqual(expected, hierarchy);
            });
        }
        public void CanGroupQualityConditionsWithCompleteExclusion()
        {
            var catA   = new DataQualityCategory("A");
            var catA1  = new DataQualityCategory("A1");
            var catA11 = new DataQualityCategory("A11");

            catA.AddSubCategory(catA1);
            catA1.AddSubCategory(catA11);

            var test = new TestDescriptor("test", new ClassDescriptor(typeof(QaMinSegAngle)));

            var qc1 = new QualityCondition("qc1", test)
            {
                Category = catA11
            };
            var qc2 = new QualityCondition("qc2", test)
            {
                Category = catA11
            };
            var qc3 = new QualityCondition("qc3", test)
            {
                Category = catA11
            };

            var issueGroups = new List <IssueGroup>
            {
                CreateIssueGroup(qc1, "ic1", 3),
                CreateIssueGroup(qc2, "ic2", 4),
                CreateIssueGroup(qc3, "ic3", 5),
                CreateIssueGroup(qc3, "ic4", 6)
            };

            var reportDefinition = new HtmlReportDefinition(
                "templatepath", "fileName",
                new List <HtmlDataQualityCategoryOptions>
            {
                new HtmlDataQualityCategoryOptions(catA.Uuid, ignoreCategoryLevel: true),
                new HtmlDataQualityCategoryOptions(catA1.Uuid, ignoreCategoryLevel: true),
                new HtmlDataQualityCategoryOptions(catA11.Uuid, ignoreCategoryLevel: true),
            });

            List <HtmlReportIssueGroup>          reportIssueGroups;
            List <HtmlReportDataQualityCategory> reportCategories =
                GroupByCategories(issueGroups, reportDefinition,
                                  out reportIssueGroups);

            Assert.AreEqual(4, reportIssueGroups.Count);
            Assert.AreEqual(18, reportIssueGroups.Sum(ig => ig.IssueCount));

            Assert.AreEqual(1, reportCategories.Count);
            Assert.AreEqual(18, reportCategories.Sum(qc => qc.IssueCount));

            List <HtmlReportDataQualityCategory> rootCategories =
                reportCategories.Where(qc => qc.IsRoot)
                .ToList();

            Assert.AreEqual(1, rootCategories.Count);
            Assert.AreEqual(18, rootCategories.Sum(qc => qc.IssueCountWithChildren));
        }
示例#10
0
 private static HtmlDataQualityCategoryOptions GetReportCategoryOptions(
     [CanBeNull] IHtmlDataQualityCategoryOptionsProvider categoryOptionsProvider,
     [CanBeNull] DataQualityCategory category)
 {
     return(category == null
                                ? null
                                : categoryOptionsProvider?.GetCategoryOptions(category.Uuid));
 }
        private void AddToCategory(
            [NotNull] XmlVerifiedQualityCondition xmlVerifiedCondition,
            [NotNull] DataQualityCategory category)
        {
            XmlVerifiedCategory xmlCategory = GetVerifiedCategory(category);

            xmlCategory.AddCondition(xmlVerifiedCondition);
        }
        private static HtmlDataQualityCategory AddDataQualityCategory(
            [CanBeNull] DataQualityCategory category,
            [NotNull] HtmlDataQualityCategoryComparer categoryComparer,
            [NotNull] HtmlQualitySpecificationElementComparer elementComparer,
            [NotNull] IDictionary <string, HtmlDataQualityCategory> reportCategories,
            [CanBeNull] IHtmlDataQualityCategoryOptionsProvider optionsProvider = null)
        {
            string key = GetCategoryKey(category);

            HtmlDataQualityCategory result;

            if (reportCategories.TryGetValue(key, out result))
            {
                // already added (including parents)
                return(result);
            }

            HtmlDataQualityCategoryOptions options =
                GetReportCategoryOptions(optionsProvider, category);

            if (category != null && options != null && options.IgnoreCategoryLevel)
            {
                // skip this category level
                result = AddDataQualityCategory(category.ParentCategory,
                                                categoryComparer,
                                                elementComparer,
                                                reportCategories,
                                                optionsProvider);

                reportCategories.Add(key, result);
                return(result);
            }

            result = new HtmlDataQualityCategory(category,
                                                 options,
                                                 categoryComparer,
                                                 elementComparer);
            reportCategories.Add(key, result);

            if (category != null && category.ParentCategory != null)
            {
                HtmlDataQualityCategory parent = AddDataQualityCategory(category.ParentCategory,
                                                                        categoryComparer,
                                                                        elementComparer,
                                                                        reportCategories,
                                                                        optionsProvider);
                if (!parent.IsUndefinedCategory)
                {
                    result.ParentCategory = parent;
                    result.ParentCategory.IncludeSubCategory(result);
                }
            }

            return(result);
        }
示例#13
0
        public void CanGroupQualityConditionsWithoutExclusion()
        {
            var catA    = new DataQualityCategory("A");
            var catA1   = new DataQualityCategory("A1");
            var catA11  = new DataQualityCategory("A11");
            var catB    = new DataQualityCategory("B");
            var catB1   = new DataQualityCategory("B1");
            var catB11  = new DataQualityCategory("B11");
            var catB111 = new DataQualityCategory("B111");

            catA.AddSubCategory(catA1);
            catA1.AddSubCategory(catA11);
            catB.AddSubCategory(catB1);
            catB1.AddSubCategory(catB11);
            catB11.AddSubCategory(catB111);

            var test = new TestDescriptor("test", new ClassDescriptor(typeof(QaMinSegAngle)));

            var qc1 = new QualityCondition("qc1", test)
            {
                Category = catA11
            };
            var qc2 = new QualityCondition("qc2", test)
            {
                Category = catB11
            };
            var qc3 = new QualityCondition("qc3", test)
            {
                Category = catB11
            };

            var issueGroups = new List <IssueGroup>
            {
                CreateIssueGroup(qc1, "ic1", 3),
                CreateIssueGroup(qc2, "ic2", 4),
                CreateIssueGroup(qc3, "ic3", 5),
                CreateIssueGroup(qc3, "ic4", 6)
            };

            List <HtmlReportIssueGroup>          reportIssueGroups;
            List <HtmlReportDataQualityCategory> reportCategories =
                GroupByCategories(issueGroups, null, out reportIssueGroups);

            Assert.AreEqual(18, reportIssueGroups.Sum(ig => ig.IssueCount));

            Assert.AreEqual(6, reportCategories.Count);
            Assert.AreEqual(18, reportCategories.Sum(qc => qc.IssueCount));

            List <HtmlReportDataQualityCategory> rootCategories =
                reportCategories.Where(qc => qc.IsRoot)
                .ToList();

            Assert.AreEqual(2, rootCategories.Count);
            Assert.AreEqual(18, rootCategories.Sum(qc => qc.IssueCountWithChildren));
        }
        public DataQualityCategoryItem([CanBeNull] DataQualityCategory category)
        {
            Category = category;

            IsUndefinedCategory = category == null;
            Name = category == null
                                       ? "<no category>"
                                       : category.Name;

            IsRootCategory = category == null || category.ParentCategory == null;
        }
        private static void AddSubCategoryQualitySpecifications(
            [NotNull] DataQualityCategory category,
            [NotNull] List <QualitySpecification> result,
            [NotNull] ISession session)
        {
            foreach (DataQualityCategory subCategory in category.SubCategories)
            {
                result.AddRange(Get(subCategory, session));

                AddSubCategoryQualitySpecifications(subCategory, result, session);
            }
        }
示例#16
0
        public IList <QualityCondition> Get(
            DataQualityCategory category,
            bool includeQualityConditionsBasedOnDeletedDatasets = true)
        {
            if (category != null && !category.IsPersistent)
            {
                return(new List <QualityCondition>());
            }

            using (ISession session = OpenSession(true))
            {
                return(Get(category, session, includeQualityConditionsBasedOnDeletedDatasets));
            }
        }
        private static IEnumerable <QualitySpecification> Get(
            [CanBeNull] DataQualityCategory category, [NotNull] ISession session)
        {
            ICriteria criteria = session.CreateCriteria(typeof(QualitySpecification));

            const string categoryProperty = "Category";

            ICriterion filterCriterion =
                category == null
                                        ? (ICriterion) new NullExpression(categoryProperty)
                                        : Restrictions.Eq(categoryProperty, category);

            return(criteria.Add(filterCriterion)
                   .List <QualitySpecification>());
        }
示例#18
0
        private static string GetDisplayName(
            [NotNull] DataQualityCategory category,
            [CanBeNull] HtmlDataQualityCategoryOptions options)
        {
            if (options == null)
            {
                return(category.Name);
            }

            string aliasName = options.AliasName;

            return(StringUtils.IsNotEmpty(aliasName)
                                       ? aliasName
                                       : category.Name);
        }
        public void AddVerifiedCondition(
            [NotNull] XmlVerifiedQualityCondition xmlVerifiedCondition)
        {
            Assert.ArgumentNotNull(xmlVerifiedCondition, nameof(xmlVerifiedCondition));

            DataQualityCategory category = xmlVerifiedCondition.Category;

            if (category == null)
            {
                AddToUndefinedCategory(xmlVerifiedCondition);
            }
            else
            {
                AddToCategory(xmlVerifiedCondition, category);
            }
        }
        private static void AddSubCategories(
            [NotNull] IEnumerable <XmlDataQualityCategory> xmlCategories,
            [NotNull] DataQualityCategory parentCategory,
            [NotNull] IDictionary <XmlDataQualityCategory, DataQualityCategory> result)
        {
            foreach (XmlDataQualityCategory xmlCategory in xmlCategories)
            {
                DataQualityCategory category =
                    XmlDataQualityUtils.CreateDataQualityCategory(xmlCategory, parentCategory);

                result.Add(xmlCategory, category);

                if (xmlCategory.SubCategories != null)
                {
                    AddSubCategories(xmlCategory.SubCategories, category, result);
                }
            }
        }
        private void WriteCategory([NotNull] TextWriter writer,
                                   [NotNull] DataQualityCategory category,
                                   int level = 0)
        {
            writer.WriteLine(@"{0}> {1}", GetIndentationPadding(level), category.Name);

            foreach (QualitySpecification qspec in
                     Resolve <IQualitySpecificationRepository>().Get(category)
                     .OrderBy(qs => qs.Name))
            {
                WriteQualitySpecification(writer, qspec, level + 1);
            }

            foreach (DataQualityCategory child in category.SubCategories.OrderBy(c => c.Name))
            {
                WriteCategory(writer, child, level + 1);
            }
        }
        public void CanGetQualifiedNames()
        {
            var cat1     = new DataQualityCategory("1", "1");
            var cat2     = new DataQualityCategory("2", "2");
            var cat1_1   = new DataQualityCategory("1", "1.1");
            var cat1_2   = new DataQualityCategory("2", "1.2");
            var cat1_1_1 = new DataQualityCategory("1", "1.1.1");

            cat1.AddSubCategory(cat1_1);
            cat1.AddSubCategory(cat1_2);
            cat1_1.AddSubCategory(cat1_1_1);

            var qspecA = new QualitySpecification("A")
            {
                Category = cat1_1
            };
            var qspecB = new QualitySpecification("B")
            {
                Category = cat1_1
            };
            var qspecC = new QualitySpecification("C")
            {
                Category = cat1_1_1
            };
            var qspec1 = new QualitySpecification("X");
            var qspec2 = new QualitySpecification("Y");

            CreateSchema(cat1, cat2, cat1_1, cat1_2, cat1_1_1,
                         qspecA, qspecB, qspecC, qspec1, qspec2);

            UnitOfWork.NewTransaction(
                delegate
            {
                var qspecs = Resolve <IQualitySpecificationRepository>();

                Assert.AreEqual("1/1/A", GetQualifiedName(qspecs.Get("A")));
                Assert.AreEqual("1/1/B", GetQualifiedName(qspecs.Get("B")));
                Assert.AreEqual("1/1/1/C", GetQualifiedName(qspecs.Get("C")));
                Assert.AreEqual("X", GetQualifiedName(qspecs.Get("X")));
                Assert.AreEqual("Y", GetQualifiedName(qspecs.Get("Y")));
            });
        }
示例#23
0
        GetDatasetValuesByConditionId(
            [CanBeNull] DataQualityCategory category,
            [NotNull] ISession session)
        {
            var result = new Dictionary <int, List <DatasetTestParameterValue> >();

            IDictionary <int, HashSet <int> > dsParamsByQualityCondition =
                GetDatasetParameterIdsByQualityConditionId(session, category);

            if (dsParamsByQualityCondition.Count == 0)
            {
                return(result);
            }

            // flatmap to get the complete parameter id list
            var allDsParamIds = new HashSet <int>(
                dsParamsByQualityCondition.SelectMany(pair => pair.Value));

            Dictionary <int, DatasetTestParameterValue> datasetValuesById =
                GetDatasetTestParameterValuesById(session, allDsParamIds);

            foreach (KeyValuePair <int, HashSet <int> > pair in dsParamsByQualityCondition)
            {
                var values = new List <DatasetTestParameterValue>();

                foreach (int paramValId in pair.Value)
                {
                    DatasetTestParameterValue value;
                    if (datasetValuesById.TryGetValue(paramValId, out value))
                    {
                        values.Add(value);
                    }
                }

                result.Add(pair.Key, values);
            }

            return(result);
        }
示例#24
0
        GetDatasetParameterIdsByQualityConditionId(
            [NotNull] ISession session,
            [CanBeNull] DataQualityCategory category)
        {
            IQuery query = category == null
                                               ? session.CreateQuery("select qcon.Id, paramVal.Id " +
                                                                     "  from QualityCondition qcon " +
                                                                     " inner join qcon.ParameterValues paramVal " +
                                                                     " where qcon.Category is null " +
                                                                     "   and paramVal.class = DatasetTestParameterValue")
                                               : session.CreateQuery("select qcon.Id, paramVal.Id " +
                                                                     "  from QualityCondition qcon " +
                                                                     " inner join qcon.ParameterValues paramVal " +
                                                                     " where qcon.Category = :category " +
                                                                     "   and paramVal.class = DatasetTestParameterValue")
                           .SetEntity("category", category);

            IDictionary <int, HashSet <int> > result = new Dictionary <int, HashSet <int> >();

            foreach (object item in query.List())
            {
                var pair = (object[])item;

                var qconId     = (int)pair[0];
                var paramValId = (int)pair[1];

                HashSet <int> paramIds;
                if (!result.TryGetValue(qconId, out paramIds))
                {
                    paramIds = new HashSet <int>();
                    result.Add(qconId, paramIds);
                }

                paramIds.Add(paramValId);
            }

            return(result);
        }
示例#25
0
        public HtmlReportDataQualityCategory(
            [CanBeNull] DataQualityCategory category,
            [NotNull] IList <ExceptionCategory> exceptionCategories,
            [CanBeNull] HtmlDataQualityCategoryOptions options,
            [NotNull] HtmlReportDataQualityCategoryComparer categoryComparer,
            [NotNull] HtmlReportQualityConditionComparer qualityConditionComparer,
            [NotNull] HtmlReportIssueGroupComparer issueGroupComparer)
        {
            Assert.ArgumentNotNull(categoryComparer, nameof(categoryComparer));
            Assert.ArgumentNotNull(exceptionCategories, nameof(exceptionCategories));
            Assert.ArgumentNotNull(qualityConditionComparer, nameof(qualityConditionComparer));
            Assert.ArgumentNotNull(issueGroupComparer, nameof(issueGroupComparer));

            _category                 = category;
            _exceptionCategories      = exceptionCategories;
            _categoryComparer         = categoryComparer;
            _qualityConditionComparer = qualityConditionComparer;
            _issueGroupComparer       = issueGroupComparer;

            if (category == null)
            {
                IsUndefinedCategory = true;
                _uniqueName         = "<nocategory>";

                Name         = string.Empty;
                Abbreviation = string.Empty;
                Description  = string.Empty;
            }
            else
            {
                IsUndefinedCategory = false;
                _uniqueName         = category.GetQualifiedName("||");

                Name         = GetDisplayName(category, options);
                Abbreviation = category.Abbreviation ?? string.Empty;
                Description  = category.Description ?? string.Empty;
            }
        }
        GetCategoryMap([NotNull] XmlDataQualityDocument document)
        {
            var result = new Dictionary <XmlDataQualityCategory, DataQualityCategory>();

            if (document.Categories == null)
            {
                return(result);
            }

            foreach (XmlDataQualityCategory xmlCategory in document.Categories)
            {
                DataQualityCategory category =
                    XmlDataQualityUtils.CreateDataQualityCategory(xmlCategory, null);

                result.Add(xmlCategory, category);

                if (xmlCategory.SubCategories != null)
                {
                    AddSubCategories(xmlCategory.SubCategories, category, result);
                }
            }

            return(result);
        }
示例#27
0
 private static string GetCategoryKey([CanBeNull] DataQualityCategory category)
 {
     return(category?.Uuid ?? string.Empty);
 }
 private static string GetCategoryKey([CanBeNull] DataQualityCategory category)
 {
     return(category == null
                                ? string.Empty
                                : category.Uuid);
 }
        private QualitySpecification CreateQualitySpecificationCore(
            [NotNull] XmlDataQualityDocument document,
            [NotNull] string qualitySpecificationName,
            [NotNull] IEnumerable <DataSource> dataSources,
            bool ignoreConditionsForUnknownDatasets)
        {
            Assert.ArgumentNotNull(document, nameof(document));
            Assert.ArgumentNotNull(dataSources, nameof(dataSources));
            Assert.ArgumentCondition(document.GetAllQualitySpecifications().Any(),
                                     "The document must contain at least one quality specification");

            XmlDataQualityUtils.AssertUniqueWorkspaceIds(document);
            XmlDataQualityUtils.AssertUniqueTestDescriptorNames(document);
            XmlDataQualityUtils.AssertUniqueQualityConditionNames(document);
            XmlDataQualityUtils.AssertUniqueQualitySpecificationNames(document);
            XmlDataQualityUtils.AssertUniqueQualifiedCategoryNames(document);

            XmlDataQualityCategory  xmlSpecificationCategory;
            XmlQualitySpecification xmlQualitySpecification =
                XmlDataQualityUtils.FindXmlQualitySpecification(document,
                                                                qualitySpecificationName,
                                                                out xmlSpecificationCategory);

            Assert.ArgumentCondition(xmlQualitySpecification != null,
                                     "Specification '{0} not found in document",
                                     qualitySpecificationName);

            XmlDataQualityUtils.AssertUniqueElementNames(xmlQualitySpecification);

            IDictionary <XmlDataQualityCategory, DataQualityCategory> categoryMap =
                GetCategoryMap(document);

            IList <KeyValuePair <XmlQualityCondition, XmlDataQualityCategory> >
            referencedXmlConditionPairs =
                XmlDataQualityUtils.GetReferencedXmlQualityConditions(
                    document, new[] { xmlQualitySpecification })
                .ToList();

            IList <XmlQualityCondition> referencedXmlConditions =
                referencedXmlConditionPairs.Select(p => p.Key)
                .ToList();

            IList <XmlWorkspace> referencedXmlWorkspaces =
                XmlDataQualityUtils.GetReferencedWorkspaces(document,
                                                            referencedXmlConditions);

            IDictionary <string, Model> modelsByWorkspaceId = GetModelsByWorkspaceId(
                referencedXmlWorkspaces, dataSources, referencedXmlConditions);

            IDictionary <string, TestDescriptor> testDescriptorsByName =
                GetReferencedTestDescriptorsByName(referencedXmlConditions, document);

            var qualityConditions = new Dictionary <string, QualityCondition>(
                StringComparer.OrdinalIgnoreCase);

            Func <string, IList <Dataset> > getDatasetsByName = name => new List <Dataset>();

            foreach (
                KeyValuePair <XmlQualityCondition, XmlDataQualityCategory> pair in
                referencedXmlConditionPairs)
            {
                XmlQualityCondition    xmlCondition         = pair.Key;
                XmlDataQualityCategory xmlConditionCategory = pair.Value;

                DataQualityCategory conditionCategory = xmlConditionCategory != null
                                                                                ? categoryMap[xmlConditionCategory]
                                                                                : null;

                ICollection <XmlDatasetTestParameterValue> unknownDatasetParameters;
                QualityCondition qualityCondition = XmlDataQualityUtils.CreateQualityCondition(
                    xmlCondition,
                    testDescriptorsByName[xmlCondition.TestDescriptorName],
                    modelsByWorkspaceId,
                    getDatasetsByName,
                    conditionCategory,
                    ignoreConditionsForUnknownDatasets,
                    out unknownDatasetParameters);

                if (qualityCondition == null)
                {
                    Assert.True(ignoreConditionsForUnknownDatasets,
                                "ignoreConditionsForUnknownDatasets");
                    Assert.True(unknownDatasetParameters.Count > 0,
                                "Unexpected number of unknown datasets");

                    _msg.WarnFormat(
                        unknownDatasetParameters.Count == 1
                                                        ? "Quality condition '{0}' is ignored because the following dataset is not found: {1}"
                                                        : "Quality condition '{0}' is ignored because the following datasets are not found: {1}",
                        xmlCondition.Name,
                        XmlDataQualityUtils.ConcatenateUnknownDatasetNames(
                            unknownDatasetParameters,
                            modelsByWorkspaceId,
                            DataSource.AnonymousId));
                }
                else
                {
                    qualityConditions.Add(qualityCondition.Name, qualityCondition);
                }
            }

            DataQualityCategory specificationCategory =
                xmlSpecificationCategory != null
                                        ? categoryMap[xmlSpecificationCategory]
                                        : null;

            return(XmlDataQualityUtils.CreateQualitySpecification(
                       qualityConditions, xmlQualitySpecification, specificationCategory,
                       ignoreConditionsForUnknownDatasets));
        }
示例#30
0
        private static string GetCategoryName([NotNull] DatasetDependency dependency)
        {
            DataQualityCategory category = dependency.QualityCondition.Category;

            return(category == null ? null : category.GetQualifiedName());
        }