Search in sources :

Example 26 with Message

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

the class NavajoStreamToMutableMessageStream method processNavajoEvent.

public Flowable<Message> processNavajoEvent(NavajoStreamEvent n) {
    switch(n.type()) {
        case NAVAJO_STARTED:
            return Flowable.empty();
        case MESSAGE_STARTED:
            Message prMessage = null;
            if (!messageStack.isEmpty()) {
                prMessage = messageStack.peek();
            }
            String mode = (String) n.attribute("mode");
            Message msg = NavajoFactory.getInstance().createMessage(null, n.path(), Message.MSG_TYPE_SIMPLE);
            msg.setMode(mode);
            if (prMessage == null) {
            // assemble.addMessage(msg);
            // currentMessage.set(msg);
            } else {
                prMessage.addMessage(msg);
            }
            messageStack.push(msg);
            tagStack.push(n.path());
            return Flowable.empty();
        case MESSAGE:
            // if(messageStack.isEmpty())
            Message msgParent = null;
            if (messageStack.isEmpty()) {
                msgParent = NavajoFactory.getInstance().createMessage(null, n.path(), Message.MSG_TYPE_SIMPLE);
            } else {
                msgParent = messageStack.pop();
            }
            Msg mm = (Msg) n.body();
            List<Prop> msgProps = mm.properties();
            for (Prop e : msgProps) {
                msgParent.addProperty(createTmlProperty(e));
            }
            if (emitStack()) {
                tagStack.pop();
                return Flowable.just(msgParent);
            }
            tagStack.pop();
            return Flowable.empty();
        case ARRAY_STARTED:
            tagStack.push(n.path());
            Message parentMessage = null;
            if (!messageStack.isEmpty()) {
                parentMessage = messageStack.peek();
            }
            Message arr = NavajoFactory.getInstance().createMessage(null, n.path(), Message.MSG_TYPE_ARRAY);
            if (parentMessage == null) {
            // assemble.addMessage(arr);
            } else {
                parentMessage.addMessage(arr);
            }
            messageStack.push(arr);
            return Flowable.empty();
        case ARRAY_DONE:
            // String apath = currentPath();
            // arrayCounts.remove(apath);
            this.messageStack.pop();
            return Flowable.empty();
        case ARRAY_ELEMENT_STARTED:
            String arrayElementName = tagStack.peek();
            Message newElt = NavajoFactory.getInstance().createMessage(null, arrayElementName, Message.MSG_TYPE_ARRAY_ELEMENT);
            Message arrParent = messageStack.peek();
            arrParent.addElement(newElt);
            messageStack.push(newElt);
            return Flowable.empty();
        case ARRAY_ELEMENT:
            Message elementParent = messageStack.pop();
            Msg msgElement = (Msg) n.body();
            List<Prop> elementProps = msgElement.properties();
            for (Prop e : elementProps) {
                elementParent.addProperty(createTmlProperty(e));
            }
            if (emitStack()) {
                // tagStack.pop();
                return Flowable.just(elementParent);
            }
            // tagStack.pop();
            return Flowable.empty();
        case MESSAGE_DEFINITION_STARTED:
            return Flowable.empty();
        case MESSAGE_DEFINITION:
            // deferredMessages.get(stripIndex(n.path())).setDefinitionMessage((Message) n.body());
            return Flowable.empty();
        case NAVAJO_DONE:
            return Flowable.empty();
        default:
            return Flowable.empty();
    }
}
Also used : Msg(com.dexels.navajo.document.stream.api.Msg) Message(com.dexels.navajo.document.Message) Prop(com.dexels.navajo.document.stream.api.Prop)

Example 27 with Message

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

the class ExpressionTest method setup.

@Before
public void setup() {
    NavajoFactory.getInstance().setExpressionEvaluator(new CachedExpressionEvaluator());
    testDoc = NavajoFactory.getInstance().createNavajo();
    topMessage = NavajoFactory.getInstance().createMessage(testDoc, "MyTop");
    testDoc.addMessage(topMessage);
    Property pt = NavajoFactory.getInstance().createProperty(testDoc, "TopProp", "1", "", Property.DIR_IN);
    testSelection = NavajoFactory.getInstance().createSelection(testDoc, "option1", "value1", true);
    pt.addSelection(testSelection);
    topMessage.addProperty(pt);
    Message a = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage", "array");
    topMessage.addMessage(a);
    for (int i = 0; i < 5; i++) {
        Message a1 = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage");
        a.addMessage(a1);
        Property p = NavajoFactory.getInstance().createProperty(testDoc, "MyProp", "string", "noot" + i, 0, "", "in");
        a1.addProperty(p);
        Property p2 = NavajoFactory.getInstance().createProperty(testDoc, "MyProp2", "string", "aap" + i, 0, "", "in");
        a1.addProperty(p2);
    }
    Map<String, Object> values = new HashMap<>();
    Map<String, String> types = new HashMap<>();
    values.put("SomeString", "Tralala");
    types.put("SomeString", "string");
    values.put("SomeInteger", 3);
    types.put("SomeInteger", "integer");
    immutableMessage = ReplicationFactory.createReplicationMessage(Optional.empty(), Optional.empty(), Optional.empty(), null, 0, Operation.NONE, Collections.emptyList(), types, values, Collections.emptyMap(), Collections.emptyMap(), Optional.empty(), Optional.empty()).message();
    Map<String, Object> valueparams = new HashMap<>();
    Map<String, String> typeparams = new HashMap<>();
    valueparams.put("SomeString", "Tralala2");
    typeparams.put("SomeString", "string");
    valueparams.put("SomeInteger", 4);
    typeparams.put("SomeInteger", "integer");
    paramMessage = ReplicationFactory.createReplicationMessage(Optional.empty(), Optional.empty(), Optional.empty(), null, 0, Operation.NONE, Collections.emptyList(), typeparams, valueparams, Collections.emptyMap(), Collections.emptyMap(), Optional.empty(), Optional.empty()).message();
}
Also used : ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Message(com.dexels.navajo.document.Message) HashMap(java.util.HashMap) CachedExpressionEvaluator(com.dexels.navajo.parser.compiled.api.CachedExpressionEvaluator) Property(com.dexels.navajo.document.Property) Before(org.junit.Before)

Example 28 with Message

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

the class ExpressionTest method testExpression.

@Test
public void testExpression() throws Exception {
    ExpressionEvaluator ee = NavajoFactory.getInstance().getExpressionEvaluator();
    Operand o = ee.evaluate("1+1", null, null, null);
    assertEquals(2, o.value);
    o = ee.evaluate("TODAY + 0#0#2#0#0#0", null, null, null);
    System.err.println(o.value);
    Navajo testDoc = NavajoFactory.getInstance().createNavajo();
    Message m = NavajoFactory.getInstance().createMessage(testDoc, "MyTop");
    testDoc.addMessage(m);
    Message a = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage", "array");
    m.addMessage(a);
    for (int i = 0; i < 5; i++) {
        Message a1 = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage");
        a.addMessage(a1);
        Property p = NavajoFactory.getInstance().createProperty(testDoc, "MyProp", "string", "noot" + i, 0, "", "in");
        a1.addProperty(p);
        Property p2 = NavajoFactory.getInstance().createProperty(testDoc, "MyProp2", "string", "aap" + i, 0, "", "in");
        a1.addProperty(p2);
    }
    o = ee.evaluate("'hallo:' + [/MyTop/MyArrayMessage@MyProp=noot1/MyProp2]", testDoc, null, null);
    assertEquals("hallo:aap1", o.value);
    o = ee.evaluate("'hallo:' + [/MyTop/MyArrayMessage@2/MyProp2]", testDoc, null, null);
    assertEquals("hallo:aap2", o.value);
}
Also used : ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Message(com.dexels.navajo.document.Message) Operand(com.dexels.navajo.document.Operand) Navajo(com.dexels.navajo.document.Navajo) ExpressionEvaluator(com.dexels.navajo.document.ExpressionEvaluator) CachedExpressionEvaluator(com.dexels.navajo.parser.compiled.api.CachedExpressionEvaluator) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Example 29 with Message

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

the class Exists 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.TRUE;
                    }
                }
            } catch (SystemException ex) {
                logger.error("Error: ", ex);
            }
        }
    } catch (NavajoException ex) {
        throw new TMLExpressionException(this, "Error evaluating message path");
    }
    return Boolean.FALSE;
}
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 30 with Message

use of com.dexels.navajo.document.Message 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)

Aggregations

Message (com.dexels.navajo.document.Message)312 Property (com.dexels.navajo.document.Property)149 Navajo (com.dexels.navajo.document.Navajo)127 Test (org.junit.Test)95 NavajoException (com.dexels.navajo.document.NavajoException)39 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)35 Access (com.dexels.navajo.script.api.Access)27 UserException (com.dexels.navajo.script.api.UserException)27 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 Selection (com.dexels.navajo.document.Selection)25 Operand (com.dexels.navajo.document.Operand)22 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)19 MappableException (com.dexels.navajo.script.api.MappableException)18 Ignore (org.junit.Ignore)17 SystemException (com.dexels.navajo.script.api.SystemException)16 Optional (java.util.Optional)15 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)13 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)13 HashMap (java.util.HashMap)13