| | 1 | | using ValidateLib.Metadata.Descriptors; |
| | 2 | | using ValidateLib.Metadata.Embedded; |
| | 3 | | using ValidateLib.Metadata.Properties; |
| | 4 | | using ValidateLib.TabularData.Parsing; |
| | 5 | | using ValidateLib.UtilityClasses; |
| | 6 | |
|
| | 7 | | namespace ValidateLib.Metadata.Unification |
| | 8 | | { |
| | 9 | | /// <summary> |
| | 10 | | /// Unifies particular descriptors before proceeding to the stage of |
| | 11 | | /// parsing and validating tabular data files. We normalize all types of different |
| | 12 | | /// validation beginnings to one common type - when we have a table group descriptor present. |
| | 13 | | /// Also create a file wrappers for every table so we do not have to concern ourselves with |
| | 14 | | /// problems with the remote files. |
| | 15 | | /// </summary> |
| | 16 | | internal class MetadataUnifier |
| | 17 | | { |
| | 18 | | /// <summary> |
| | 19 | | /// Transform the case when we begin from the table to the table group case. |
| | 20 | | /// We simple create table group description containing one original table descriptor. |
| | 21 | | /// </summary> |
| | 22 | | /// <param name="tableDescriptor"> Original table description passed by user and extracted from metadata file.</ |
| | 23 | | /// <returns> Unified table group descriptor. The table group descriptor contains only one table in tables prope |
| | 24 | | /// and that is <paramref name="tableDescriptor"/>. |
| | 25 | | /// </returns> |
| | 26 | | public static TableGroupDescriptor UnifyTable(TableDescriptor tableDescriptor) |
| | 27 | | { |
| 1 | 28 | | var fw = new FileWrapper(tableDescriptor.url!._value!); |
| 1 | 29 | | var tableGroupDescriptor = new TableGroupDescriptor(); |
| 1 | 30 | | tableGroupDescriptor.tables = new ArrayProperty<TableDescriptor>(new List<TableDescriptor>() { tableDescript |
| 1 | 31 | | tableDescriptor._fileWrapper = fw; |
| 1 | 32 | | return tableGroupDescriptor; |
| | 33 | | } |
| | 34 | | /// <summary> |
| | 35 | | /// Unifies case when we have table group descriptor extracted from metadata |
| | 36 | | /// file. |
| | 37 | | /// </summary> |
| | 38 | | /// <param name="tableGroupDescriptor"></param> |
| | 39 | | /// <returns></returns> |
| | 40 | |
|
| | 41 | | public static TableGroupDescriptor UnifyTableGroup(TableGroupDescriptor tableGroupDescriptor) |
| | 42 | | { |
| 1 | 43 | | foreach (var table in tableGroupDescriptor.tables!._value!) |
| | 44 | | { |
| 1 | 45 | | table._fileWrapper = new FileWrapper(table.url!._value!); |
| | 46 | | } |
| 1 | 47 | | return tableGroupDescriptor; |
| | 48 | | } |
| | 49 | |
|
| | 50 | | /// <summary> |
| | 51 | | /// Unifies case when we validate table without metadata and embedded metadata |
| | 52 | | /// have to be used instead. |
| | 53 | | /// </summary> |
| | 54 | | /// <param name="fileIRI"></param> |
| | 55 | | /// <returns></returns> |
| | 56 | | public static TableGroupDescriptor UnifyTableWithoutMetadata(string fileIRI) |
| | 57 | | { |
| 1 | 58 | | var fw = new FileWrapper(fileIRI); |
| 1 | 59 | | var defaulDialect = new DialectDescriptor(); |
| 1 | 60 | | var flags = FlagsCreator.ExtractFlagsFromDialectDescriptor(defaulDialect); |
| 1 | 61 | | EmbeddedMetadataExtractor metadataExtrator = new EmbeddedMetadataExtractor(flags); |
| 1 | 62 | | using (var fs = fw.OpenNewFileStream()) |
| | 63 | | { |
| 1 | 64 | | var tabularDataDescriptorEmbedded = metadataExtrator.extractEmbeddedMetadataTableDescriptor(fs, defaulDi |
| 1 | 65 | | tabularDataDescriptorEmbedded._fileWrapper = fw; |
| | 66 | |
|
| 1 | 67 | | var tableGroupDescriptor = new TableGroupDescriptor(); |
| 1 | 68 | | tableGroupDescriptor.tables = new ArrayProperty<TableDescriptor>(new List<TableDescriptor>() { tabularDa |
| 1 | 69 | | return tableGroupDescriptor; |
| | 70 | | } |
| | 71 | |
|
| 1 | 72 | | } |
| | 73 | | } |
| | 74 | | } |