| | 1 | | using ValidateLib.ErrorsAndWarnings.Warnings; |
| | 2 | | using ValidateLib.Metadata.Descriptors; |
| | 3 | |
|
| | 4 | | namespace ValidateLib.Metadata.Validators |
| | 5 | | { |
| | 6 | | internal class RowTitlesValidator : IMValidator<SchemaDescriptor> |
| | 7 | | { |
| | 8 | | public List<Warning> Validate(SchemaDescriptor schemaDescriptor) |
| | 9 | | { |
| 1 | 10 | | List<Warning> warnings = new List<Warning>(); |
| 1 | 11 | | if (schemaDescriptor.rowTitles is not null) |
| | 12 | | { |
| 0 | 13 | | var primaryKeyDescriptor = schemaDescriptor.rowTitles._value; |
| 0 | 14 | | bool validPrimaryKeyDescriptor = true; |
| 0 | 15 | | string? nonExistingColumnName = null; |
| 0 | 16 | | foreach (var primaryKeyColumnName in primaryKeyDescriptor!) |
| | 17 | | { |
| 0 | 18 | | if (!DoesReferencedColumnExist(schemaDescriptor, primaryKeyColumnName)) |
| | 19 | | { |
| 0 | 20 | | nonExistingColumnName = primaryKeyColumnName; |
| 0 | 21 | | validPrimaryKeyDescriptor = false; |
| | 22 | | } |
| | 23 | | } |
| 0 | 24 | | if (!validPrimaryKeyDescriptor) |
| | 25 | | { |
| 0 | 26 | | warnings.Add(WarningFactory.GetReferencedCOlumnDoesNotExistWarning("rowTitles", nonExistingColumnNam |
| 0 | 27 | | schemaDescriptor.rowTitles = null; |
| | 28 | | } |
| | 29 | | } |
| 1 | 30 | | return warnings; |
| | 31 | | } |
| | 32 | |
|
| | 33 | | static bool DoesReferencedColumnExist(SchemaDescriptor schemaDescriptor, string referencedColumnName) |
| | 34 | | { |
| 0 | 35 | | if (schemaDescriptor.columns is not null) |
| | 36 | | { |
| 0 | 37 | | foreach (var column in schemaDescriptor.columns._value!) |
| | 38 | | { |
| 0 | 39 | | if (column.name is null) continue; |
| 0 | 40 | | else if (column.name._value == referencedColumnName) return true; |
| | 41 | | } |
| 0 | 42 | | return false; |
| | 43 | | } |
| 0 | 44 | | else return false; |
| 0 | 45 | | } |
| | 46 | | } |
| | 47 | | } |