use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class JsonTmlConverterImpl method toMessage.
@Override
public Message toMessage(String messageName, ImmutableMessage message, Navajo rootNavajo) {
Message cV = NavajoFactory.getInstance().createMessage(rootNavajo, messageName);
for (String columnName : message.columnNames()) {
String type = message.columnType(columnName);
Object value = message.value(columnName).orElse(null);
Property colProp = NavajoFactory.getInstance().createProperty(rootNavajo, columnName, type, null, 0, "", Property.DIR_OUT);
switch(type) {
case Property.CLOCKTIME_PROPERTY:
if (value != null) {
ClockTime ct = new ClockTime((Date) value);
colProp.setAnyValue(ct);
}
colProp.setType(type);
break;
default:
colProp.setAnyValue(value);
colProp.setType(type);
break;
}
cV.addProperty(colProp);
}
for (Entry<String, List<ImmutableMessage>> e : message.subMessageListMap().entrySet()) {
Message subArrayMessage = NavajoFactory.getInstance().createMessage(rootNavajo, e.getKey(), Message.MSG_TYPE_ARRAY);
cV.addMessage(subArrayMessage);
for (ImmutableMessage elt : e.getValue()) {
Message msgElt = toMessage(e.getKey(), elt, rootNavajo);
subArrayMessage.addElement(msgElt);
}
}
for (Entry<String, ImmutableMessage> e : message.subMessageMap().entrySet()) {
Message msgElt = toMessage(e.getKey(), e.getValue(), rootNavajo);
cV.addMessage(msgElt);
}
return cV;
}
use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class JsonTmlConverterImpl method createColumnsMessage.
private Message createColumnsMessage(ReplicationMessage message, Navajo n) {
Message cV = NavajoFactory.getInstance().createMessage(n, "Columns", Message.MSG_TYPE_ARRAY);
for (String columnName : message.columnNames()) {
Message vM = NavajoFactory.getInstance().createMessage(n, "Columns");
cV.addElement(vM);
Object value = message.columnValue(columnName);
Property colPropName = NavajoFactory.getInstance().createProperty(n, "Name", Property.STRING_PROPERTY, columnName, 0, "", Property.DIR_OUT);
Property colPropValue = NavajoFactory.getInstance().createProperty(n, "Value", Property.STRING_PROPERTY, "", 0, "", Property.DIR_OUT);
colPropValue.setAnyValue(value);
vM.addProperty(colPropName);
vM.addProperty(colPropValue);
}
return cV;
}
use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class JsonTmlConverterImpl method createTransactionMessage.
private Message createTransactionMessage(ReplicationMessage message, String tenant, String table, Optional<String> datasource, Navajo n) {
String transactionId = message.transactionId();
Message msg = NavajoFactory.getInstance().createMessage(n, "Transaction");
Property transactionIdProp = NavajoFactory.getInstance().createProperty(n, "TransactionId", Property.STRING_PROPERTY, transactionId, 0, "", Property.DIR_OUT);
Property timestamp = NavajoFactory.getInstance().createProperty(n, "Timestamp", Property.LONG_PROPERTY, message.timestamp() + "", 0, "", Property.DIR_OUT);
Property dbOperation = NavajoFactory.getInstance().createProperty(n, "Operation", Property.STRING_PROPERTY, message.operation().toString(), 0, "", Property.DIR_OUT);
Property tenantProp = NavajoFactory.getInstance().createProperty(n, "Tenant", Property.STRING_PROPERTY, tenant, 0, "", Property.DIR_OUT);
Property tableProp = NavajoFactory.getInstance().createProperty(n, "SourceTable", Property.STRING_PROPERTY, table, 0, "", Property.DIR_OUT);
Property status = NavajoFactory.getInstance().createProperty(n, "Status", Property.STRING_PROPERTY, "PENDING", 0, "", Property.DIR_OUT);
msg.addProperty(transactionIdProp);
msg.addProperty(tenantProp);
msg.addProperty(tableProp);
if (datasource.isPresent()) {
Property source = NavajoFactory.getInstance().createProperty(n, "DataSource", Property.STRING_PROPERTY, datasource.get(), 0, "", Property.DIR_OUT);
msg.addProperty(source);
}
msg.addProperty(timestamp);
msg.addProperty(dbOperation);
msg.addProperty(status);
return msg;
}
use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class SerializationUtilTest method testRemove3.
@Test
public void testRemove3() {
Navajo n = NavajoFactory.getInstance().createNavajo();
Message m = NavajoFactory.getInstance().createMessage(n, "TestMessage");
n.addMessage(m);
String name = SerializationUtil.serializeNavajo(n, "TestNavajo");
Assert.assertEquals(true, SerializationUtil.existsNavajo("TestNavajo"));
SerializationUtil.removeNavajo("Apenoot");
Assert.assertEquals(false, SerializationUtil.existsNavajo("Apenoot"));
SerializationUtil.removeNavajo(name);
Assert.assertEquals(false, SerializationUtil.existsNavajo("TestNavajo"));
}
use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class DomainObjectMapperTest method testStoreWithMultipleSelectionProperty.
@Test
public void testStoreWithMultipleSelectionProperty() throws Exception {
// The other way around, with an input Navajo with property that does
// have an associated attribute.
Navajo doc = NavajoFactory.getInstance().createNavajo();
Message m = NavajoFactory.getInstance().createMessage(doc, "MyMessage");
doc.addMessage(m);
Property p1 = NavajoFactory.getInstance().createProperty(doc, "Id", "string", "hello", 0, "", "in");
Property p2 = NavajoFactory.getInstance().createProperty(doc, "Selection", "+", "", "in");
m.addProperty(p1);
m.addProperty(p2);
// Add selections...
Selection s1 = NavajoFactory.getInstance().createSelection(doc, "aap", "AAP", true);
Selection s2 = NavajoFactory.getInstance().createSelection(doc, "noot", "NOOT", true);
Selection s3 = NavajoFactory.getInstance().createSelection(doc, "mies", "MIES", false);
p2.addSelection(s1);
p2.addSelection(s2);
p2.addSelection(s3);
Access a = new Access();
a.setInDoc(doc);
DomainObjectMapper dom2 = new DomainObjectMapper();
dom2.setCurrentMessageName("MyMessage");
dom2.load(a);
dom2.setObjectName("com.dexels.navajo.mapping.bean.Relation");
boolean exception = false;
try {
dom2.store();
} catch (Exception e) {
exception = true;
}
// Multiple cardinality is not yet supported, hence exception.
assertTrue(exception);
// Object o = dom2.getMyObject();
// assertNotNull(o);
// assertEquals(Relation.class, o.getClass());
// assertEquals("hello", ((Relation) o).getId());
// assertEquals("NOOT", ((Relation) o).getSelection());
}
Aggregations