return Boolean.parseBoolean(evaluate(mandatoryCondition, jexlContext));
}
public static String evaluate(final String expression, final AbstractAttributableTO attributableTO) {
final JexlContext context = new MapContext();
addFieldsToContext(attributableTO, context);
for (AttributeTO attr : attributableTO.getAttributes()) {
List<String> values = attr.getValues();
String expressionValue = values.isEmpty()
? StringUtils.EMPTY
: values.get(0);
LOG.debug("Add attribute {} with value {}", attr.getSchema(), expressionValue);
context.set(attr.getSchema(), expressionValue);
}
for (AttributeTO derAttr : attributableTO.getDerivedAttributes()) {
List<String> values = derAttr.getValues();
String expressionValue = values.isEmpty()
? StringUtils.EMPTY
: values.get(0);
LOG.debug("Add derived attribute {} with value {}", derAttr.getSchema(), expressionValue);
context.set(derAttr.getSchema(), expressionValue);
}
for (AttributeTO virAttr : attributableTO.getVirtualAttributes()) {
List<String> values = virAttr.getValues();
String expressionValue = values.isEmpty()
? StringUtils.EMPTY
: values.get(0);
LOG.debug("Add virtual attribute {} with value {}", virAttr.getSchema(), expressionValue);
context.set(virAttr.getSchema(), expressionValue);
}
// Evaluate expression using the context prepared before
return evaluate(expression, context);
}