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

com.kenshoo.pl.entity.internal.audit.AuditRequiredFieldsCalculator 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.ChangeOperation;
import com.kenshoo.pl.entity.EntityField;
import com.kenshoo.pl.entity.EntityType;
import com.kenshoo.pl.entity.spi.CurrentStateConsumer;
import org.jooq.lambda.Seq;

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

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

public class AuditRequiredFieldsCalculator> implements CurrentStateConsumer {

    private final AuditedFieldSet auditedFieldSet;

    public AuditRequiredFieldsCalculator(final AuditedFieldSet auditedFieldSet) {
        this.auditedFieldSet = requireNonNull(auditedFieldSet, "auditedFieldSet is required");
    }

    @Override
    public Stream> requiredFields(final Collection> fieldsToChange,
                                                              final ChangeOperation changeOperation) {

        final Set> onChangeFields = auditedFieldSet.getOnChangeFields().collect(toSet());

        final Seq> intersectedChangeFields =
            seq(fieldsToChange).filter(onChangeFields::contains);

        return Seq.>of(auditedFieldSet.getIdField())
            .append(auditedFieldSet.getMandatoryFields())
            .append(intersectedChangeFields);
    }

    @VisibleForTesting
    public AuditedFieldSet getAuditedFieldSet() {
        return auditedFieldSet;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy