nz.co.senanque.workflow.nmcrules.R1 Maven / Gradle / Ivy
The newest version!
package nz.co.senanque.workflow.nmcrules;
import java.io.Serializable;
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 nz.co.senanque.workflow.nmcinstances.NMC;
import org.springframework.stereotype.Component;
/**
* rule:NMC p0
* {if
* (reservationId==none){
* status=rejected;
* hasFunds=false;
* rejected=true;}}
*
*/
@Component("nz.co.senanque.workflow.nmcrules.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 proxyFieldstatus = session.getRuleProxyField(session.getMetadata(object).getProxyField("status"));
final RuleProxyField proxyFieldreservationId = session.getRuleProxyField(session.getMetadata(object).getProxyField("reservationId"));
final RuleProxyField proxyFieldhasFunds = session.getRuleProxyField(session.getMetadata(object).getProxyField("hasFunds"));
final RuleProxyField proxyFieldrejected = session.getRuleProxyField(session.getMetadata(object).getProxyField("rejected"));
try {
try {
operations.checkTrue(operations.eq("none", ((String) proxyFieldreservationId.getValue())));
} catch (NotTrueException _x) {
return ;
}
session.assign(ruleContext, "rejected", proxyFieldstatus);
session.assign(ruleContext, false, proxyFieldhasFunds);
session.assign(ruleContext, true, proxyFieldrejected);
} catch (UnKnownFieldValueException _x) {
return ;
}
}
public String getRuleName() {
return "nz.co.senanque.workflow.nmcrules.R1:p0";
}
public String getMessage(final RuleSession session, final ValidationObject object) {
return session.getMessage("nz.co.senanque.workflow.nmcrules.R1", new Object[] { });
}
public String toString() {
return "nz.co.senanque.workflow.nmcrules.R1:p0";
}
public String getClassName() {
return "NMC";
}
public Class getScope() {
return NMC.class;
}
public FieldReference[] listeners() {
return new FieldReference[] {new FieldReference("NMC", "NMC", "reservationId")};
}
public FieldReference[] outputs() {
return new FieldReference[] {new FieldReference("NMC", "NMC", "status"), new FieldReference("NMC", "NMC", "hasFunds"), new FieldReference("NMC", "NMC", "rejected")};
}
}