< Summary

Information
Class: ValidateLib.Metadata.Validators.TitlesValidator
Assembly: validatelib.dll
File(s): C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\Metadata\Validators\TitlesValidator.cs
Line coverage
100%
Covered lines: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 84
Line coverage: 100%
Branch coverage
N/A
Covered branches: 0
Total branches: 0
Branch coverage: N/A
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Metrics

File(s)

C:\skola_karlovka\RP\code\csv-validator\CSV_Validator\ValidateLib\Metadata\Validators\TitlesValidator.cs

#LineLine coverage
 1using ValidateLib.ErrorsAndWarnings.Errors;
 2using ValidateLib.ErrorsAndWarnings.Warnings;
 3using ValidateLib.Metadata.Descriptors;
 4using ValidateLib.Metadata.Properties;
 5using ValidateLib.UtilityClasses;
 6
 7namespace ValidateLib.Metadata.Validators
 8{
 9    public class TitlesValidator : IMValidator<TableGroupDescriptor>, IMValidator<TableDescriptor>
 10    {
 11        public List<Warning> Validate(TableGroupDescriptor tableGroupDescriptor)
 12        {
 113            List<Warning> warnings = new List<Warning>();
 14
 115            if (tableGroupDescriptor is not null && tableGroupDescriptor.tables is not null)
 16            {
 117                foreach (var table in tableGroupDescriptor.tables._value!)
 18                {
 119                    if (table.tableSchema is not null)
 20                    {
 121                        ProcessOneScheme(table.tableSchema._value!);
 22                    }
 23                }
 24            }
 25
 126            return warnings;
 27        }
 28
 29        public List<Warning> Validate(TableDescriptor table)
 30        {
 131            List<Warning> warnings = new List<Warning>();
 132            if (table.tableSchema is not null)
 33            {
 134                ProcessOneScheme(table.tableSchema._value!);
 35            }
 136            return warnings;
 37        }
 38
 39        void ProcessOneScheme(SchemaDescriptor schemaDescriptor)
 40        {
 141            if (AreDesiredPropertiesPresent(schemaDescriptor))
 42            {
 143                foreach (var column in schemaDescriptor!.columns!._value!)
 44                {
 145                    if (column.titles is not null)
 46                    {
 147                        if (
 148                            !IsLangCompatibleWithTitle(
 149                            LanguageUtilityClass.GetMostGeneralLanguagePart(schemaDescriptor.lang!._value!)
 150                            , column.titles)
 151                            )
 52                        {
 153                            ErrorFactory.ThrowTitleNotCompatibleWithLangError(column.titles._value!.FirstOrDefault().Val
 54                        }
 55                    }
 56                }
 57            }
 158        }
 59        bool AreDesiredPropertiesPresent(SchemaDescriptor schemaDescriptor)
 60        {
 161            return schemaDescriptor is not null &&
 162                schemaDescriptor.lang is not null &&
 163                schemaDescriptor.columns is not null &&
 164                schemaDescriptor.columns._value is not null
 165                ;
 66        }
 67
 68        bool IsLangCompatibleWithTitle(string lang, NaturalLanguageProperty titles)
 69        {
 170            if (lang == MetadataConstants.DefaultLang)
 171                return true;
 172            foreach (var kvp in titles._value!)
 73            {
 174                var generalKeyPart = LanguageUtilityClass.GetMostGeneralLanguagePart(kvp.Key);
 175                if (generalKeyPart == lang || kvp.Key == MetadataConstants.DefaultLang)
 76                {
 177                    return true;
 78                }
 79            }
 80
 181            return false;
 182        }
 83    }
 84}