Search in sources :

Example 11 with Expression

use of io.atlasmap.v2.Expression in project oozie by apache.

the class CoordInputLogicEvaluatorUtil method checkPullMissingDependencies.

/**
 * Check pull missing dependencies.
 *
 * @return true, if successful
 * @throws JDOMException the JDOM exception
 */
public boolean checkPullMissingDependencies() throws JDOMException {
    JexlEngine jexl = new OozieJexlEngine();
    String expression = CoordUtils.getInputLogic(coordAction.getActionXml().toString());
    if (StringUtils.isEmpty(expression)) {
        return true;
    }
    Expression e = jexl.createExpression(expression);
    JexlContext jc = new OozieJexlParser(jexl, new CoordInputLogicBuilder(new CoordInputLogicEvaluatorPhaseOne(coordAction, coordAction.getPullInputDependencies())));
    CoordInputLogicEvaluatorResult result = (CoordInputLogicEvaluatorResult) e.evaluate(jc);
    log.debug("Input logic expression for [{0}] and evaluate result is [{1}]", expression, result.getStatus());
    if (result.isWaiting()) {
        return false;
    }
    return result.isTrue();
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext)

Example 12 with Expression

use of io.atlasmap.v2.Expression in project oozie by apache.

the class CoordInputLogicEvaluatorUtil method checkPushDependencies.

/**
 * Check push dependencies.
 *
 * @return true, if successful
 * @throws JDOMException the JDOM exception
 */
public boolean checkPushDependencies() throws JDOMException {
    JexlEngine jexl = new OozieJexlEngine();
    String expression = CoordUtils.getInputLogic(coordAction.getActionXml().toString());
    if (StringUtils.isEmpty(expression)) {
        return true;
    }
    Expression e = jexl.createExpression(expression);
    JexlContext jc = new OozieJexlParser(jexl, new CoordInputLogicBuilder(new CoordInputLogicEvaluatorPhaseOne(coordAction, coordAction.getPushInputDependencies())));
    CoordInputLogicEvaluatorResult result = (CoordInputLogicEvaluatorResult) e.evaluate(jc);
    log.debug("Input logic expression for [{0}] and evaluate result is [{1}]", expression, result.getStatus());
    if (result.isWaiting()) {
        return false;
    }
    return result.isTrue();
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext)

Example 13 with Expression

use of io.atlasmap.v2.Expression in project oozie by apache.

the class CoordInputLogicEvaluatorUtil method checkUnResolved.

/**
 * Check unresolved.
 *
 * @param actualTime the actual time
 * @return true, if successful
 * @throws JDOMException the JDOM exception
 */
public boolean checkUnResolved(Date actualTime) throws JDOMException {
    JexlEngine jexl = new OozieJexlEngine();
    String expression = CoordUtils.getInputLogic(coordAction.getActionXml().toString());
    if (StringUtils.isEmpty(expression)) {
        return true;
    }
    Expression e = jexl.createExpression(expression);
    JexlContext jc = new OozieJexlParser(jexl, new CoordInputLogicBuilder(new CoordInputLogicEvaluatorPhaseTwo(coordAction, actualTime)));
    CoordInputLogicEvaluatorResult result = (CoordInputLogicEvaluatorResult) e.evaluate(jc);
    log.debug("Input logic expression for [{0}] and evaluate result is [{1}]", expression, result.getStatus());
    if (result.isWaiting()) {
        return false;
    }
    return result.isTrue();
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext)

Example 14 with Expression

use of io.atlasmap.v2.Expression in project oozie by apache.

the class CoordInputLogicEvaluatorUtil method getInputDependencies.

/**
 * Get input dependencies.
 *
 * @param name the name
 * @param syncCoordAction the sync coord action
 * @return the string
 * @throws JDOMException the JDOM exception
 */
public String getInputDependencies(String name, SyncCoordAction syncCoordAction) throws JDOMException {
    JexlEngine jexl = new OozieJexlEngine();
    CoordinatorActionBean coordAction = new CoordinatorActionBean();
    ELEvaluator eval = ELEvaluator.getCurrent();
    coordAction.setId(syncCoordAction.getActionId());
    Element eJob = XmlUtils.parseXml(eval.getVariable(".actionInputLogic").toString());
    String expression = new InputLogicParser().parseWithName(eJob, name);
    Expression e = jexl.createExpression(expression);
    CoordPullInputDependency pull = (CoordPullInputDependency) syncCoordAction.getPullDependencies();
    CoordPushInputDependency push = (CoordPushInputDependency) syncCoordAction.getPushDependencies();
    coordAction.setPushInputDependencies(push);
    coordAction.setPullInputDependencies(pull);
    JexlContext jc = new OozieJexlParser(jexl, new CoordInputLogicBuilder(new CoordInputLogicEvaluatorPhaseThree(coordAction, eval)));
    CoordInputLogicEvaluatorResult result = (CoordInputLogicEvaluatorResult) e.evaluate(jc);
    if (result == null || !result.isTrue()) {
        log.debug("Input logic expression for [{0}] is [{1}] and it is not resolved", name, expression);
        return "${coord:dataIn('" + name + "')}";
    } else {
        log.debug("Input logic expression for [{0}] is [{1}] and evaluate result is [{2}]", name, expression, result.getStatus());
        return result.getDataSets();
    }
}
Also used : CoordinatorActionBean(org.apache.oozie.CoordinatorActionBean) Element(org.jdom.Element) CoordPullInputDependency(org.apache.oozie.coord.input.dependency.CoordPullInputDependency) JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) ELEvaluator(org.apache.oozie.util.ELEvaluator) CoordPushInputDependency(org.apache.oozie.coord.input.dependency.CoordPushInputDependency)

Example 15 with Expression

use of io.atlasmap.v2.Expression in project javautils by jiadongpo.

the class PropsUtils method resolveVariableExpression.

/**
 * Function that looks for expressions to parse. It parses backwards to capture embedded
 * expressions
 */
private static String resolveVariableExpression(final String value, final int last, final JexlEngine jexl) {
    final int lastIndex = value.lastIndexOf("$(", last);
    if (lastIndex == -1) {
        return value;
    }
    // Want to check that everything is well formed, and that
    // we properly capture $( ...(...)...).
    int bracketCount = 0;
    int nextClosed = lastIndex + 2;
    for (; nextClosed < value.length(); ++nextClosed) {
        if (value.charAt(nextClosed) == '(') {
            bracketCount++;
        } else if (value.charAt(nextClosed) == ')') {
            bracketCount--;
            if (bracketCount == -1) {
                break;
            }
        }
    }
    if (nextClosed == value.length()) {
        throw new IllegalArgumentException("Expression " + value + " not well formed.");
    }
    final String innerExpression = value.substring(lastIndex + 2, nextClosed);
    Object result = null;
    try {
        final Expression e = jexl.createExpression(innerExpression);
        result = e.evaluate(new MapContext());
    } catch (final JexlException e) {
        throw new IllegalArgumentException("Expression " + value + " not well formed. " + e.getMessage(), e);
    }
    if (result == null) {
        // for backward compatibility it is best to return value
        return value;
    }
    final String newValue = value.substring(0, lastIndex) + result.toString() + value.substring(nextClosed + 1);
    return resolveVariableExpression(newValue, lastIndex, jexl);
}
Also used : Expression(org.apache.commons.jexl2.Expression) JexlException(org.apache.commons.jexl2.JexlException) MapContext(org.apache.commons.jexl2.MapContext)

Aggregations

Test (org.junit.jupiter.api.Test)34 Expression (org.apache.commons.jexl2.Expression)28 Expression (io.atlasmap.v2.Expression)26 JexlContext (org.apache.commons.jexl2.JexlContext)25 JexlEngine (org.apache.commons.jexl2.JexlEngine)22 Field (io.atlasmap.v2.Field)21 FieldGroup (io.atlasmap.v2.FieldGroup)20 MapContext (org.apache.commons.jexl2.MapContext)20 SimpleField (io.atlasmap.v2.SimpleField)16 Test (org.testng.annotations.Test)13 PropertyField (io.atlasmap.v2.PropertyField)9 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)7 Expression (org.eclipse.xtext.resource.bug385636.Expression)7 Expression (org.kie.workbench.common.dmn.api.definition.v1_1.Expression)7 Expression (io.atlasmap.expression.Expression)6 ArrayList (java.util.ArrayList)6 List (java.util.List)5 ParseException (io.atlasmap.expression.parser.ParseException)4 Action (io.atlasmap.v2.Action)4 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)4