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

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

import com.kenshoo.pl.entity.ChangeOperation;
import com.kenshoo.pl.entity.EntityFieldValue;
import com.kenshoo.pl.entity.EntityType;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.Collection;

import static java.util.Collections.emptyList;
import static java.util.Objects.requireNonNull;
import static java.util.stream.Collectors.toList;

public class AuditRecord> {
    private final E entityType;
    private final String entityId;
    private final Collection mandatoryFieldValues;
    private final ChangeOperation operator;
    private final Collection> fieldRecords;
    private final Collection> childRecords;

    private AuditRecord(final E entityType,
                        final String entityId,
                        final Collection mandatoryFieldValues,
                        final ChangeOperation operator,
                        final Collection> fieldRecords,
                        final Collection> childRecords) {
        this.entityType = requireNonNull(entityType, "entityType is required");
        this.entityId = requireNonNull(entityId, "entityId is required");
        this.mandatoryFieldValues = mandatoryFieldValues;
        this.operator = requireNonNull(operator, "operator is required");
        this.fieldRecords = fieldRecords;
        this.childRecords = childRecords;
    }

    public E getEntityType() {
        return entityType;
    }

    public String getEntityId() {
        return entityId;
    }

    public Collection getMandatoryFieldValues() {
        return mandatoryFieldValues;
    }

    public ChangeOperation getOperator() {
        return operator;
    }

    public Collection> getFieldRecords() {
        return fieldRecords;
    }

    public Collection> getChildRecords() {
        return childRecords;
    }

    public boolean hasNoChanges() {
        return fieldRecords.isEmpty() && childRecords.isEmpty();
    }

    /**
     * Generates a deep string representation of the entire hierarchy of records.
* WARNING: if there are many nested levels of child records, will have poor performance! */ @Override public String toString() { return toString(Integer.MAX_VALUE); } /** * Generates a deep string representation limited to the given number of nested levels. * @param maxDepth maximum depth of recursion, must be at least one (one means without child records). */ public String toString(final int maxDepth) { if (maxDepth <= 0) { return StringUtils.EMPTY; } return new ToStringBuilder(this, ToStringStyle.SHORT_PREFIX_STYLE) .append("entityType", entityType.getName()) .append("entityId", entityId) .append("mandatoryFieldValues", mandatoryFieldValues) .append("operator", operator) .append("fieldRecords", fieldRecords) .append("childRecords", childRecordsToString(maxDepth)) .toString(); } private String childRecordsToString(final int maxDepth) { return childRecords.stream() .map(childRecord -> childRecord.toString(maxDepth - 1)) .collect(toList()) .toString(); } public static class Builder> { private E entityType; private String entityId; private Collection mandatoryFieldValues = emptyList(); private ChangeOperation operator; private Collection> fieldRecords = emptyList(); private Collection> childRecords = emptyList(); public Builder withEntityType(E entityType) { this.entityType = entityType; return this; } public Builder withEntityId(String entityId) { this.entityId = entityId; return this; } public Builder withOperator(ChangeOperation operator) { this.operator = operator; return this; } public Builder withMandatoryFieldValues(final Collection fieldValues) { this.mandatoryFieldValues = fieldValues == null ? emptyList() : fieldValues; return this; } public Builder withFieldRecords(Collection> fieldRecords) { this.fieldRecords = fieldRecords == null ? emptyList() : fieldRecords; return this; } public Builder withChildRecords(Collection> childRecords) { this.childRecords = childRecords == null ? emptyList() : childRecords; return this; } public AuditRecord build() { return new AuditRecord<>(entityType, entityId, mandatoryFieldValues, operator, fieldRecords, childRecords); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy