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"));
}
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"));
}
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());
}
}
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;
}
}
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);
}
}
}
Aggregations