use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class Condition method evaluate.
public static final boolean evaluate(String clause, Navajo inMessage, MappableTreeNode o, Message parent, Message paramParent, Access access) throws TMLExpressionException, SystemException {
Map<String, Object> params = new HashMap<>();
params.put(Expression.ACCESS, access);
// valuate(clause, inMessage, o, parent, paramParent);
Operand evaluate = Expression.evaluate(clause, inMessage, o, parent, paramParent, null, null, params);
return (boolean) evaluate.value;
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class ASTFunctionNode method resolveNormalFunction.
private ContextExpression resolveNormalFunction(List<ContextExpression> l, Map<String, ContextExpression> named, List<String> problems, String expression) {
FunctionInterface typeCheckInstance = getFunction();
if (typeCheckInstance == null) {
throw new NullPointerException("Function: " + functionName + " can not be resolved!");
}
try {
List<String> typeProblems = typeCheckInstance.typeCheck(l, expression);
if (!typeProblems.isEmpty() && RuntimeConfig.STRICT_TYPECHECK.getValue() != null) {
problems.addAll(typeProblems);
}
} catch (Throwable e2) {
typechecklogger.error("Typechecker itself failed when parsing: " + expression + " function definition: " + typeCheckInstance + " Error: ", e2);
}
boolean isImmutable = typeCheckInstance.isPure() && l.stream().allMatch(e -> e.isLiteral());
ContextExpression dynamic = new ContextExpression() {
@Override
public boolean isLiteral() {
// TODO also check named params
return isImmutable;
}
@Override
public Operand apply(Navajo doc, Message parentMsg, Message parentParamMsg, Selection parentSel, MappableTreeNode mapNode, TipiLink tipiLink, Access access, Optional<ImmutableMessage> immutableMessage, Optional<ImmutableMessage> paramMessage) {
FunctionInterface f = getFunction();
Map<String, Operand> resolvedNamed = named.entrySet().stream().collect(Collectors.toMap(e -> e.getKey(), e -> e.getValue().apply(doc, parentMsg, parentParamMsg, parentSel, mapNode, tipiLink, access, immutableMessage, paramMessage)));
f.setInMessage(doc);
f.setNamedParameter(resolvedNamed);
f.setCurrentMessage(parentMsg);
f.setAccess(access);
f.reset();
l.stream().map(e -> {
try {
Operand evaluated = e.apply(doc, parentMsg, parentParamMsg, parentSel, mapNode, tipiLink, access, immutableMessage, paramMessage);
if (evaluated == null) {
logger.warn("Problematic expression returned null object. If you really insist, return an Operand.NULL. Evaluating expression: {}", expression);
}
return evaluated;
} catch (TMLExpressionException e1) {
throw new TMLExpressionException("Error parsing parameters for function: " + functionName, e1);
}
}).forEach(e -> f.insertOperand(e));
return f.evaluateWithTypeCheckingOperand();
}
@Override
public Optional<String> returnType() {
return typeCheckInstance.getReturnType();
}
@Override
public String expression() {
return expression;
}
};
if (isImmutable && CacheSubexpression.getCacheSubExpression()) {
Optional<String> returnType = dynamic.returnType();
String immutablExpression = dynamic.expression();
Operand resolved = dynamic.apply();
return new ContextExpression() {
@Override
public Optional<String> returnType() {
return returnType;
}
@Override
public boolean isLiteral() {
return true;
}
@Override
public String expression() {
return immutablExpression;
}
@Override
public Operand apply(Navajo doc, Message parentMsg, Message parentParamMsg, Selection parentSel, MappableTreeNode mapNode, TipiLink tipiLink, Access access, Optional<ImmutableMessage> immutableMessage, Optional<ImmutableMessage> paramMessage) {
return resolved;
}
};
} else {
return dynamic;
}
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class ExpressionTest method testExpressionWithDocSpecWithoutCompiled.
// Re-enable if I backport this to non-compiled expressions.
@Test
@Ignore
public void testExpressionWithDocSpecWithoutCompiled() throws Exception {
Expression.compileExpressions = false;
Operand o = Expression.evaluate("[custom|/MyTop/MyArrayMessage@2/MyProp2]", testDoc);
assertEquals("aap2", o.value);
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class ExpressionTest method testExpressionWithDocSpec.
@Test
public void testExpressionWithDocSpec() throws Exception {
Expression.compileExpressions = true;
Operand o = Expression.evaluate("[custom|/MyTop/MyArrayMessage@2/MyProp2]", testDoc);
assertEquals("aap2", o.value);
}
use of com.dexels.navajo.document.Operand in project navajo by Dexels.
the class ExpressionTest method testUnicode.
@Test
public void testUnicode() throws Exception {
ExpressionEvaluator ee = NavajoFactory.getInstance().getExpressionEvaluator();
Operand o = ee.evaluate("'ø'+'æ'", null, null, null);
assertEquals("øæ", o.value);
}
Aggregations