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);
}
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);
}
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;
}
}
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;
}
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);
}
Aggregations