private static XmlDataQualityDocument ReadXmlDocument( [NotNull] string xml, [NotNull] out IList <XmlQualitySpecification> qualitySpecifications) { Assert.ArgumentNotNullOrEmpty(xml, nameof(xml)); XmlDataQualityDocument document = XmlDataQualityUtils.DeserializeXml(xml); Assert.ArgumentCondition(document.GetAllQualitySpecifications().Any(), "The document does not contain any quality specifications"); XmlDataQualityUtils.AssertUniqueQualitySpecificationNames(document); XmlDataQualityUtils.AssertUniqueQualityConditionNames(document); XmlDataQualityUtils.AssertUniqueTestDescriptorNames(document); qualitySpecifications = document.GetAllQualitySpecifications() .Select(p => p.Key) .Where(qs => qs.Elements.Count > 0) .ToList(); return(document); }
public QualitySpecification CreateQualitySpecification( [NotNull] XmlDataQualityDocument document, [NotNull] IEnumerable <DataSource> dataSources, bool ignoreConditionsForUnknownDatasets) { KeyValuePair <XmlQualitySpecification, XmlDataQualityCategory> keyValuePair = document.GetAllQualitySpecifications().Single(); string singleSpecificationName = Assert.NotNullOrEmpty(keyValuePair.Key.Name); return(CreateQualitySpecification(document, singleSpecificationName, dataSources, ignoreConditionsForUnknownDatasets)); }
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)); }