| | 1 | | using Newtonsoft.Json.Linq; |
| | 2 | | using ValidateLib.ErrorsAndWarnings.Warnings; |
| | 3 | | using ValidateLib.Metadata.Descriptors; |
| | 4 | | using ValidateLib.Metadata.Parsers; |
| | 5 | | using ValidateLib.Metadata.Validators; |
| | 6 | | using ValidateLib.UtilityClasses; |
| | 7 | |
|
| | 8 | | namespace ValidateLib.Metadata.ParsingAndValidation |
| | 9 | | { |
| | 10 | | public class MetadataParserValidator |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// Method which parses and validates metadata document containing TableGroup Descriptor and |
| | 14 | | /// returns object representing such descriptor. |
| | 15 | | /// </summary> |
| | 16 | | /// <param name="warnings">List where warnings are stored</param> |
| | 17 | | /// <param name="metadataUrlOrFilePath">Url or path to a metadata document</param> |
| | 18 | | /// <returns>Object representing TableGroup Descriptor</returns> |
| | 19 | | /// <exception cref="ArgumentException"></exception> |
| | 20 | | public static TableGroupDescriptor ProcessTableGroup(List<Warning> warnings, string metadataUrlOrFilePath) |
| | 21 | | { |
| 1 | 22 | | JObject? jObject = ObjectPropertyUtilityClass.GetDescriptor(metadataUrlOrFilePath); |
| 1 | 23 | | if (jObject is null) throw new ArgumentException(); |
| 1 | 24 | | var metadataLocation = IriUtilityClass.GetMetadataLocation(metadataUrlOrFilePath); |
| 1 | 25 | | var context = Context.GetContextFromJToken(jObject, warnings, metadataLocation!); |
| 1 | 26 | | TableGroupDescriptor.Normalize(jObject, context); |
| | 27 | |
|
| 1 | 28 | | var tableGroupDescriptor = new TableGroupDescriptor(); |
| 1 | 29 | | tableGroupDescriptor.context = context; |
| 1 | 30 | | var tableGroupDescriptorParser = new TableGroupParser(warnings, tableGroupDescriptor); |
| 1 | 31 | | tableGroupDescriptor = tableGroupDescriptorParser.ParseJToken(jObject, "tableGroup"); |
| 1 | 32 | | tableGroupDescriptor.PassInheritedProperties(); |
| 1 | 33 | | ApplyMetadataTGValidators(warnings, tableGroupDescriptor); |
| 1 | 34 | | return tableGroupDescriptor; |
| | 35 | | } |
| | 36 | |
|
| | 37 | |
|
| | 38 | | public static TableGroupDescriptor ProcessTableGroup(List<Warning> warnings, string metadataPathOrUrl, JObject j |
| | 39 | | { |
| 1 | 40 | | var metadataLocation = IriUtilityClass.GetMetadataLocation(metadataPathOrUrl); |
| 1 | 41 | | if (metadataLocation is null) |
| 0 | 42 | | throw new ArgumentException(); |
| 1 | 43 | | var context = Context.GetContextFromJToken(jObject, warnings, metadataLocation); |
| 1 | 44 | | TableGroupDescriptor.Normalize(jObject, context); |
| | 45 | |
|
| 1 | 46 | | var tableGroupDescriptor = new TableGroupDescriptor(); |
| 1 | 47 | | tableGroupDescriptor.context = context; |
| 1 | 48 | | var tableGroupDescriptorParser = new TableGroupParser(warnings, tableGroupDescriptor); |
| 1 | 49 | | tableGroupDescriptor = tableGroupDescriptorParser.ParseJToken(jObject, "tableGroup"); |
| 1 | 50 | | tableGroupDescriptor.PassInheritedProperties(); |
| 1 | 51 | | ApplyMetadataTGValidators(warnings, tableGroupDescriptor); |
| 1 | 52 | | return tableGroupDescriptor; |
| | 53 | | } |
| | 54 | |
|
| | 55 | | /// <summary> |
| | 56 | | /// Method which parses and validates metadata document containing Table Descriptor and |
| | 57 | | /// returns object representing such descriptor. |
| | 58 | | /// </summary> |
| | 59 | | /// <param name="warnings">List where warnings are stored</param> |
| | 60 | | /// <param name="metadataUrlOrFilePath">Url or path to a metadata document</param> |
| | 61 | | /// <returns>Object representing Table Descriptor</returns> |
| | 62 | | /// <exception cref="ArgumentException"></exception> |
| | 63 | | public static TableDescriptor ProcessTable(List<Warning> warnings, string metadataUrlOrFilePath) |
| | 64 | | { |
| 1 | 65 | | JObject? jObject = ObjectPropertyUtilityClass.GetDescriptor(metadataUrlOrFilePath); |
| 1 | 66 | | if (jObject is null) throw new ArgumentException(); |
| 1 | 67 | | var metadataLocation = IriUtilityClass.GetMetadataLocation(metadataUrlOrFilePath); |
| 1 | 68 | | var context = Context.GetContextFromJToken(jObject, warnings, metadataLocation!); |
| 1 | 69 | | TableDescriptor.Normalize(jObject, context); |
| | 70 | |
|
| 1 | 71 | | var tableDescriptor = new TableDescriptor(); |
| 1 | 72 | | tableDescriptor.context = context; |
| 1 | 73 | | var tableDescriptorParser = new TableParser(warnings, tableDescriptor); |
| 1 | 74 | | tableDescriptor = tableDescriptorParser.ParseJToken(jObject, "table"); |
| 1 | 75 | | tableDescriptor.PassInheritedProperties(); |
| 1 | 76 | | ApplyMetadataTableValidators(warnings, tableDescriptor); |
| 1 | 77 | | return tableDescriptor; |
| | 78 | | } |
| | 79 | |
|
| | 80 | | internal static TableDescriptor ProcessTableFromJObject(List<Warning> warnings, JObject metadataObject, string f |
| | 81 | | { |
| 1 | 82 | | if (metadataObject is null) throw new ArgumentException("Could not find the file"); |
| 1 | 83 | | var context = Context.GetContextFromJToken(metadataObject, warnings, filePath); |
| 1 | 84 | | TableDescriptor.Normalize(metadataObject, context); |
| | 85 | |
|
| 1 | 86 | | var tableDescriptor = new TableDescriptor(); |
| 1 | 87 | | tableDescriptor.context = context; |
| 1 | 88 | | var tableDescriptorParser = new TableParser(warnings, tableDescriptor); |
| 1 | 89 | | tableDescriptor = tableDescriptorParser.ParseJToken(metadataObject, "table"); |
| 1 | 90 | | tableDescriptor.PassInheritedProperties(); |
| 1 | 91 | | ApplyMetadataTableValidators(warnings, tableDescriptor); |
| 1 | 92 | | return tableDescriptor; |
| | 93 | | } |
| | 94 | |
|
| | 95 | | static void ApplyMetadataTGValidators(List<Warning> warnings, TableGroupDescriptor tableGroupDescriptor) |
| | 96 | | { |
| 1 | 97 | | ForeignKeyValidator foreignKeyValidator = new ForeignKeyValidator(); |
| 1 | 98 | | warnings.AddRange(foreignKeyValidator.Validate(tableGroupDescriptor)); |
| 1 | 99 | | TitlesValidator titlesValidator = new TitlesValidator(); |
| 1 | 100 | | warnings.AddRange(titlesValidator.Validate(tableGroupDescriptor)); |
| 1 | 101 | | } |
| | 102 | | static void ApplyMetadataTableValidators(List<Warning> warnings, TableDescriptor tableDescriptor) |
| | 103 | | { |
| 1 | 104 | | TitlesValidator titlesValidator = new TitlesValidator(); |
| 1 | 105 | | warnings.AddRange(titlesValidator.Validate(tableDescriptor)); |
| 1 | 106 | | } |
| | 107 | |
|
| | 108 | | } |
| | 109 | | } |