nz.co.senanque.customer.R7 Maven / Gradle / Ivy
package nz.co.senanque.customer;
import java.io.Serializable;
import nz.co.senanque.base.Customer;
import nz.co.senanque.pizzaorder.externals.MyExternalFunctions;
import nz.co.senanque.rules.FieldReference;
import nz.co.senanque.rules.NotTrueException;
import nz.co.senanque.rules.Operations;
import nz.co.senanque.rules.Rule;
import nz.co.senanque.rules.RuleContext;
import nz.co.senanque.rules.RuleProxyField;
import nz.co.senanque.rules.RuleSession;
import nz.co.senanque.rules.UnKnownFieldValueException;
import nz.co.senanque.validationengine.ValidationObject;
import org.springframework.stereotype.Component;
/**
* rule:Customer Determine customerType B from name
* {if
* (name==aaaaab){
* customerType=b;
* testBoolean=true;
* amount=combine((5,7);}}
*
*/
@Component("nz.co.senanque.customer.R7")
public class R7
implements Serializable, Rule
{
private final static long serialVersionUID = 1L;
public void evaluate(final RuleSession session, final ValidationObject object, final RuleContext ruleContext) {
final Operations operations = session.getOperations();
final RuleProxyField proxyFieldname = session.getRuleProxyField(session.getMetadata(object).getProxyField("name"));
final RuleProxyField proxyFieldtestBoolean = session.getRuleProxyField(session.getMetadata(object).getProxyField("testBoolean"));
final RuleProxyField proxyFieldcustomerType = session.getRuleProxyField(session.getMetadata(object).getProxyField("customerType"));
final RuleProxyField proxyFieldamount = session.getRuleProxyField(session.getMetadata(object).getProxyField("amount"));
try {
try {
operations.checkTrue(operations.eq("aaaaab", ((String) proxyFieldname.getValue())));
} catch (NotTrueException _x) {
return ;
}
session.assign(ruleContext, "b", proxyFieldcustomerType);
session.assign(ruleContext, true, proxyFieldtestBoolean);
session.assign(ruleContext, MyExternalFunctions.combine(7L, 5L), proxyFieldamount);
} catch (UnKnownFieldValueException _x) {
return ;
}
}
public String getRuleName() {
return "nz.co.senanque.customer.R7:Determine customerType B from name";
}
public String getMessage(final RuleSession session, final ValidationObject object) {
return session.getMessage("nz.co.senanque.customer.R7", new Object[] { });
}
public String toString() {
return "nz.co.senanque.customer.R7:Determine customerType B from name";
}
public String getClassName() {
return "Customer";
}
public Class getScope() {
return Customer.class;
}
public FieldReference[] listeners() {
return new FieldReference[] {new FieldReference("Customer", "Customer", "name")};
}
public FieldReference[] outputs() {
return new FieldReference[] {new FieldReference("Customer", "Customer", "testBoolean"), new FieldReference("Customer", "Customer", "customerType"), new FieldReference("Customer", "Customer", "amount")};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy