return context;
}
public String evaluate(final String expression, final AbstractAttributableTO attributableTO) {
final JexlContext context = new MapContext();
if (attributableTO instanceof UserTO) {
UserTO user = (UserTO) attributableTO;
context.set("username", user.getUsername() != null
? user.getUsername()
: StringUtils.EMPTY);
context.set("password", user.getPassword() != null
? user.getPassword()
: StringUtils.EMPTY);
}
for (AttributeTO attribute : attributableTO.getAttributes()) {
List<String> attributeValues = attribute.getValues();
String expressionValue = attributeValues.isEmpty()
? StringUtils.EMPTY
: attributeValues.get(0);
LOG.debug("Add attribute {} with value {}", new Object[] { attribute.getSchema(), expressionValue });
context.set(attribute.getSchema(), expressionValue);
}
for (AttributeTO attribute : attributableTO.getDerivedAttributes()) {
List<String> attributeValues = attribute.getValues();
String expressionValue = attributeValues.isEmpty()
? StringUtils.EMPTY
: attributeValues.get(0);
LOG.debug("Add attribute {} with value {}", new Object[] { attribute.getSchema(), expressionValue });
context.set(attribute.getSchema(), expressionValue);
}
for (AttributeTO attribute : attributableTO.getVirtualAttributes()) {
List<String> attributeValues = attribute.getValues();
String expressionValue = attributeValues.isEmpty()
? StringUtils.EMPTY
: attributeValues.get(0);
LOG.debug("Add attribute {} with value {}", new Object[] { attribute.getSchema(), expressionValue });
context.set(attribute.getSchema(), expressionValue);
}
// Evaluate expression using the context prepared before
return evaluate(expression, context);
}