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

com.kenshoo.pl.entity.internal.DefaultFieldValueEnricher 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;

import com.kenshoo.pl.entity.*;
import com.kenshoo.pl.entity.spi.PostFetchCommandEnricher;
import com.kenshoo.pl.entity.spi.helpers.CommandsFieldMatcher;

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

/**
 * Created by yuvalr on 2/1/16.
 */
public class DefaultFieldValueEnricher, T> implements PostFetchCommandEnricher {

    private final EntityField field;
    private final T defaultValue;

    public DefaultFieldValueEnricher(EntityField field, T defaultValue) {
        this.field = field;
        this.defaultValue = defaultValue;
    }

    @Override
    public void enrich(Collection> changeEntityCommands, ChangeOperation changeOperation, ChangeContext changeContext) {
        changeEntityCommands.stream()
        .filter(command -> !command.isFieldChanged(field))
        .forEach(command -> command.set(field, defaultValue));
    }

    @Override
    public Stream> fieldsToEnrich() {
        return Stream.of(field);
    }

    @Override
    public boolean shouldRun(Collection> changeEntityCommands) {
        return CommandsFieldMatcher.isAnyFieldMissingInAnyCommand(changeEntityCommands, field);
    }

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy