Search in sources :

Example 6 with ResultMessage

use of com.dexels.navajo.adapter.messagemap.ResultMessage in project navajo by Dexels.

the class TestAdapters method testMessageMap.

// TODO Add asserts
@Test
public void testMessageMap() throws UserException, MappableException {
    Navajo out = NavajoFactory.getInstance().createNavajo();
    Message msg1 = NavajoFactory.getInstance().createMessage(out, "message1");
    msg1.setType("array");
    Message msg2 = NavajoFactory.getInstance().createMessage(out, "message2");
    msg2.setType("array");
    out.addMessage(msg1);
    out.addMessage(msg2);
    for (int i = 0; i < 4; i++) {
        Message m1 = NavajoFactory.getInstance().createMessage(out, "message1");
        Message m2 = NavajoFactory.getInstance().createMessage(out, "message2");
        msg1.addMessage(m1);
        msg2.addMessage(m2);
        Property p;
        p = NavajoFactory.getInstance().createProperty(out, "propje1", Property.STRING_PROPERTY, "" + 3 * i, 0, "", "");
        m1.addProperty(p);
        p = NavajoFactory.getInstance().createProperty(out, "propje2", Property.STRING_PROPERTY, "" + 8 * i, 0, "", "");
        m1.addProperty(p);
        p = NavajoFactory.getInstance().createProperty(out, "propje3", Property.STRING_PROPERTY, "propjes" + 23 * i, 0, "", "");
        m1.addProperty(p);
        p = NavajoFactory.getInstance().createProperty(out, "blieblab", Property.STRING_PROPERTY, "" + 3 * i, 0, "", "");
        m2.addProperty(p);
        p = NavajoFactory.getInstance().createProperty(out, "apenoot2", Property.STRING_PROPERTY, "apenoot" + 8 * i, 0, "", "");
        m2.addProperty(p);
        p = NavajoFactory.getInstance().createProperty(out, "apfelkorn", Property.STRING_PROPERTY, "apfelkorn" + 23 * i, 0, "", "");
        m2.addProperty(p);
    }
    Property p;
    Message m1 = NavajoFactory.getInstance().createMessage(out, "message1");
    msg1.addMessage(m1);
    p = NavajoFactory.getInstance().createProperty(out, "propje1", Property.STRING_PROPERTY, "343", 0, "", "");
    m1.addProperty(p);
    p = NavajoFactory.getInstance().createProperty(out, "propje2", Property.STRING_PROPERTY, "12321", 0, "", "");
    m1.addProperty(p);
    p = NavajoFactory.getInstance().createProperty(out, "propje3", Property.STRING_PROPERTY, "propjes2321", 0, "", "");
    m1.addProperty(p);
    // Additional m2.
    Message m2 = NavajoFactory.getInstance().createMessage(out, "message2");
    msg2.addMessage(m2);
    p = NavajoFactory.getInstance().createProperty(out, "blieblab", Property.STRING_PROPERTY, "0", 0, "", "");
    m2.addProperty(p);
    p = NavajoFactory.getInstance().createProperty(out, "apenoot2", Property.STRING_PROPERTY, "12321", 0, "", "");
    m2.addProperty(p);
    p = NavajoFactory.getInstance().createProperty(out, "apfelkorn", Property.STRING_PROPERTY, "propjes2321", 0, "", "");
    m2.addProperty(p);
    Access a = new Access();
    a.setOutputDoc(out);
    MessageMap mm = new MessageMap();
    mm.load(a);
    mm.setSuppressProperties("propje3");
    mm.setJoinMessage1("message1");
    mm.setJoinMessage2("message2");
    mm.setJoinCondition("propje1=blieblab");
    mm.setJoinType("inner");
    Message resultMessage = NavajoFactory.getInstance().createMessage(out, "ResultingMessage");
    resultMessage.setType("array");
    out.addMessage(resultMessage);
    a.setCurrentOutMessage(resultMessage);
    ResultMessage[] result = mm.getResultMessage();
    for (int i = 0; i < result.length; i++) {
        Message resultElementMessage = NavajoFactory.getInstance().createMessage(out, "ResultingMessage");
        resultElementMessage.setType("array_element");
        resultMessage.addElement(resultElementMessage);
        a.setCurrentOutMessage(resultElementMessage);
        result[i].load(a);
        result[i].store();
    }
    a.setCurrentOutMessage(null);
    mm.store();
}
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) Test(org.junit.Test)

Aggregations

ResultMessage (com.dexels.navajo.adapter.messagemap.ResultMessage)6 Message (com.dexels.navajo.document.Message)6 Navajo (com.dexels.navajo.document.Navajo)6 Property (com.dexels.navajo.document.Property)6 Access (com.dexels.navajo.script.api.Access)5 Test (org.junit.Test)5 PropertyAggregate (com.dexels.navajo.adapter.messagemap.PropertyAggregate)1 NavajoException (com.dexels.navajo.document.NavajoException)1 Operand (com.dexels.navajo.document.Operand)1 MappableException (com.dexels.navajo.script.api.MappableException)1 UserException (com.dexels.navajo.script.api.UserException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 TreeMap (java.util.TreeMap)1