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

nz.co.senanque.pizzaorder.rules.R13 Maven / Gradle / Ivy

Go to download

This is a rules-driven pizza configuration which lets you pick different pizza bases, toppings and sizes, except that only some combinations are allowed and the rules enforce this. The rules, UI and underlying domain objects are all delivered by this sub-application.

There is a newer version: 3.4.0
Show newest version

package nz.co.senanque.pizzaorder.rules;

import java.io.Serializable;
import nz.co.senanque.pizzaorder.instances.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.ValidationObject;
import org.springframework.stereotype.Component;


/**
 * formula:Customer Weight pounds
 * {
 * weight=weightPounds*0.453D;}
 * 
 */
@Component
public class R13
    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 proxyFieldweight = session.getRuleProxyField(session.getMetadata(object).getProxyField("weight"));
        final RuleProxyField proxyFieldweightPounds = session.getRuleProxyField(session.getMetadata(object).getProxyField("weightPounds"));
        try {
            session.assign(ruleContext, operations.mul(0.453D, ((Double) proxyFieldweightPounds.getValue())), proxyFieldweight);
        } catch (UnKnownFieldValueException _x) {
            return ;
        }
    }

    public String getRuleName() {
        return "R13:Weight pounds";
    }

    public String getMessage(final RuleSession session, final ValidationObject object) {
        return session.getMessage("nz.co.senanque.pizzaorder.rules.R13", new Object[] { });
    }

    public String toString() {
        return "R13:Weight pounds";
    }

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

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

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

    public FieldReference[] outputs() {
        return new FieldReference[] {new FieldReference("Customer", "Customer", "weight")};
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy