com.memority.toolkit.rule.api.ActionOutcome Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of toolkit-rule-api Show documentation
Show all versions of toolkit-rule-api Show documentation
This artifact provides the API classes that are necessary to implement the contracts of Memority configuration Rules.
/*
* Copyright (c) 2016-2023 Memority. All Rights Reserved.
*
* This file is part of Memority Toolkit API , a Memority project.
*
* This file is released under the Memority Public Artifacts End-User License Agreement,
* see
* Unauthorized copying of this file, via any medium is strictly prohibited.
*/
package com.memority.toolkit.rule.api;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import java.util.HashMap;
import java.util.Map;
/**
* Describes the result of an {@link ActionRule} execution.
*/
@AllArgsConstructor(access = AccessLevel.PRIVATE) @EqualsAndHashCode
public class ActionOutcome {
private Outcome outcome;
private String failureMessage;
private String i18nKey;
private Map i18nArgs = new HashMap<>();
public enum Outcome {
/**
* The action execution succeeded in performing its task
*/
SUCCESS,
/**
* The action execution was a failure
*/
FAILURE,
/**
* The action execution was cancelled and no task was performed
*/
NOOP
}
@SuppressWarnings("unused") // For Jackson
ActionOutcome() {
}
public ActionOutcome putI18nArg(String key, Object value) {
this.i18nArgs.put(key, value);
return this;
}
public boolean isFailure() { return this.outcome == Outcome.FAILURE; }
public boolean isSuccess() { return this.outcome == Outcome.SUCCESS || this.outcome == Outcome.NOOP; }
public static ActionOutcome success() {
return new ActionOutcome(Outcome.SUCCESS, null, null, null);
}
public static ActionOutcome noop() {
return new ActionOutcome(Outcome.NOOP, null, null, null);
}
public static ActionOutcome failure() {
return new ActionOutcome(Outcome.FAILURE, "Action execution failure", null, null);
}
public static ActionOutcome failure(String msg) { return new ActionOutcome(Outcome.FAILURE, msg, null, null); }
public static ActionOutcome failure(String msg, String i18nKey) { return new ActionOutcome(Outcome.FAILURE, msg, i18nKey, null); }
public static ActionOutcome failure(String msg, String i18nKey, Map i18nArgs) { return new ActionOutcome(Outcome.FAILURE, msg, i18nKey, i18nArgs); }
public Outcome getOutcome() {
return outcome;
}
public String getFailureMessage() {
return failureMessage;
}
public String getI18nKey() {
return i18nKey;
}
public Map getI18nArgs() {
return i18nArgs;
}
}