Search in sources :

Example 6 with ReplicationMessage

use of com.dexels.replication.api.ReplicationMessage in project navajo by Dexels.

the class JsonTmlConverterImpl method toFlatNavajo.

@Override
public Navajo toFlatNavajo(String name, ReplicationMessage message) {
    Navajo rootNavajo = NavajoFactory.getInstance().createNavajo();
    Message root = toMessage(name, message.message(), rootNavajo);
    Property timestamp = NavajoFactory.getInstance().createProperty(rootNavajo, "Timestamp", Property.LONG_PROPERTY, message.timestamp() + "", 0, "", Property.DIR_OUT);
    root.addProperty(timestamp);
    rootNavajo.addMessage(root);
    return rootNavajo;
}
Also used : Message(com.dexels.navajo.document.Message) ReplicationMessage(com.dexels.replication.api.ReplicationMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property)

Example 7 with ReplicationMessage

use of com.dexels.replication.api.ReplicationMessage in project navajo by Dexels.

the class TestJsonConversion method testConversion.

@Test
public void testConversion() throws IOException {
    InputStream resource = TestJsonConversion.class.getResourceAsStream("testtml.xml");
    Navajo base = NavajoFactory.getInstance().createNavajo(resource);
    Message m = base.getMessage("Pool");
    ObjectNode on = JsonTmlFactory.getInstance().toNode(m, "ble");
    JSONReplicationMessageParserImpl parser = new JSONReplicationMessageParserImpl();
    ReplicationMessage rmsg = parser.parseJson(Optional.empty(), on);
    ObjectMapper mapper = new ObjectMapper();
    logger.info("Before:\n");
    StringWriter sw = new StringWriter();
    mapper.writerWithDefaultPrettyPrinter().writeValue(sw, on);
    logger.info("Value: {}", sw);
    Optional<List<ImmutableMessage>> r = rmsg.subMessages("Standings");
    Assert.assertTrue(r.isPresent());
    Assert.assertEquals(12, r.get().size());
    Navajo rr = JsonTmlFactory.getInstance().toReplicationNavajo(rmsg, "Tenant", "Table", Optional.of("Datasource"));
    Assert.assertEquals(10, rr.getMessage("Transaction/Columns").getArraySize());
}
Also used : Message(com.dexels.navajo.document.Message) ReplicationMessage(com.dexels.replication.api.ReplicationMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) StringWriter(java.io.StringWriter) InputStream(java.io.InputStream) JSONReplicationMessageParserImpl(com.dexels.replication.impl.json.JSONReplicationMessageParserImpl) List(java.util.List) Navajo(com.dexels.navajo.document.Navajo) ReplicationMessage(com.dexels.replication.api.ReplicationMessage) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 8 with ReplicationMessage

use of com.dexels.replication.api.ReplicationMessage in project navajo by Dexels.

the class TestTMLReplicationConversion method testReplToMessage.

@Test
public void testReplToMessage() {
    ReplicationMessage rm = ReplicationFactory.empty().with("Monkey", "Koko", "string");
    Navajo n = NavajoFactory.getInstance().createNavajo();
    n.addMessage(StreamDocument.replicationToMessage(rm.message(), "Message", false));
    n.write(System.err);
    String mn = (String) n.getMessage("Message").getProperty("Monkey").getTypedValue();
    Assert.assertEquals("Koko", mn);
}
Also used : Navajo(com.dexels.navajo.document.Navajo) ReplicationMessage(com.dexels.replication.api.ReplicationMessage) Test(org.junit.Test)

Aggregations

ReplicationMessage (com.dexels.replication.api.ReplicationMessage)8 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)6 Message (com.dexels.navajo.document.Message)6 Navajo (com.dexels.navajo.document.Navajo)5 Property (com.dexels.navajo.document.Property)4 Test (org.junit.Test)3 JSONReplicationMessageParserImpl (com.dexels.replication.impl.json.JSONReplicationMessageParserImpl)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 InputStream (java.io.InputStream)1 StringWriter (java.io.StringWriter)1 List (java.util.List)1