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

com.kenshoo.pl.entity.spi.FieldComplexValidator 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.spi;

import com.kenshoo.pl.entity.*;

import java.util.function.Predicate;
import java.util.stream.Stream;

/**
 * A validator that checks one field and uses parent entity fields for the verification.
 *
 * @param  entity type
 * @param  data type of the field being validated
 */
public interface FieldComplexValidator, T> extends ChangeValidator {

    /**
     * @return the field validated by this validator
     */
    EntityField validatedField();

    /**
     * Called by the framework to validate the value. The implementation can query the entity only for
     * the fields it has declared in {@link #fetchFields()}.
     *
     * @param fieldValue new value of the field
     * @param currentState existing entity
     *
     * @return a validation error if any, null if none
     */
    ValidationError validate(T fieldValue, CurrentEntityState currentState);

    /**
     * @return a list of fields to fetch. Can contain only parent entities fields.
     */
    Stream> fetchFields();

    /**
     * The predicate is evaluated on the final state of the entity See {@link FinalEntityState}.
     * @return a predicate indicating when the field should be validated. It will be evaluated together with {@link #fetchFields()},
     * which means that all the fields appearing in the predicate must also be included in the fields to fetch or be required
     * for create operation
     */
    default Predicate validateWhen() {
        return e -> true;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy