org.algorithmx.rules.model.RuleExecution Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ruling-class Show documentation
Show all versions of ruling-class Show documentation
Java Rule Engine for the masses
The newest version!
/**
* This software is licensed under the Apache 2 license, quoted below.
*
* Copyright (c) 2019, algorithmx.org ([email protected])
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.algorithmx.rules.model;
import org.algorithmx.rules.bind.Binding;
import org.algorithmx.rules.spring.util.Assert;
import java.lang.ref.WeakReference;
import java.util.Arrays;
import java.util.Date;
import java.util.LinkedHashMap;
import java.util.Map;
/**
* Rule audit details. Contains all the details of a Rule Execution. It contains the details of the rule, all the associated
* rule parameters, result or error and the time of the execution.
*
* @author Max Arulananthan
* @since 1.0
*/
public final class RuleExecution implements Comparable {
// Make sure we don't hold onto the actual rule definition
private final WeakReference ruleDefinition;
private final Map params = new LinkedHashMap<>();
private final Date time = new Date();
private Boolean result;
private Exception error;
public RuleExecution(RuleDefinition ruleDefinition) {
super();
Assert.notNull(ruleDefinition, "ruleDefinition cannot be null.");
this.ruleDefinition = new WeakReference<>(ruleDefinition);
}
/**
* Returns the assocated Rule Definition. Could be null.
*
* @return rule definition (if avail).
*/
public RuleDefinition getRuleDefinition() {
return ruleDefinition.get();
}
/**
* Adds all the associated rule parameters.
*
* @param bindings rule parameters.
*/
public void add(Binding