<commit_before>package org.pdxfinder.dataloaders.updog.tablevalidation;

import org.apache.commons.collections4.CollectionUtils;
import org.pdxfinder.dataloaders.updog.tablevalidation.error.BrokenRelationErrorCreator;
import org.pdxfinder.dataloaders.updog.tablevalidation.error.DuplicateValueErrorCreator;
import org.pdxfinder.dataloaders.updog.tablevalidation.error.EmptyValueErrorCreator;
import org.pdxfinder.dataloaders.updog.tablevalidation.error.MissingColumnErrorCreator;
import org.pdxfinder.dataloaders.updog.tablevalidation.error.MissingTableErrorCreator;
import org.pdxfinder.dataloaders.updog.tablevalidation.error.ValidationError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import tech.tablesaw.api.Table;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
public class Validator {

    private static final Logger log = LoggerFactory.getLogger(Validator.class);
    private List<ValidationError> validationErrors;
    private MissingTableErrorCreator missingTableErrorCreator;

    public Validator(
        MissingTableErrorCreator missingTableErrorCreator
    ) {
        this.missingTableErrorCreator = missingTableErrorCreator;
        this.validationErrors = new ArrayList<>();
    }

    public List<ValidationError> validate(
        Map<String, Table> tableSet,
        TableSetSpecification tableSetSpecification
    ) {
        checkRequiredTablesPresent(tableSet, tableSetSpecification);
        if (CollectionUtils.isNotEmpty(validationErrors)) {
            log.error(
                "Not all required tables where present for {}. Aborting further validation",
                tableSetSpecification.getProvider());
            return validationErrors;
        }
        checkRequiredColumnsPresent(tableSet, tableSetSpecification);
        checkAllNonEmptyValuesPresent(tableSet, tableSetSpecification);
        checkAllUniqueColumnsForDuplicates(tableSet, tableSetSpecification);
        checkRelationsValid(tableSet, tableSetSpecification);

        return validationErrors;
    }

    private void checkRequiredTablesPresent(
        Map<String, Table> tableSet,
        TableSetSpecification tableSetSpecification
    ) {
        if (tableSetSpecification.hasRequiredColumns())
            validationErrors.addAll(missingTableErrorCreator.generateErrors(tableSet, tableSetSpecification));
    }

    private void checkRequiredColumnsPresent(
        Map<String, Table> tableSet,
        TableSetSpecification tableSetSpecification
    ) {
        if (tableSetSpecification.hasRequiredColumns())
            validationErrors.addAll(new MissingColumnErrorCreator().generateErrors(tableSet, tableSetSpecification));
    }<commit_msg>Disable validation due to exception<commit_after>package org.pdxfinder.dataloaders.updog.tablevalidation;

import org.apache.commons.collections4.CollectionUtils;
import org.pdxfinder.dataloaders.updog.tablevalidation.error.BrokenRelationErrorCreator;
import org.pdxfinder.dataloaders.updog.tablevalidation.error.DuplicateValueErrorCreator;
import org.pdxfinder.dataloaders.updog.tablevalidation.error.EmptyValueErrorCreator;
import org.pdxfinder.dataloaders.updog.tablevalidation.error.MissingColumnErrorCreator;
import org.pdxfinder.dataloaders.updog.tablevalidation.error.MissingTableErrorCreator;
import org.pdxfinder.dataloaders.updog.tablevalidation.error.ValidationError;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import tech.tablesaw.api.Table;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Component
public class Validator {

    private static final Logger log = LoggerFactory.getLogger(Validator.class);
    private List<ValidationError> validationErrors;
    private MissingTableErrorCreator missingTableErrorCreator;

    public Validator(
        MissingTableErrorCreator missingTableErrorCreator
    ) {
        this.missingTableErrorCreator = missingTableErrorCreator;
        this.validationErrors = new ArrayList<>();
    }

    public List<ValidationError> validate(
        Map<String, Table> tableSet,
        TableSetSpecification tableSetSpecification
    ) {
        checkRequiredTablesPresent(tableSet, tableSetSpecification);
        if (CollectionUtils.isNotEmpty(validationErrors)) {
            log.error(
                "Not all required tables where present for {}. Aborting further validation",
                tableSetSpecification.getProvider());
            return validationErrors;
        }
        checkRequiredColumnsPresent(tableSet, tableSetSpecification);
        checkAllNonEmptyValuesPresent(tableSet, tableSetSpecification);
        checkAllUniqueColumnsForDuplicates(tableSet, tableSetSpecification);
        //checkRelationsValid(tableSet, tableSetSpecification);

        return validationErrors;
    }

    private void checkRequiredTablesPresent(
        Map<String, Table> tableSet,
        TableSetSpecification tableSetSpecification
    ) {
        if (tableSetSpecification.hasRequiredColumns())
            validationErrors.addAll(missingTableErrorCreator.generateErrors(tableSet, tableSetSpecification));
    }

    private void checkRequiredColumnsPresent(
        Map<String, Table> tableSet,
        TableSetSpecification tableSetSpecification
    ) {
        if (tableSetSpecification.hasRequiredColumns())
            validationErrors.addAll(new MissingColumnErrorCreator().generateErrors(tableSet, tableSetSpecification));
    }
{'fraction_non_alphanumeric': 0.07248467363865849, 'fraction_numerical': 0.0010818608005769925, 'mean_word_length': 4.411707317073171, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4673863', 'n_tokens_mistral': 1454, 'n_tokens_neox': 1426, 'n_words': 236}