nz.co.senanque.customer.R1 Maven / Gradle / Ivy
package nz.co.senanque.customer;
import java.io.Serializable;
import nz.co.senanque.base.Customer;
import nz.co.senanque.rules.FieldReference;
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.ListeningArray;
import nz.co.senanque.validationengine.ValidationObject;
import org.springframework.stereotype.Component;
/**
* formula:Customer Count Items in list
* {
* invoiceCount=count((invoices);}
*
*/
@Component("nz.co.senanque.customer.R1")
public class R1
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 proxyFieldinvoiceCount = session.getRuleProxyField(session.getMetadata(object).getProxyField("invoiceCount"));
final RuleProxyField proxyFieldinvoices = session.getRuleProxyField(session.getMetadata(object).getProxyField("invoices"));
try {
session.assign(ruleContext, operations.count(((ListeningArray) proxyFieldinvoices.getValue())), proxyFieldinvoiceCount);
} catch (UnKnownFieldValueException _x) {
return ;
}
}
public String getRuleName() {
return "nz.co.senanque.customer.R1:Count Items in list";
}
public String getMessage(final RuleSession session, final ValidationObject object) {
return session.getMessage("nz.co.senanque.customer.R1", new Object[] { });
}
public String toString() {
return "nz.co.senanque.customer.R1:Count Items in list";
}
public String getClassName() {
return "Customer";
}
public Class getScope() {
return Customer.class;
}
public FieldReference[] listeners() {
return new FieldReference[] {new FieldReference("Customer", "Customer", "invoices")};
}
public FieldReference[] outputs() {
return new FieldReference[] {new FieldReference("Customer", "Customer", "invoiceCount")};
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy