Search in sources :

Example 31 with Expression

use of org.kie.workbench.common.dmn.api.definition.v1_1.Expression in project kie-wb-common by kiegroup.

the class LiteralExpressionEditorDefinitionTest method testEditor.

@Test
public void testEditor() {
    final Optional<LiteralExpression> expression = definition.getModelClass();
    final Optional<BaseExpressionGrid> oEditor = definition.getEditor(parent, Optional.empty(), hasExpression, expression, hasName, 0);
    assertThat(oEditor).isPresent();
    final GridWidget editor = oEditor.get();
    assertThat(editor).isInstanceOf(LiteralExpressionGrid.class);
}
Also used : GridWidget(org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) Test(org.junit.Test)

Example 32 with Expression

use of org.kie.workbench.common.dmn.api.definition.v1_1.Expression in project kie-wb-common by kiegroup.

the class ExpressionContainerUIModelMapperTest method testFromDMNModelLiteralExpressionType.

@Test
@SuppressWarnings("unchecked")
public void testFromDMNModelLiteralExpressionType() {
    expression = new LiteralExpression();
    mapper.fromDMNModel(0, 0);
    assertUiModel();
    assertEditorType(literalExpressionEditor.getClass());
    verify(uiExpressionColumn).setWidth(MINIMUM_COLUMN_WIDTH);
    verify(literalExpressionEditorDefinition).getEditor(eq(parent), nodeUUIDCaptor.capture(), eq(hasExpression), eq(Optional.of(expression)), eq(Optional.of(hasName)), eq(0));
    final Optional<String> nodeUUID = nodeUUIDCaptor.getValue();
    assertThat(nodeUUID.isPresent()).isTrue();
    assertThat(nodeUUID.get()).isEqualTo(NODE_UUID);
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) Test(org.junit.Test)

Example 33 with Expression

use of org.kie.workbench.common.dmn.api.definition.v1_1.Expression in project vorto by eclipse.

the class AbstractDataMapper method matchesCondition.

private boolean matchesCondition(Map<String, String> attributes, JXPathContext context) {
    if (attributes.containsKey(ATTRIBUTE_CONDITION) && !attributes.get(ATTRIBUTE_CONDITION).equals("")) {
        Expression e = JEXL.createExpression(normalizeCondition(attributes.get(ATTRIBUTE_CONDITION)));
        JexlContext jc = new ObjectContext<Object>(JEXL, context.getContextBean());
        jc.set("this", context.getContextBean());
        return (boolean) e.evaluate(jc);
    } else {
        return true;
    }
}
Also used : Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) ObjectContext(org.apache.commons.jexl2.ObjectContext)

Example 34 with Expression

use of org.kie.workbench.common.dmn.api.definition.v1_1.Expression in project rubia-forums by flashboss.

the class ForumsACLResource method evaluate.

public boolean evaluate() {
    boolean isCriteriaMet = true;
    if (criteria != null) {
        try {
            JexlEngine jexl = new JexlEngine();
            JexlContext context2 = new MapContext();
            if (criteria != null) {
                Expression expression = jexl.createExpression(criteria);
                context2.set("param", map.get("runtimeInfo"));
                context2.set("identity", map.get("identity"));
                Object value = expression.evaluate(context2);
                isCriteriaMet = ((Boolean) value).booleanValue();
            }
        } catch (Exception e) {
            log.error(e);
            isCriteriaMet = false;
        }
    }
    return isCriteriaMet;
}
Also used : JexlEngine(org.apache.commons.jexl2.JexlEngine) Expression(org.apache.commons.jexl2.Expression) JexlContext(org.apache.commons.jexl2.JexlContext) MapContext(org.apache.commons.jexl2.MapContext)

Example 35 with Expression

use of org.kie.workbench.common.dmn.api.definition.v1_1.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

Expression (org.kie.workbench.common.dmn.api.definition.v1_1.Expression)19 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)15 Expression (org.apache.commons.jexl2.Expression)14 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)13 JexlContext (org.apache.commons.jexl2.JexlContext)12 Test (org.junit.Test)12 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)12 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)11 HasName (org.kie.workbench.common.dmn.api.definition.HasName)10 JexlEngine (org.apache.commons.jexl2.JexlEngine)9 InformationItem (org.kie.workbench.common.dmn.api.definition.v1_1.InformationItem)9 BaseGridCellValue (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)9 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)9 MapContext (org.apache.commons.jexl2.MapContext)8 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)7 Expression (org.eclipse.xtext.resource.bug385636.Expression)7 Optional (java.util.Optional)6 Before (org.junit.Before)6 Decision (org.kie.workbench.common.dmn.api.definition.v1_1.Decision)6 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)6