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

nz.co.senanque.listfunctions.R6 Maven / Gradle / Ivy


package nz.co.senanque.listfunctions;

import java.io.Serializable;
import nz.co.senanque.base.Customer;
import nz.co.senanque.rules.ConstraintViolationException;
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;


/**
 * constraint:Customer invoice count must be greater than {0}[minInvoiceCount]
 * {
 * (invoiceCount>=minInvoiceCount);}
 * 
 */
@Component("nz.co.senanque.listfunctions.R6")
public class R6
    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 proxyFieldminInvoiceCount = session.getRuleProxyField(session.getMetadata(object).getProxyField("minInvoiceCount"));
        try {
            try {
                operations.checkTrue(operations.ge(((Long) proxyFieldminInvoiceCount.getValue()), ((Long) proxyFieldinvoiceCount.getValue())));
            } catch (NotTrueException _x) {
                throw new ConstraintViolationException(getMessage(session, object));
            }
        } catch (UnKnownFieldValueException _x) {
            return ;
        }
    }

    public String getRuleName() {
        return "nz.co.senanque.listfunctions.R6:invoice count must be greater than {0}";
    }

    public String getMessage(final RuleSession session, final ValidationObject object) {
        return session.getMessage("nz.co.senanque.listfunctions.R6", new Object[] {((Long) session.getMetadata(object).getProxyField("minInvoiceCount").getValue())});
    }

    public String toString() {
        return "nz.co.senanque.listfunctions.R6:invoice count must be greater than {0}";
    }

    public String getClassName() {
        return "Customer";
    }

    public Class getScope() {
        return Customer.class;
    }

    public FieldReference[] listeners() {
        return new FieldReference[] {new FieldReference("Customer", "Customer", "minInvoiceCount"), new FieldReference("Customer", "Customer", "invoiceCount")};
    }

    public FieldReference[] outputs() {
        return null;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy