| | 1 | | using Newtonsoft.Json.Linq; |
| | 2 | | using ValidateLib.ErrorsAndWarnings.Errors; |
| | 3 | | using ValidateLib.ErrorsAndWarnings.Warnings; |
| | 4 | | using ValidateLib.Metadata.Descriptors.Interfaces; |
| | 5 | | using ValidateLib.Metadata.Parsers; |
| | 6 | | using ValidateLib.Metadata.Properties; |
| | 7 | | using ValidateLib.Metadata.Properties.AtomicProperties; |
| | 8 | | using ValidateLib.Metadata.PropertyParsers; |
| | 9 | | using ValidateLib.Metadata.PropertyParsers.DescriptorNS; |
| | 10 | | using ValidateLib.Metadata.PropertyParsers.Table; |
| | 11 | | using ValidateLib.TabularData.AnnotatedTabularDataModel; |
| | 12 | | using ValidateLib.TabularData.Parsing; |
| | 13 | | using ValidateLib.UtilityClasses; |
| | 14 | |
|
| | 15 | | namespace ValidateLib.Metadata.Descriptors |
| | 16 | | { |
| | 17 | | public class TableDescriptor : TopLevelObjectDescriptor, INormalize, Interfaces.IParsable<TableDescriptor>, ITypable |
| | 18 | | { |
| 1 | 19 | | public Table? table { get; set; } = null; |
| 1 | 20 | | new public static string getTypeForTypeProperty() => "Table"; |
| 1 | 21 | | public LinkProperty? url { get; set; } |
| 1 | 22 | | public AtomicPropertyBoolean? suppressOutput { get; set; } = new AtomicPropertyBoolean(false) { IsDefault = true |
| | 23 | |
|
| | 24 | | public Flags? _flags; |
| | 25 | | public FileWrapper? _fileWrapper; |
| | 26 | |
|
| | 27 | | new public List<Warning> CheckRequiredPropertiesPresent() |
| | 28 | | { |
| 1 | 29 | | List<Warning> errors = ((TopLevelObjectDescriptor)this).CheckRequiredPropertiesPresent(); |
| 1 | 30 | | if (url == null) ErrorFactory.ThrowRequiredPropertyMissingError("url", nameof(TableDescriptor)); |
| 1 | 31 | | return errors; |
| | 32 | | } |
| | 33 | |
|
| | 34 | | public static List<Warning> Normalize(JToken token, Context context, JProperty? property = null) |
| | 35 | | { |
| | 36 | |
|
| 1 | 37 | | List<Warning> errors = new List<Warning>(); |
| 1 | 38 | | if (token.Type != JTokenType.Object) return errors; |
| 1 | 39 | | foreach (JProperty jProperty in token) |
| | 40 | | { |
| 1 | 41 | | var results = NormalizeProperty(jProperty, context); |
| 1 | 42 | | MergeTwoList(errors, results); |
| | 43 | | } |
| 1 | 44 | | ContextUtilityClass.RemoveContextFromJToken(token); |
| 1 | 45 | | return errors; |
| | 46 | | } |
| | 47 | |
|
| | 48 | | new static public List<Warning> NormalizeProperty(JProperty property, Context context) |
| | 49 | | { |
| 1 | 50 | | List<Warning> errors = new List<Warning>(); |
| 1 | 51 | | if (CommonProperty.IsCommonProperty(property.Name)) return CommonProperty.Normalize(property.Value, context, |
| 1 | 52 | | switch (property.Name) |
| | 53 | | { |
| | 54 | | case "url": |
| 1 | 55 | | return LinkProperty.Normalize(property.Value, context, property); |
| | 56 | | case "suppressOutput": |
| 1 | 57 | | return errors; |
| | 58 | | default: |
| 1 | 59 | | return TopLevelObjectDescriptor.NormalizeProperty(property, context); |
| | 60 | |
|
| | 61 | | } |
| | 62 | | } |
| | 63 | |
|
| | 64 | |
|
| 1 | 65 | | static public IParser<TableDescriptor> GetParser(List<Warning> warnings, TableDescriptor? descriptor = null) => |
| | 66 | |
|
| | 67 | | new public IPropertyParserBase? GetPropertyParser(JProperty property, List<Warning> warnings) |
| | 68 | | { |
| 1 | 69 | | string propertyName = property.Name; |
| 1 | 70 | | if (CommonProperty.IsCommonProperty(propertyName)) return ((CommonPropertiesDescriptor)this).GetPropertyPars |
| | 71 | | switch (propertyName) |
| | 72 | | { |
| | 73 | | case "url": |
| 1 | 74 | | return new UrlPropertyParser(warnings, this); |
| | 75 | | case "suppressOutput": |
| 1 | 76 | | return new SuppresOutputPropertyParser(warnings, this); |
| | 77 | | case "@type": |
| 1 | 78 | | return new TypePropertyParser<TableDescriptor>(warnings, this); |
| | 79 | | default: |
| 1 | 80 | | return ((TopLevelObjectDescriptor)this).GetPropertyParser(property, warnings); |
| | 81 | |
|
| | 82 | | } |
| | 83 | | } |
| | 84 | |
|
| | 85 | | public override void PassInheritedProperties() |
| | 86 | | { |
| 1 | 87 | | if (tableSchema is not null) |
| 1 | 88 | | tableSchema._value!.ProcessPassedInheritedProperties(this); |
| | 89 | |
|
| 1 | 90 | | } |
| | 91 | | } |
| | 92 | | } |