Search in sources :

Example 31 with JexlContext

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);
}
Also used : AnyTO(org.apache.syncope.common.lib.to.AnyTO) ArrayList(java.util.ArrayList) JexlContext(org.apache.commons.jexl3.JexlContext) RealmTO(org.apache.syncope.common.lib.to.RealmTO) MapContext(org.apache.commons.jexl3.MapContext)

Example 32 with JexlContext

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;
}
Also used : JexlContext(org.apache.commons.jexl3.JexlContext) MapContext(org.apache.commons.jexl3.MapContext) Any(org.apache.syncope.core.persistence.api.entity.Any)

Example 33 with JexlContext

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;
}
Also used : DerSchema(org.apache.syncope.core.persistence.api.entity.DerSchema) HashMap(java.util.HashMap) JexlContext(org.apache.commons.jexl3.JexlContext) MapContext(org.apache.commons.jexl3.MapContext)

Example 34 with JexlContext

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));
}
Also used : JexlContext(org.apache.commons.jexl3.JexlContext) MapContext(org.apache.commons.jexl3.MapContext) Realm(org.apache.syncope.core.persistence.api.entity.Realm) Test(org.junit.jupiter.api.Test)

Example 35 with 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());
    }
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) CommandException(org.apache.oozie.command.CommandException)

Aggregations

JexlContext (org.apache.commons.jexl2.JexlContext)31 Expression (org.apache.commons.jexl2.Expression)25 MapContext (org.apache.commons.jexl2.MapContext)23 JexlContext (org.apache.commons.jexl3.JexlContext)21 JexlEngine (org.apache.commons.jexl2.JexlEngine)20 MapContext (org.apache.commons.jexl3.MapContext)17 Test (org.testng.annotations.Test)13 HashMap (java.util.HashMap)5 Map (java.util.Map)4 ArrayList (java.util.ArrayList)3 JexlException (org.apache.commons.jexl2.JexlException)3 ObjectContext (org.apache.commons.jexl2.ObjectContext)3 IOException (java.io.IOException)2 ReadonlyContext (org.apache.commons.jexl2.ReadonlyContext)2 JexlScript (org.apache.commons.jexl3.JexlScript)2 NumberUtils (org.apache.commons.lang.math.NumberUtils)2 FloatWritable (org.apache.hadoop.io.FloatWritable)2 IntWritable (org.apache.hadoop.io.IntWritable)2 Text (org.apache.hadoop.io.Text)2 VersionMismatchException (org.apache.hadoop.io.VersionMismatchException)2