| | 1 | | using Newtonsoft.Json.Linq; |
| | 2 | | using ValidateLib.ErrorsAndWarnings.Warnings; |
| | 3 | | using ValidateLib.Metadata.Descriptors; |
| | 4 | | using ValidateLib.Metadata.Properties; |
| | 5 | |
|
| | 6 | | namespace ValidateLib.Metadata.PropertyParsers.Schema |
| | 7 | | { |
| | 8 | | internal class PrimaryKeyPropertyParser : PropertyParserBase<SchemaDescriptor>, IPropertyParser<SchemaDescriptor> |
| | 9 | | { |
| 1 | 10 | | public PrimaryKeyPropertyParser(List<Warning> warnings, SchemaDescriptor descriptor) : base(warnings, descriptor |
| | 11 | | { |
| 1 | 12 | | } |
| | 13 | | public void ParseProperty(JProperty property) |
| | 14 | | { |
| 1 | 15 | | if (property.Value.Type == JTokenType.String) |
| 1 | 16 | | Descriptor.primaryKey = new ColumnReferenceProperty(new List<string>() { property.Value.ToString() }); |
| 1 | 17 | | else if (property.Value.Type == JTokenType.Array) |
| | 18 | | { |
| 1 | 19 | | List<string> primaryKeys = new List<string>(); |
| 1 | 20 | | foreach (var referencedColumnName in property.Value) |
| | 21 | | { |
| 1 | 22 | | if (referencedColumnName.Type != JTokenType.String) |
| | 23 | | { |
| 0 | 24 | | Warnings.Add(WarningFactory.GetColumnReferencePropertyWrongValueWarning(property.Value, property |
| 0 | 25 | | return; |
| | 26 | | } |
| | 27 | | else |
| 1 | 28 | | primaryKeys.Add(referencedColumnName.ToString()); |
| | 29 | |
|
| | 30 | | } |
| 1 | 31 | | if (primaryKeys.Count > 0) |
| 1 | 32 | | Descriptor.primaryKey = new ColumnReferenceProperty(primaryKeys); |
| | 33 | | else |
| 0 | 34 | | Warnings.Add(WarningFactory.GetColumnReferencePropertyWrongValueWarning(property.Value, property.Nam |
| | 35 | | } |
| | 36 | | else |
| 0 | 37 | | Warnings.Add(WarningFactory.GetColumnReferencePropertyWrongValueWarning(property.Value, property.Name, p |
| | 38 | |
|
| 0 | 39 | | } |
| | 40 | | } |
| | 41 | | } |