| | | 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.PropertyParsers; |
| | | 8 | | using ValidateLib.Metadata.PropertyParsers.Reference; |
| | | 9 | | |
| | | 10 | | namespace ValidateLib.Metadata.Descriptors |
| | | 11 | | { |
| | | 12 | | public class ReferenceDescriptor : DescriptorBase, INormalize, Interfaces.IParsable<ReferenceDescriptor>, IRequiredP |
| | | 13 | | { |
| | 1 | 14 | | public LinkProperty? resource { get; set; } |
| | 1 | 15 | | public LinkProperty? schemaReference { get; set; } |
| | 1 | 16 | | public ColumnReferenceProperty? columnReference { get; set; } |
| | | 17 | | |
| | | 18 | | public static List<Warning> Normalize(JToken token, Context context, JProperty? property = null) |
| | | 19 | | { |
| | 1 | 20 | | List<Warning> errors = new List<Warning>(); |
| | 1 | 21 | | if (token.Type != JTokenType.Object) return errors; |
| | 1 | 22 | | foreach (JProperty jProperty in token) |
| | | 23 | | { |
| | 1 | 24 | | var results = NormalizeProperty(jProperty, context); |
| | 1 | 25 | | Descriptor.MergeTwoList(errors, results); |
| | | 26 | | } |
| | 1 | 27 | | return errors; |
| | | 28 | | } |
| | | 29 | | |
| | | 30 | | static protected List<Warning> NormalizeProperty(JProperty property, Context context) |
| | | 31 | | { |
| | 1 | 32 | | List<Warning> warnings = new List<Warning>(); |
| | 1 | 33 | | switch (property.Name) |
| | | 34 | | { |
| | | 35 | | case "resource": |
| | | 36 | | case "schemaReference": |
| | 1 | 37 | | return LinkProperty.Normalize(property.Value, context, property); |
| | | 38 | | case "columnReference": |
| | 1 | 39 | | return warnings; |
| | | 40 | | default: |
| | 1 | 41 | | warnings.Add(WarningFactory.GetUnknownPropertyWarning(property)); |
| | 1 | 42 | | return warnings; |
| | | 43 | | |
| | | 44 | | } |
| | | 45 | | } |
| | | 46 | | |
| | 0 | 47 | | public static IParser<ReferenceDescriptor> GetParser(List<Warning> warnings, ReferenceDescriptor? descriptor = n |
| | | 48 | | |
| | | 49 | | public IPropertyParserBase? GetPropertyParser(JProperty property, List<Warning> warnings) |
| | | 50 | | { |
| | | 51 | | |
| | 1 | 52 | | switch (property.Name) |
| | | 53 | | { |
| | | 54 | | case "resource": |
| | 1 | 55 | | return new ResourcePropertyParser(warnings, this); |
| | | 56 | | case "schemaReference": |
| | 1 | 57 | | return new SchemaReferencePropertyParser(warnings, this); |
| | | 58 | | case "columnReference": |
| | 1 | 59 | | return new ColumnReferencePropertyParser(warnings, this); |
| | | 60 | | default: |
| | 1 | 61 | | return null; |
| | | 62 | | } |
| | | 63 | | } |
| | | 64 | | |
| | | 65 | | public List<Warning> CheckRequiredPropertiesPresent() |
| | | 66 | | { |
| | 1 | 67 | | if (columnReference is null) ErrorFactory.ThrowRequiredPropertyMissingError("columnReference", nameof(Refere |
| | 1 | 68 | | if (resource is null && schemaReference is null) ErrorFactory.ThrowRequiredPropertyMissingError("Missing bot |
| | 1 | 69 | | return new List<Warning>(); |
| | | 70 | | } |
| | | 71 | | } |
| | | 72 | | } |