use of org.apache.commons.jexl2.JexlContext in project syncope by apache.
the class JEXLItemTransformerImpl method beforePull.
@Override
public List<Object> beforePull(final Item item, final EntityTO entityTO, final List<Object> values) {
if (StringUtils.isNotBlank(pullJEXL) && values != null) {
List<Object> newValues = new ArrayList<>(values.size());
values.forEach(value -> {
JexlContext jexlContext = new MapContext();
jexlContext.set("value", value);
if (entityTO instanceof AnyTO) {
JexlUtils.addFieldsToContext((AnyTO) entityTO, jexlContext);
JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getPlainAttrs(), jexlContext);
JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getDerAttrs(), jexlContext);
JexlUtils.addAttrTOsToContext(((AnyTO) entityTO).getVirAttrs(), jexlContext);
} else if (entityTO instanceof RealmTO) {
JexlUtils.addFieldsToContext((RealmTO) entityTO, jexlContext);
newValues.add(JexlUtils.evaluate(pullJEXL, jexlContext));
}
newValues.add(JexlUtils.evaluate(pullJEXL, jexlContext));
});
return newValues;
}
return JEXLItemTransformer.super.beforePull(item, entityTO, values);
}
use of org.apache.commons.jexl2.JexlContext in project syncope by apache.
the class JEXLItemTransformerImpl method beforePropagation.
@Override
public List<PlainAttrValue> beforePropagation(final Item item, final Entity entity, final List<PlainAttrValue> values) {
if (StringUtils.isNotBlank(propagationJEXL) && values != null) {
values.forEach(value -> {
JexlContext jexlContext = new MapContext();
if (entity != null) {
JexlUtils.addFieldsToContext(entity, jexlContext);
if (entity instanceof Any) {
JexlUtils.addPlainAttrsToContext(((Any<?>) entity).getPlainAttrs(), jexlContext);
JexlUtils.addDerAttrsToContext(((Any<?>) entity), jexlContext);
}
}
jexlContext.set("value", value.getValueAsString());
value.setStringValue(JexlUtils.evaluate(propagationJEXL, jexlContext));
});
return values;
}
return values;
}
use of org.apache.commons.jexl2.JexlContext in project syncope by apache.
the class DerAttrHandlerImpl method getValues.
private Map<DerSchema, String> getValues(final Any<?> any, final Set<DerSchema> schemas) {
Map<DerSchema, String> result = new HashMap<>(schemas.size());
for (DerSchema schema : schemas) {
JexlContext jexlContext = new MapContext();
JexlUtils.addPlainAttrsToContext(any.getPlainAttrs(), jexlContext);
JexlUtils.addFieldsToContext(any, jexlContext);
result.put(schema, JexlUtils.evaluate(schema.getExpression(), jexlContext));
}
return result;
}
use of org.apache.commons.jexl2.JexlContext in project syncope by apache.
the class MappingTest method realmConnObjectLink.
@Test
public void realmConnObjectLink() {
Realm realm = realmDAO.findByFullPath("/even/two");
assertNotNull(realm);
JexlContext jexlContext = new MapContext();
JexlUtils.addFieldsToContext(realm, jexlContext);
String connObjectLink = "syncope:fullPath2Dn(fullPath, 'ou') + ',o=isp'";
assertEquals("ou=two,ou=even,o=isp", JexlUtils.evaluate(connObjectLink, jexlContext));
realm = realmDAO.findByFullPath("/even");
assertNotNull(realm);
jexlContext = new MapContext();
JexlUtils.addFieldsToContext(realm, jexlContext);
assertEquals("ou=even,o=isp", JexlUtils.evaluate(connObjectLink, jexlContext));
}
use of org.apache.commons.jexl2.JexlContext in project oozie by apache.
the class CoordInputLogicEvaluatorUtil method validateInputLogic.
/**
* Validate input logic.
*
* @throws JDOMException the JDOM exception
* @throws CommandException in case of error
*/
public void validateInputLogic() throws JDOMException, CommandException {
JexlEngine jexl = new OozieJexlEngine();
String expression = CoordUtils.getInputLogic(coordAction.getActionXml().toString());
if (StringUtils.isEmpty(expression)) {
return;
}
Expression e = jexl.createExpression(expression);
JexlContext jc = new OozieJexlParser(jexl, new CoordInputLogicBuilder(new CoordInputLogicEvaluatorPhaseValidate(coordAction)));
try {
Object result = e.evaluate(jc);
log.debug("Input logic expression is [{0}] and evaluate result is [{1}]", expression, result);
} catch (RuntimeException re) {
throw new CommandException(ErrorCode.E1028, re.getCause().getMessage());
}
}
Aggregations