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

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

import com.google.common.annotations.VisibleForTesting;
import com.kenshoo.pl.entity.CurrentEntityState;
import com.kenshoo.pl.entity.EntityType;
import com.kenshoo.pl.entity.FinalEntityState;
import com.kenshoo.pl.entity.audit.FieldAuditRecord;

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

import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;
import static org.jooq.lambda.Seq.seq;

public class AuditFieldChangesGenerator> {

    private final Collection> onChangeFields;
    private final AuditFieldChangeGenerator singleGenerator;

    public AuditFieldChangesGenerator(final Stream> onChangeFields) {
        this(onChangeFields, new AuditFieldChangeGenerator());
    }

    @VisibleForTesting
    AuditFieldChangesGenerator(final Stream> onChangeFields,
                               final AuditFieldChangeGenerator singleGenerator) {
        requireNonNull(onChangeFields, "onChangeFields must not be null (can be empty)");
        this.onChangeFields = onChangeFields.collect(toList());
        this.singleGenerator = singleGenerator;
    }

    Collection generate(final CurrentEntityState currentState,
                                          final FinalEntityState finalState) {
        return seq(onChangeFields)
            .map(field -> singleGenerator.generate(currentState, finalState, field))
            .filter(Optional::isPresent)
            .map(Optional::get)
            .collect(toList());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy