Search in sources :

Example 96 with Message

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

the class MessageMapTest method test.

@Test
public void test() throws Exception {
    Navajo n = NavajoFactory.getInstance().createNavajo();
    Message array = NavajoFactory.getInstance().createMessage(n, "Array");
    n.addMessage(array);
    array.setType(Message.MSG_TYPE_ARRAY);
    for (int i = 0; i < 10; i++) {
        Message c = NavajoFactory.getInstance().createMessage(n, "Array");
        array.addElement(c);
        if (i % 2 == 0) {
            Property p1 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
            Property p1a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Laptop", 0, "", "out");
            Property p2 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, (i * 10) + "", 0, "", "out");
            String d3 = "2012-01-" + ((i + 1) < 10 ? "0" + (i + 1) : i);
            Property p3 = NavajoFactory.getInstance().createProperty(n, "Date", Property.DATE_PROPERTY, d3, 0, "", "out");
            Property p4 = NavajoFactory.getInstance().createProperty(n, "Gender", "1", "Geslacht", "");
            p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Man", "Man", false));
            p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Vrouw", "Vrouw", true));
            c.addProperty(p1);
            c.addProperty(p1a);
            c.addProperty(p2);
            c.addProperty(p3);
            c.addProperty(p4);
            if (i % 4 == 0) {
                Property p5 = NavajoFactory.getInstance().createProperty(n, "City", Property.STRING_PROPERTY, "Amsterdam", 0, "", "out");
                c.addProperty(p5);
            } else {
                Property p5 = NavajoFactory.getInstance().createProperty(n, "City", Property.STRING_PROPERTY, "Leiden", 0, "", "out");
                c.addProperty(p5);
            }
        } else {
            Property p1 = NavajoFactory.getInstance().createProperty(n, "Product", Property.STRING_PROPERTY, "PC", 0, "", "out");
            Property p1a = NavajoFactory.getInstance().createProperty(n, "Sub", Property.STRING_PROPERTY, "Desktop", 0, "", "out");
            Property p2 = NavajoFactory.getInstance().createProperty(n, "Age", Property.INTEGER_PROPERTY, (i * 20) + "", 0, "", "out");
            String d3 = "2012-01-" + ((i + 1) < 10 ? "0" + (i + 1) : (i + 1));
            Property p3 = NavajoFactory.getInstance().createProperty(n, "Date", Property.DATE_PROPERTY, d3, 0, "", "out");
            Property p4 = NavajoFactory.getInstance().createProperty(n, "Gender", "1", "Geslacht", "");
            p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Man", "Man", true));
            p4.addSelection(NavajoFactory.getInstance().createSelection(n, "Vrouw", "Vrouw", true));
            c.addProperty(p1);
            c.addProperty(p1a);
            c.addProperty(p2);
            c.addProperty(p3);
            c.addProperty(p4);
            if (i % 4 == 1) {
                Property p5 = NavajoFactory.getInstance().createProperty(n, "City", Property.STRING_PROPERTY, "Leiden", 0, "", "out");
                c.addProperty(p5);
            } else {
                // Undo the double selected for the 4x + 3 rows
                p4.setSelected("Man");
                Property p5 = NavajoFactory.getInstance().createProperty(n, "City", Property.STRING_PROPERTY, "Hoorn", 0, "", "out");
                c.addProperty(p5);
            }
        }
    }
    n.write(System.err);
    Access a = new Access();
    a.setOutputDoc(n);
    MessageMap mm = new MessageMap();
    mm.load(a);
    mm.setGroupBy("Product,Sub");
    mm.setJoinMessage1("Array");
    mm.setJoinType("outer");
    // mm.setRemoveSource(true);
    Message resultMessage = NavajoFactory.getInstance().createMessage(n, "ResultingMessage");
    resultMessage.setType("array");
    n.addMessage(resultMessage);
    a.setCurrentOutMessage(resultMessage);
    ResultMessage[] result = mm.getResultMessage();
    // for (int i = 0; i < result.length; i++) {
    // result[i].load(a);
    // result[i].getMsg().write(System.err);
    // System.err.println("Count: " + result[i].getCount("Age"));
    // System.err.println("Sum: " + result[i].getSum("Age"));
    // System.err.println("Average: " + result[i].getAvg("Age"));
    // result[i].store();
    // }
    a.setCurrentOutMessage(null);
    mm.store();
    assertEquals(2, result.length);
    assertEquals(5, result[0].getCount("Age"));
    assertEquals(200.0, result[0].getSum("Age"), 1);
    assertEquals(500.0, result[1].getSum("Age"), 1);
    assertEquals(40.0, result[0].getAvg("Age"), 1);
    assertEquals(100.0, result[1].getAvg("Age"), 1);
    assertEquals(80.0, result[0].getMax("Age"));
    assertEquals(0.0, result[0].getMin("Age"));
    assertEquals(180.0, result[1].getMax("Age"));
    assertEquals(20.0, result[1].getMin("Age"));
    assertEquals(new SimpleDateFormat("yyyy-MM-dd").parseObject("2012-01-01"), result[0].getMin("Date"));
    assertEquals(new SimpleDateFormat("yyyy-MM-dd").parseObject("2012-01-02"), result[1].getMin("Date"));
    assertEquals(new SimpleDateFormat("yyyy-MM-dd").parseObject("2012-01-09"), result[0].getMax("Date"));
    assertEquals(new SimpleDateFormat("yyyy-MM-dd").parseObject("2012-01-10"), result[1].getMax("Date"));
    assertEquals("Amsterdam", result[0].getAny("City"));
    assertEquals("Leiden", result[1].getAny("City"));
    assertEquals("Amsterdam;Leiden;Amsterdam;Leiden;Amsterdam", result[0].getConcatenated("City"));
    assertEquals("Leiden;Hoorn;Leiden;Hoorn;Leiden", result[1].getConcatenated("City"));
    assertEquals("Vrouw", result[0].getAny("Gender").toString());
    assertEquals("Man,Vrouw", result[1].getAny("Gender").toString());
    assertEquals("Vrouw;Vrouw;Vrouw;Vrouw;Vrouw", result[0].getConcatenated("Gender"));
    assertEquals("Man;Vrouw;Man;Man;Vrouw;Man;Man;Vrouw", result[1].getConcatenated("Gender"));
}
Also used : Message(com.dexels.navajo.document.Message) ResultMessage(com.dexels.navajo.adapter.messagemap.ResultMessage) Access(com.dexels.navajo.script.api.Access) Navajo(com.dexels.navajo.document.Navajo) ResultMessage(com.dexels.navajo.adapter.messagemap.ResultMessage) Property(com.dexels.navajo.document.Property) SimpleDateFormat(java.text.SimpleDateFormat) Test(org.junit.Test)

Example 97 with Message

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

the class TestNavajoMap method testSendThroughSetTrue.

@Test
public void testSendThroughSetTrue() throws MappableException, UserException {
    Navajo inDoc = NavajoFactory.getInstance().createNavajo();
    Property property = NavajoFactory.getInstance().createProperty(inDoc, "Meaning", INTEGER_PROPERTY, "42", 0, "", "out");
    Message message = NavajoFactory.getInstance().createMessage(inDoc, "SendThrough");
    message.addProperty(property);
    inDoc.addMessage(message);
    Message global = NavajoFactory.getInstance().createMessage(inDoc, "Global");
    global.setScope(Message.MSG_SCOPE_GLOBAL);
    inDoc.addMessage(global);
    Message local = NavajoFactory.getInstance().createMessage(inDoc, "Local");
    local.setScope(Message.MSG_SCOPE_LOCAL);
    inDoc.addMessage(local);
    // Initialize the navajomap.
    DispatcherFactory.createDispatcher(new Dispatcher());
    Access access = new Access();
    access.setInDoc(inDoc);
    access.setOutputDoc(outDoc);
    map.load(access);
    map.setSendThrough(true);
    map.prepareOutDoc();
    assertTrue(map.getSendThrough());
    assertEquals("42", map.outDoc.getMessage("SendThrough").getProperty("Meaning").getValue());
    assertEquals(Message.MSG_SCOPE_GLOBAL, map.outDoc.getMessage("Global").getScope());
    assertNull(map.outDoc.getMessage("Local"));
}
Also used : Message(com.dexels.navajo.document.Message) Access(com.dexels.navajo.script.api.Access) Navajo(com.dexels.navajo.document.Navajo) Dispatcher(com.dexels.navajo.server.Dispatcher) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Example 98 with Message

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

the class MessageMap method getMessages.

public MessageMap[] getMessages() throws UserException {
    try {
        List<Message> all = msg.getMessages(messagePointer);
        if ((all == null))
            throw new UserException(-1, "Could not find messages: " + messagePointer + " in response document (" + msg.getName() + ")");
        messages = new MessageMap[all.size()];
        for (int i = 0; i < all.size(); i++) {
            MessageMap m = new MessageMap();
            m.setMsg(all.get(i));
            messages[i] = m;
        }
        return messages;
    } catch (Exception e) {
        throw new UserException(-1, e.getMessage());
    }
}
Also used : Message(com.dexels.navajo.document.Message) UserException(com.dexels.navajo.script.api.UserException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException) NavajoException(com.dexels.navajo.document.NavajoException)

Example 99 with Message

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

the class MessageMap method getMessage.

public MessageMap getMessage() throws UserException {
    Message m = msg.getMessage(messagePointer);
    if (m == null)
        throw new UserException(-1, "Could not find message: " + messagePointer + " in response document (" + msg.getName() + ")");
    else {
        MessageMap mm = new MessageMap();
        mm.setMsg(m);
        return mm;
    }
}
Also used : Message(com.dexels.navajo.document.Message) UserException(com.dexels.navajo.script.api.UserException)

Example 100 with Message

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

the class TmlToXmlMap method appendMessages.

private final void appendMessages(Message m, TagMap parent) throws UserException {
    if (!m.getMode().equals(Message.MSG_MODE_IGNORE)) {
        // Check for array messages. Only append array children
        TagMap child;
        if (!m.getType().equals(Message.MSG_TYPE_ARRAY)) {
            child = new TagMap();
            child.setCompact(true);
            child.setName(m.getName());
            parent.setChild(child);
        } else {
            child = parent;
        }
        List<Property> allProperties = m.getAllProperties();
        for (int i = 0; i < allProperties.size(); i++) {
            appendProperty(allProperties.get(i), child);
        }
        List<Message> allMessages = m.getAllMessages();
        for (int i = 0; i < allMessages.size(); i++) {
            appendMessages(allMessages.get(i), child);
        }
    }
}
Also used : Message(com.dexels.navajo.document.Message) Property(com.dexels.navajo.document.Property) TagMap(com.dexels.navajo.adapter.xmlmap.TagMap)

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