use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.
the class ExpressionFieldActionTest method testLT.
@Test
public void testLT() throws Exception {
Expression action = new Expression();
action.setExpression("IF(LT(${0}, ${1}), ${0}, ${1})");
assertEquals(10, ExpressionFieldAction.process(action, Arrays.asList(10, 100)));
assertEquals(100, ExpressionFieldAction.process(action, Arrays.asList(1000, 100)));
assertEquals(-10, ExpressionFieldAction.process(action, Arrays.asList(10, -10)));
action.setExpression("IF(${0} < ${1}, ${0}, ${1})");
assertEquals(10, ExpressionFieldAction.process(action, Arrays.asList(10, 100)));
assertEquals(100, ExpressionFieldAction.process(action, Arrays.asList(1000, 100)));
assertEquals(-10, ExpressionFieldAction.process(action, Arrays.asList(10, -10)));
}
use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.
the class ArithmeticExpression method evaluate.
/**
* Evaluates the expression.
* @param message expression context
* @return result {@link Field}
*/
public Field evaluate(ExpressionContext message) throws ExpressionException {
Field lfield = left.evaluate(message);
if (lfield == null || lfield.getValue() == null) {
return wrapWithField(null);
}
Field rfield = right.evaluate(message);
if (rfield == null || rfield.getValue() == null) {
return null;
}
return evaluate(lfield, rfield);
}
use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.
the class StringComplexFieldActions method replaceFirst.
/**
* Replaces first hit with the regular expression specified as a parameter.
* @param replaceFirst action model
* @param input source
* @return processed
*/
@AtlasActionProcessor
public static String replaceFirst(ReplaceFirst replaceFirst, String input) {
if (replaceFirst == null || replaceFirst.getMatch() == null || replaceFirst.getMatch().isEmpty()) {
throw new IllegalArgumentException("ReplaceFirst action must be specified with a non-empty old string");
}
String match = replaceFirst.getMatch();
String newString = replaceFirst.getNewString();
return input == null ? null : input.replaceFirst(match, newString == null ? "" : newString);
}
use of io.atlasmap.v2.Expression in project atlasmap by atlasmap.
the class ExpressionFieldAction method process.
/**
* Processes expression field action.
* @param action action model
* @param args expression arguments
* @return processed
* @throws ExpressionException expression processing error
*/
@Deprecated
@AtlasActionProcessor
public static Object process(io.atlasmap.v2.Expression action, List<Object> args) throws ExpressionException {
if (action.getExpression() == null || action.getExpression().trim().isEmpty()) {
return null;
}
Expression parsedExpression = Expression.parse(action.getExpression(), DefaultAtlasFunctionResolver.getInstance());
Field answer = parsedExpression.evaluate((index) -> {
try {
return wrapWithField(args.get(Integer.parseInt(index)));
} catch (Throwable e) {
throw new ExpressionException("Invalid variable: " + index);
}
});
return unwrapField(answer);
}
use of io.atlasmap.v2.Expression in project vorto by eclipse.
the class DataMapperJxpath method matchesCondition.
private boolean matchesCondition(FunctionblockModel fbModel, JXPathContext context) {
Optional<Stereotype> conditionStereotype = fbModel.getStereotype("condition");
if (conditionStereotype.isPresent() && conditionStereotype.get().hasAttribute("value")) {
Expression e = jexlEngine.createExpression(normalizeCondition(conditionStereotype.get().getAttributes().get("value")));
JexlContext jc = new ObjectContext<Object>(jexlEngine, context.getContextBean());
jc.set("this", context.getContextBean());
jc.set("obj", context.getContextBean());
return (boolean) e.evaluate(jc);
} else {
return true;
}
}
Aggregations