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

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

import com.google.common.collect.Lists;
import com.kenshoo.pl.entity.ChangeContext;
import com.kenshoo.pl.entity.ChangeEntityCommand;
import com.kenshoo.pl.entity.ChangeOperation;
import com.kenshoo.pl.entity.EntityChange;
import com.kenshoo.pl.entity.EntityField;
import com.kenshoo.pl.entity.EntityType;
import com.kenshoo.pl.entity.spi.ChangesValidator;
import com.kenshoo.pl.entity.spi.CurrentStateConsumer;

import java.util.Collection;
import java.util.List;
import java.util.stream.Stream;

public class CompoundChangesValidator> implements ChangesValidator {

    private final List> changesValidators = Lists.newArrayList();

    public void register(ChangesValidator changesValidator) {
        changesValidators.add(changesValidator);
    }

    @Override
    public void validate(Collection> entityChanges, ChangeOperation changeOperation, ChangeContext changeContext) {
        changesValidators.stream().
                filter(CurrentStateConsumer.supporting(changeOperation)).
                    forEach(validator -> validator.validate(entityChanges, changeOperation, changeContext));
    }

    @Override
    public Stream> requiredFields(Collection> fieldsToUpdate, ChangeOperation changeOperation) {
        return changesValidators.stream()
                .filter(CurrentStateConsumer.supporting(changeOperation))
                .flatMap(changesValidator -> changesValidator.requiredFields(fieldsToUpdate, changeOperation));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy