Search in sources :

Example 86 with Operand

use of com.dexels.navajo.document.Operand in project navajo by Dexels.

the class CallService method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    Operand result = null;
    String serviceName = getStringOperand(0);
    String expression = getOperands().size() == 1 ? null : getStringOperand(1);
    if (getNavajo() == null) {
        throw new TMLExpressionException("No Navajo Request object available.");
    }
    if (getOperands().size() > 2) {
        throw new TMLExpressionException("Invalid number of parameters.");
    }
    try {
        Navajo response = getNavajo().getNavajo(serviceName);
        if (response == null) {
            DispatcherInterface dispatcher = DispatcherFactory.getInstance();
            Navajo input = getNavajo().copy();
            input.getHeader().setRPCName(serviceName);
            response = dispatcher.handle(input, this.getAccess().getTenant(), true);
            getNavajo().addNavajo(serviceName, response);
        }
        if (expression == null) {
            Binary bbb = new Binary();
            OutputStream os = bbb.getOutputStream();
            response.write(os);
            os.flush();
            os.close();
            return bbb;
        } else {
            result = Expression.evaluate(expression, response);
        }
    } catch (Exception ex) {
        logger.error("Error: ", ex);
    }
    if (result != null) {
        return result.value;
    } else {
        return null;
    }
}
Also used : DispatcherInterface(com.dexels.navajo.server.DispatcherInterface) Operand(com.dexels.navajo.document.Operand) OutputStream(java.io.OutputStream) Navajo(com.dexels.navajo.document.Navajo) Binary(com.dexels.navajo.document.types.Binary) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 87 with Operand

use of com.dexels.navajo.document.Operand in project navajo by Dexels.

the class EvaluateExpression method evaluate.

@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    if (getOperands().size() != 1 && getOperands().size() != 3) {
        throw new TMLExpressionException("Wrong number of arguments");
    }
    Navajo currentNavajo = this.getNavajo();
    Message currentMessage = this.getCurrentMessage();
    Operand result = null;
    boolean conditional = (this.getOperands().size() == 3);
    if (!conditional) {
        String expression = (String) getOperand(0);
        try {
            result = Expression.evaluate(expression, currentNavajo, null, currentMessage, null, null, null, null);
        } catch (TMLExpressionException ex) {
            logger.error("Error: ", ex);
        }
    } else {
        String condition = (String) getOperand(0);
        String exp1 = (String) getOperand(1);
        String exp2 = (String) getOperand(2);
        try {
            if (Condition.evaluate(condition, currentNavajo, null, currentMessage, getAccess())) {
                result = Expression.evaluate(exp1, currentNavajo, null, currentMessage, null, null, null, null);
            } else {
                result = Expression.evaluate(exp2, currentNavajo, null, currentMessage, null, null, null, null);
            }
        } catch (SystemException ex1) {
            logger.error("Error: ", ex1);
            throw new TMLExpressionException(this, ex1.getMessage());
        } catch (TMLExpressionException ex1) {
            logger.error("Error: ", ex1);
            throw new TMLExpressionException(this, ex1.getMessage());
        }
    }
    if (result != null) {
        return result.value;
    } else {
        return null;
    }
}
Also used : Message(com.dexels.navajo.document.Message) SystemException(com.dexels.navajo.script.api.SystemException) Operand(com.dexels.navajo.document.Operand) Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 88 with Operand

use of com.dexels.navajo.document.Operand in project navajo by Dexels.

the class ParseStringList method main.

public static void main(String[] args) throws Exception {
    String expression = "Contains(ParseStringList('CLUBFUNCTION,UNIONFUNCTION,2',','), 'FUNCTION'))";
    Operand o = Expression.evaluate(expression, null);
    System.err.println("o = " + o.value);
}
Also used : Operand(com.dexels.navajo.document.Operand)

Example 89 with Operand

use of com.dexels.navajo.document.Operand in project navajo by Dexels.

the class Size method main.

public static void main(String[] args) throws Exception {
    Navajo n = NavajoFactory.getInstance().createNavajo();
    Message m = NavajoFactory.getInstance().createMessage(n, "Aap");
    n.addMessage(m);
    Property p = NavajoFactory.getInstance().createProperty(n, "Selection", "+", "", "out");
    m.addProperty(p);
    Selection s = NavajoFactory.getInstance().createSelection(n, "Aap", "0", false);
    p.addSelection(s);
    n.write(System.err);
    Operand o = Expression.evaluate("GetPropertyType('/Aap/Selection') == 'selection' AND Size([Aap/Selection]) == 0", n);
    System.err.println("o " + o.value + ", type: " + o.type);
}
Also used : Message(com.dexels.navajo.document.Message) Selection(com.dexels.navajo.document.Selection) Operand(com.dexels.navajo.document.Operand) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property)

Example 90 with Operand

use of com.dexels.navajo.document.Operand in project navajo by Dexels.

the class ToClockTime method main.

public static void main(String[] args) throws Exception {
    // Tests.
    ToClockTime cct = new ToClockTime();
    cct.reset();
    cct.insertStringOperand("12");
    System.out.println("cct = " + cct.evaluate());
    String expr = "ToClockTime('09:00') + ToClockTime('10')";
    Operand o = Expression.evaluate(expr, null);
    System.out.println("9:00 > 10:00 ? " + o.value + ", ToClockTime('25:88') = " + new ClockTime("25:88").toString());
    expr = "ToClockTime('9') >= ToClockTime('9')";
    Operand o2 = Expression.evaluate(expr, null);
    System.out.println("9:00 >= 9:00 ? " + o2.value);
    expr = "ToClockTime('9') < ToClockTime('12')";
    Operand o3 = Expression.evaluate(expr, null);
    System.out.println("9:00 < 12:00 ? " + o3.value);
}
Also used : Operand(com.dexels.navajo.document.Operand) ClockTime(com.dexels.navajo.document.types.ClockTime)

Aggregations

Operand (com.dexels.navajo.document.Operand)95 Test (org.junit.Test)57 Message (com.dexels.navajo.document.Message)22 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)20 Navajo (com.dexels.navajo.document.Navajo)20 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)15 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)14 ArrayList (java.util.ArrayList)12 Selection (com.dexels.navajo.document.Selection)11 Property (com.dexels.navajo.document.Property)10 FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)10 Access (com.dexels.navajo.script.api.Access)10 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)10 NavajoException (com.dexels.navajo.document.NavajoException)9 TipiLink (com.dexels.navajo.expression.api.TipiLink)9 Optional (java.util.Optional)9 FunctionDefinition (com.dexels.navajo.expression.api.FunctionDefinition)8 GiveLongTestFunction (com.dexels.navajo.expression.compiled.GiveLongTestFunction)6 SystemException (com.dexels.navajo.script.api.SystemException)6 List (java.util.List)6