All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.kenshoo.pl.entity.internal.validators.FieldValidationAdapter Maven / Gradle / Ivy

Go to download

A Java persistence layer based on JOOQ for high performance and business flow support.

There is a newer version: 0.1.121-jooq-3.16.3
Show newest version
package com.kenshoo.pl.entity.internal.validators;

import com.kenshoo.pl.entity.*;
import com.kenshoo.pl.entity.spi.FieldValidator;

import java.util.stream.Stream;

public class FieldValidationAdapter, T> implements ChangeValidatorAdapter {

    private final FieldValidator validator;
    private final ValidationTrigger trigger;

    public FieldValidationAdapter(FieldValidator validator) {
        this.validator = validator;
        this.trigger = new FieldTrigger<>(validator.validatedField());
    }


    @Override
    public ValidationTrigger trigger() {
        return trigger;
    }

    @Override
    public SupportedChangeOperation getSupportedChangeOperation() {
        return SupportedChangeOperation.CREATE_AND_UPDATE;
    }

    @Override
    public Stream> fieldsToFetch() {
        return validator.fetchFields();
    }

    @Override
    public ValidationError validate(EntityChange entityChange, CurrentEntityState currentState, FinalEntityState finalState) {
        if (entityChange.isFieldChanged(validator.validatedField()) && validator.validateWhen().test(finalState)) {
            return validator.validate(entityChange.get(validator.validatedField()));
        } else {
            return null;
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy