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

com.kenshoo.pl.entity.internal.audit.AuditMandatoryFieldValuesGenerator 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.FieldValue;
import com.kenshoo.pl.entity.FinalEntityState;
import org.apache.commons.lang3.tuple.ImmutablePair;

import java.util.Collection;
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 AuditMandatoryFieldValuesGenerator {

    private final Collection> mandatoryFields;
    private final AuditFieldValueResolver auditFieldValueResolver;

    public AuditMandatoryFieldValuesGenerator(final Stream> mandatoryFields) {
        this(mandatoryFields, AuditFieldValueResolver.INSTANCE);
    }

    @VisibleForTesting
    AuditMandatoryFieldValuesGenerator(final Stream> mandatoryFields,
                                       final AuditFieldValueResolver auditFieldValueResolver) {
        requireNonNull(mandatoryFields, "mandatoryFields must not be null (can be empty)");
        this.mandatoryFields = mandatoryFields.collect(toList());
        this.auditFieldValueResolver = auditFieldValueResolver;
    }

    Collection generate(final FinalEntityState finalState) {
        requireNonNull(finalState, "finalState is required");
        return seq(mandatoryFields)
            .map(field -> ImmutablePair.of(field, auditFieldValueResolver.resolveToString(field, finalState)))
            .filter(pair -> pair.getValue().isNotNull())
            .map(pair -> new FieldValue(pair.getKey().getName(), pair.getValue().get()))
            .collect(toList());
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy