| | 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.Transformation; |
| | 11 | |
|
| | 12 | | namespace ValidateLib.Metadata.Descriptors |
| | 13 | | { |
| | 14 | | public class TransformationDescriptor : CommonPropertiesDescriptor, INormalize, Interfaces.IParsable<TransformationD |
| | 15 | | { |
| 0 | 16 | | public LinkProperty? url { get; set; } |
| 1 | 17 | | public LinkProperty? scriptFormat { get; set; } |
| 0 | 18 | | public LinkProperty? targetFormat { get; set; } |
| 1 | 19 | | public AtomicPropertyString? source { get; set; } = new AtomicPropertyString(null) { IsDefault = true }; |
| 1 | 20 | | public NaturalLanguageProperty? titles { get; set; } |
| 1 | 21 | | new public static string getTypeForTypeProperty() => "Template"; |
| | 22 | |
|
| | 23 | | public List<Warning> CheckRequiredPropertiesPresent() |
| | 24 | | { |
| 0 | 25 | | List<Warning> warnings = new List<Warning>(); |
| 0 | 26 | | if (url == null) |
| | 27 | | { |
| 0 | 28 | | ErrorFactory.ThrowRequiredPropertyMissingError(nameof(url), nameof(TransformationDescriptor)); |
| | 29 | | } |
| 0 | 30 | | if (scriptFormat == null) |
| | 31 | | { |
| 0 | 32 | | ErrorFactory.ThrowRequiredPropertyMissingError(nameof(scriptFormat), nameof(TransformationDescriptor)); |
| | 33 | | } |
| 0 | 34 | | if (targetFormat == null) |
| | 35 | | { |
| 0 | 36 | | ErrorFactory.ThrowRequiredPropertyMissingError(nameof(scriptFormat), nameof(TransformationDescriptor)); |
| | 37 | |
|
| | 38 | | } |
| 0 | 39 | | return warnings; |
| | 40 | |
|
| | 41 | | } |
| | 42 | |
|
| | 43 | | public static List<Warning> Normalize(JToken token, Context context, JProperty? property = null) |
| | 44 | | { |
| | 45 | |
|
| 1 | 46 | | List<Warning> errors = new List<Warning>(); |
| 1 | 47 | | if (token.Type != JTokenType.Object) return errors; |
| 1 | 48 | | foreach (JProperty jProperty in token) |
| | 49 | | { |
| 1 | 50 | | var results = NormalizeProperty(jProperty, context); |
| 1 | 51 | | MergeTwoList(errors, results); |
| | 52 | | } |
| 1 | 53 | | return errors; |
| | 54 | | } |
| | 55 | |
|
| | 56 | | new static List<Warning> NormalizeProperty(JProperty property, Context context) |
| | 57 | | { |
| 1 | 58 | | List<Warning> errors = new List<Warning>(); |
| 1 | 59 | | if (CommonProperty.IsCommonProperty(property.Name)) CommonProperty.Normalize(property.Value, context, proper |
| 1 | 60 | | switch (property.Name) |
| | 61 | | { |
| | 62 | | case "url": |
| | 63 | | case "scriptFormat": |
| | 64 | | case "targetFormat": |
| 1 | 65 | | return LinkProperty.Normalize(property.Value, context, property); |
| | 66 | | case "source": |
| 1 | 67 | | return errors; |
| | 68 | | case "titles": |
| 1 | 69 | | return NaturalLanguageProperty.Normalize(property.Value, context, property); |
| | 70 | | default: |
| 1 | 71 | | return ContextDescriptor.NormalizeProperty(property, context); |
| | 72 | | } |
| | 73 | | } |
| | 74 | |
|
| | 75 | | new public IPropertyParserBase? GetPropertyParser(JProperty property, List<Warning> warnings) |
| | 76 | | { |
| 1 | 77 | | string propertyName = property.Name; |
| 1 | 78 | | if (CommonProperty.IsCommonProperty(propertyName)) ((CommonPropertiesDescriptor)this).GetPropertyParser(prop |
| | 79 | | switch (propertyName) |
| | 80 | | { |
| | 81 | | case "url": |
| 1 | 82 | | return new UrlPropertyParser(warnings, this); |
| | 83 | | case "scriptFormat": |
| 1 | 84 | | return new ScriptFormatPropertyParser(warnings, this); |
| | 85 | | case "targetFormat": |
| 1 | 86 | | return new TargetFormatPropertyParser(warnings, this); |
| | 87 | | case "source": |
| 1 | 88 | | return new SourcePropertyParser(warnings, this); |
| | 89 | | case "titles": |
| 1 | 90 | | return new TitlesPropertyParser(warnings, this); |
| | 91 | | case "@type": |
| 1 | 92 | | return new TypePropertyParser<TransformationDescriptor>(warnings, this); |
| | 93 | | default: |
| 1 | 94 | | return ((Descriptor)this).GetPropertyParser(property, warnings); |
| | 95 | | } |
| | 96 | | } |
| | 97 | |
|
| 1 | 98 | | public static IParser<TransformationDescriptor> GetParser(List<Warning> warnings, TransformationDescriptor? desc |
| | 99 | | } |
| | 100 | | } |