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

com.kenshoo.pl.entity.spi.helpers.ObservedResult 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.spi.helpers;


import com.kenshoo.pl.entity.CurrentEntityState;
import com.kenshoo.pl.entity.EntityField;
import com.kenshoo.pl.entity.EntityType;
import com.kenshoo.pl.entity.FieldsValueMap;
import com.kenshoo.pl.entity.Identifier;

import java.util.Optional;

public class ObservedResult> implements FieldsValueMap{

    public enum InspectedStatus {
        IDENTICAL,
        VALUE_MISMATCH,
        LEGACY_ERROR_MISMATCH,
        PERSISTENCE_ERROR_MISMATCH
    }

    private final boolean isSuccess;
    private final Identifier identifier;
    private final CurrentEntityState currentState;
    private final Optional errorCode;
    private InspectedStatus inspectedStatus = InspectedStatus.IDENTICAL;


    private ObservedResult(Identifier identifier, CurrentEntityState currentState) {
        this(identifier, currentState, true, null);
    }

    private ObservedResult(Identifier identifier, CurrentEntityState currentState, boolean isSuccess, String errorCode) {
        this.isSuccess = isSuccess;
        this.identifier = identifier;
        this.currentState = currentState;
        this.errorCode = Optional.ofNullable(errorCode);
    }

    public InspectedStatus getInspectedStatus() {
        return inspectedStatus;
    }

    void setInspectedStatus(InspectedStatus inspectedStatus) {
        this.inspectedStatus = inspectedStatus;
    }

    public boolean isSuccess() {
        return isSuccess;
    }

    public Identifier getIdentifier() {
        return identifier;
    }

    @Override
    public  boolean containsField(EntityField field) {
        return  currentState.containsField(field);
    }

    @Override
    public  T get(EntityField field) {
        return  currentState.get(field);
    }


    public Optional getErrorCode() {
        return errorCode;
    }

    public static > ObservedResult of(Identifier identifier, CurrentEntityState currentState)  {
        return new ObservedResult<>(identifier, currentState);
    }

    public static > ObservedResult error(Identifier identifier,  String errorCode)  {
        return new ObservedResult<>(identifier, null, false, errorCode);
    }

    public static class Builder> {
        private Identifier identifier;
        private CurrentEntityState currentState;
        private boolean isSuccess = true;
        private String errorCode;

        public Builder withIdentifier(Identifier identifier) {
            this.identifier = identifier;
            return this;
        }

        public Builder withEntity(CurrentEntityState currentState) {
            this.currentState = currentState;
            return this;
        }

        public Builder withErrorCode(String errorCode) {
            this.isSuccess = false;
            this.errorCode = errorCode;
            return this;
        }

        public ObservedResult build() {
            return new ObservedResult<>(identifier, currentState, isSuccess, errorCode);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy