Search in sources :

Example 36 with Navajo

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

the class MergeNavajo method evaluate.

@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    Object a = this.getOperands().get(0);
    Object b = this.getOperands().get(1);
    try {
        Navajo slave = (Navajo) a;
        Navajo result = slave.copy();
        Navajo master = (Navajo) b;
        return result.merge(master);
    } catch (Exception e) {
        throw new TMLExpressionException(this, "Illegal type specified in MergeNavajo() function: " + e.getMessage(), e);
    }
}
Also used : Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 37 with Navajo

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

the class EvaluateParameters method main.

public static void main(String[] args) throws Exception {
    // Navajo n = NavajoFactory.getInstance().createNavajo();
    // Message noot = NavajoFactory.getInstance().createMessage(n, "Noot");
    // 
    // n.addMessage(noot);
    // noot.addProperty(ai);
    String expression = "test [/mies/ActivityId]";
    Navajo m = NavajoFactory.getInstance().createNavajo();
    Message mies = NavajoFactory.getInstance().createMessage(m, "mies");
    Property ai = NavajoFactory.getInstance().createProperty(m, "ActivityId", "string", "4792834", 10, "Ac", "in");
    mies.addProperty(ai);
    Property p = NavajoFactory.getInstance().createProperty(m, "exp", "string", expression, 10, "Ac", "in");
    m.addMessage(mies);
    mies.addProperty(p);
    System.err.println(Expression.evaluate("EvaluateParameters([/mies/exp])", m).value);
/*
		EvaluateParameters ce = new EvaluateParameters();
		ce.reset();
		ce.currentMessage = noot;	
		ce.insertOperand(Expression.evaluate("[/mies/exp]", m).value);
		String result = (String) ce.evaluate();
		System.err.println("result:");
		System.err.println(result);*/
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property)

Example 38 with Navajo

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

the class ExistsProperty method evaluate.

@Override
public Object evaluate() throws TMLExpressionException {
    if (getOperands().size() != 1) {
        throw new TMLExpressionException(this, "Invalid function call");
    }
    Object o = getOperand(0);
    if (!(o instanceof String)) {
        throw new TMLExpressionException(this, "Invalid function call");
    }
    Navajo in = getNavajo();
    return (in.getProperty((String) o) != null);
}
Also used : Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 39 with Navajo

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

the class ForAll method evaluate.

@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    /**
     *@todo Implement this com.dexels.navajo.parser.FunctionInterface abstract method
     */
    Message arrayMessage = null;
    String messagePath = null;
    if (getOperand(0) instanceof Message) {
        arrayMessage = (Message) getOperand(0);
    } else {
        messagePath = (String) getOperand(0);
    }
    String expression = (String) getOperand(1);
    String filter = null;
    if (getOperands().size() > 2) {
        filter = (String) getOperand(2);
    }
    Message parent = getCurrentMessage();
    Navajo doc = getNavajo();
    // try {
    try {
        List<Message> arrayMsg = null;
        if (arrayMessage != null) {
            arrayMsg = arrayMessage.getAllMessages();
        } else {
            arrayMsg = (parent != null ? parent.getMessages(messagePath) : doc.getMessages(messagePath));
        }
        if (arrayMsg == null) {
            throw new TMLExpressionException(this, "Empty or non existing array message: " + messagePath);
        }
        for (int i = 0; i < arrayMsg.size(); i++) {
            Message current = arrayMsg.get(i);
            try {
                boolean evaluate = (filter != null ? Condition.evaluate(filter, doc, null, current, getAccess()) : true);
                if (evaluate) {
                    Operand result = Expression.evaluate(expression, doc, null, current);
                    if (result == null) {
                        throw new TMLExpressionException(this, "Error evaluating expression: " + expression + " in message: " + current.getFullMessageName());
                    }
                    if (result.value == null) {
                        throw new TMLExpressionException(this, "Error evaluating expression: " + expression + " in message: " + current.getFullMessageName());
                    }
                    String res2 = "" + result.value;
                    Operand result2 = Expression.evaluate(res2, doc, null, current);
                    if (result2 == null) {
                        throw new TMLExpressionException(this, "Error evaluating expression: " + res2 + " in message: " + current.getFullMessageName());
                    }
                    if (result2.value == null) {
                        throw new TMLExpressionException(this, "Error evaluating expression: " + res2 + " in message: " + current.getFullMessageName());
                    }
                    boolean res = ((Boolean) result2.value).booleanValue();
                    if (!res) {
                        return Boolean.FALSE;
                    }
                }
            } catch (SystemException ex) {
                logger.error("Error: ", ex);
            }
        }
    } catch (NavajoException ex) {
        throw new TMLExpressionException(this, "Error evaluating message path");
    }
    return Boolean.TRUE;
}
Also used : Message(com.dexels.navajo.document.Message) SystemException(com.dexels.navajo.script.api.SystemException) Operand(com.dexels.navajo.document.Operand) NavajoException(com.dexels.navajo.document.NavajoException) Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Example 40 with Navajo

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

the class GetPropertyValue method evaluate.

@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    if (getOperands().size() != 2) {
        throw new TMLExpressionException(this, "Invalid function call");
    }
    Object m = operand(0).value;
    ;
    if (m == null) {
        throw new TMLExpressionException(this, "Message or navajo argument expected. This one is null");
    }
    // Object o = getOperand(1);
    // if (!(o instanceof String)) {
    // throw new TMLExpressionException(this, "String argument expected");
    // }
    String propertyName = getStringOperand(1);
    if (!(m instanceof Message) && !(m instanceof Navajo)) {
        throw new TMLExpressionException(this, "Message or navajo argument expected");
    }
    if (m instanceof Navajo) {
        Navajo n = (Navajo) m;
        return n.getProperty(propertyName).getTypedValue();
    }
    if (m instanceof Message) {
        Message message = (Message) m;
        return message.getProperty(propertyName).getTypedValue();
    }
    return null;
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException)

Aggregations

Navajo (com.dexels.navajo.document.Navajo)258 Message (com.dexels.navajo.document.Message)131 Test (org.junit.Test)109 Property (com.dexels.navajo.document.Property)86 NavajoException (com.dexels.navajo.document.NavajoException)31 Access (com.dexels.navajo.script.api.Access)30 IOException (java.io.IOException)28 StringWriter (java.io.StringWriter)27 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 FunctionInterface (com.dexels.navajo.expression.api.FunctionInterface)25 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)22 Selection (com.dexels.navajo.document.Selection)22 Header (com.dexels.navajo.document.Header)20 Operand (com.dexels.navajo.document.Operand)20 InputStream (java.io.InputStream)17 UserException (com.dexels.navajo.script.api.UserException)16 Optional (java.util.Optional)16 FatalException (com.dexels.navajo.script.api.FatalException)14 SystemException (com.dexels.navajo.script.api.SystemException)14 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)13