Search in sources :

Example 6 with TMLExpressionException

use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.

the class ASTDivNode method interpret.

private final Operand interpret(Operand ao, Operand bo) {
    Object a = ao.value;
    Object b = bo.value;
    if (a instanceof String || b instanceof String)
        throw new TMLExpressionException("Division not defined for strings");
    if (a instanceof Integer && b instanceof Integer)
        return Operand.ofInteger(Integer.valueOf(((Integer) a).intValue() / ((Integer) b).intValue()));
    double dA = Utils.getDoubleValue(a);
    double dB = Utils.getDoubleValue(b);
    return Operand.ofFloat(Double.valueOf(dA / dB));
}
Also used : TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 7 with TMLExpressionException

use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.

the class ASTForAllNode method interpret.

/**
 * FORALL(<EXPRESSION>, `[$x] <EXPRESSION>`) E.G.
 * FORALL([/ClubMembership/ClubMemberships/ClubIdentifier],
 * `CheckRelatieCode([$x])`)
 *
 * @return
 */
private final Operand interpret(Navajo doc, Message parentMsg, Message parentParamMsg, Selection parentSel, MappableTreeNode mapNode, TipiLink tipiLink, Access access, Optional<ImmutableMessage> immutableMessage, Optional<ImmutableMessage> paramMessage, ContextExpression a, ContextExpression b) {
    boolean matchAll = true;
    if (functionName.equals("FORALL"))
        matchAll = true;
    else
        matchAll = false;
    String msgList = (String) a.apply(doc, parentMsg, parentParamMsg, parentSel, mapNode, tipiLink, access, immutableMessage, paramMessage).value;
    try {
        List<Message> list = null;
        if (parentMsg == null) {
            list = doc.getMessages(msgList);
        } else {
            list = parentMsg.getMessages(msgList);
        }
        for (int i = 0; i < list.size(); i++) {
            Object o = list.get(i);
            parentMsg = (Message) o;
            // ignore definition messages in the evaluation
            if (parentMsg.getType().equals(Message.MSG_TYPE_DEFINITION))
                continue;
            Operand apply = b.apply(doc, parentMsg, parentParamMsg, parentSel, mapNode, tipiLink, access, immutableMessage, paramMessage);
            boolean result = (Boolean) apply.value;
            if ((!(result)) && matchAll)
                return Operand.ofBoolean(false);
            if ((result) && !matchAll)
                return Operand.ofBoolean(true);
        }
    } catch (NavajoException ne) {
        throw new TMLExpressionException("Invalid expression in FORALL construct: \n" + ne.getMessage());
    }
    return Operand.ofBoolean(matchAll);
}
Also used : Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Operand(com.dexels.navajo.document.Operand) NavajoException(com.dexels.navajo.document.NavajoException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 8 with TMLExpressionException

use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.

the class ASTForAllNode method interpretToLambda.

@Override
public ContextExpression interpretToLambda(List<String> problems, String expression, Function<String, FunctionClassification> functionClassifier, Function<String, Optional<Node>> mapResolver) {
    return new ContextExpression() {

        @Override
        public boolean isLiteral() {
            return false;
        }

        @Override
        public Operand apply(Navajo doc, Message parentMsg, Message parentParamMsg, Selection parentSel, MappableTreeNode mapNode, TipiLink tipiLink, Access access, Optional<ImmutableMessage> immutableMessage, Optional<ImmutableMessage> paramMessage) {
            List<String> problems = new ArrayList<>();
            ContextExpression a = jjtGetChild(0).interpretToLambda(problems, expression, functionClassifier, mapResolver);
            ContextExpression b = jjtGetChild(1).interpretToLambda(problems, expression, functionClassifier, mapResolver);
            if (!problems.isEmpty()) {
                throw new TMLExpressionException(problems, expression);
            }
            return interpret(doc, parentMsg, parentParamMsg, parentSel, mapNode, tipiLink, access, immutableMessage, paramMessage, a, b);
        }

        @Override
        public Optional<String> returnType() {
            return Optional.empty();
        }

        @Override
        public String expression() {
            return expression;
        }
    };
}
Also used : MappableTreeNode(com.dexels.navajo.script.api.MappableTreeNode) TipiLink(com.dexels.navajo.expression.api.TipiLink) Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Optional(java.util.Optional) Selection(com.dexels.navajo.document.Selection) ContextExpression(com.dexels.navajo.expression.api.ContextExpression) Access(com.dexels.navajo.script.api.Access) ArrayList(java.util.ArrayList) Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 9 with TMLExpressionException

use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.

the class Expression method match.

public static final Message match(String matchString, Navajo inMessage, MappableTreeNode o, Message parent) throws SystemException {
    try {
        StringTokenizer tokens = new StringTokenizer(matchString, ";");
        String matchSet = tokens.nextToken();
        if (matchSet == null)
            throw new TMLExpressionException("Invalid usage of match: match=\"[match set];[match value]\"");
        String matchValue = tokens.nextToken();
        if (matchValue == null)
            throw new TMLExpressionException("Invalid usage of match: match=\"[match set];[match value]\"");
        Operand value = evaluate(matchValue, inMessage, o, parent, null, null, null, null);
        List<Property> properties;
        if (parent == null)
            properties = inMessage.getProperties(matchSet);
        else
            properties = parent.getProperties(matchSet);
        for (int i = 0; i < properties.size(); i++) {
            Property prop = properties.get(i);
            Message parentMsg = prop.getParentMessage();
            if (prop.getValue().equals(value.value))
                return parentMsg;
        }
    } catch (NavajoException e) {
        throw new SystemException(-1, e.getMessage(), e);
    }
    return null;
}
Also used : StringTokenizer(java.util.StringTokenizer) Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) SystemException(com.dexels.navajo.script.api.SystemException) Operand(com.dexels.navajo.document.Operand) NavajoException(com.dexels.navajo.document.NavajoException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Property(com.dexels.navajo.document.Property)

Example 10 with TMLExpressionException

use of com.dexels.navajo.expression.api.TMLExpressionException in project navajo by Dexels.

the class Switch method testWithPropertyAndSingleValueParameter.

@Test
public void testWithPropertyAndSingleValueParameter() throws Exception {
    FunctionInterface fi = fff.getInstance(cl, "Switch");
    fi.reset();
    Navajo n = createTestNavajo();
    fi.setInMessage(n);
    fi.insertOperand(Expression.evaluate("[/Single/Vuur]", n));
    fi.insertIntegerOperand(0);
    try {
        Object result = fi.evaluate();
    } catch (TMLExpressionException tmle) {
        assertTrue(tmle.getMessage().indexOf("Not enough") != -1);
    }
}
Also used : FunctionInterface(com.dexels.navajo.expression.api.FunctionInterface) Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Test(org.junit.Test)

Aggregations

TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)129 Message (com.dexels.navajo.document.Message)26 Navajo (com.dexels.navajo.document.Navajo)26 Binary (com.dexels.navajo.document.types.Binary)23 Property (com.dexels.navajo.document.Property)17 ArrayList (java.util.ArrayList)16 Operand (com.dexels.navajo.document.Operand)15 List (java.util.List)13 NavajoException (com.dexels.navajo.document.NavajoException)12 IOException (java.io.IOException)12 Selection (com.dexels.navajo.document.Selection)11 Access (com.dexels.navajo.script.api.Access)10 Calendar (java.util.Calendar)10 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)9 Test (org.junit.Test)9 Money (com.dexels.navajo.document.types.Money)8 SystemException (com.dexels.navajo.script.api.SystemException)8 StringTokenizer (java.util.StringTokenizer)8 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)7 ClockTime (com.dexels.navajo.document.types.ClockTime)7