Search in sources :

Example 21 with ImmutableMessage

use of com.dexels.immutable.api.ImmutableMessage in project navajo by Dexels.

the class StreamDocument method toImmutable.

public static ImmutableMessage toImmutable(Navajo n) {
    Map<String, ImmutableMessage> subMessages = null;
    Map<String, List<ImmutableMessage>> subMessageLists = null;
    // Map<S>
    for (Message msg : n.getAllMessages()) {
        if (msg.isArrayMessage()) {
            if (subMessageLists == null) {
                subMessageLists = new HashMap<>();
            }
            subMessageLists.put(msg.getName(), toImmutableList(msg));
        } else {
            if (subMessages == null) {
                subMessages = new HashMap<>();
            }
            subMessages.put(msg.getName(), toImmutable(n));
        }
    }
    if (subMessageLists == null) {
        subMessageLists = Collections.emptyMap();
    }
    if (subMessages == null) {
        subMessages = Collections.emptyMap();
    }
    return ImmutableFactory.create(Collections.emptyMap(), Collections.emptyMap(), subMessages, subMessageLists);
}
Also used : Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) List(java.util.List)

Example 22 with ImmutableMessage

use of com.dexels.immutable.api.ImmutableMessage 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 23 with ImmutableMessage

use of com.dexels.immutable.api.ImmutableMessage in project navajo by Dexels.

the class TestRun method testReplicationToTML.

@Test
public void testReplicationToTML() {
    ImmutableMessage msg = ReplicationFactory.getInstance().parseStream(getClass().getResourceAsStream("test.json")).message();
    Navajo nn = JsonTmlFactory.getInstance().toFlatNavajo("Pool", msg);
    Message standings = nn.getMessage("Pool").getMessage("standings");
    Assert.assertEquals(14, standings.getArraySize());
    nn.write(System.err);
}
Also used : Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Navajo(com.dexels.navajo.document.Navajo) Test(org.junit.Test)

Example 24 with ImmutableMessage

use of com.dexels.immutable.api.ImmutableMessage in project navajo by Dexels.

the class TestRun method testClocktimeReplicationToTML.

@Test
public void testClocktimeReplicationToTML() {
    ImmutableMessage msg = ReplicationFactory.getInstance().parseStream(getClass().getResourceAsStream("calendarday.json")).message();
    Navajo nn = JsonTmlFactory.getInstance().toFlatNavajo("CalendarDay", msg);
    nn.write(System.err);
    Message calendarday = nn.getMessage("CalendarDay");
    System.err.println(">> " + calendarday.getProperty("starttime").getValue());
    ClockTime ct = (ClockTime) calendarday.getProperty("starttime").getTypedValue();
    Assert.assertFalse(ct.isEmpty());
    int hours = ct.getHours();
    Assert.assertEquals(17, hours);
    System.err.println("Clocktime: " + hours);
// ReplicationMessage rm2 =  protoBufParser.parseBytes(bb);
// Assert.assertEquals(7, rm2.values().size());
// 
// final Date columnValue2 = (Date) rm2.columnValue("starttime");
// Assert.assertTrue(Math.abs(c.getTime().getTime() - columnValue2.getTime())<1000);
// 
// Assert.assertEquals(14,standings.getArraySize());
}
Also used : Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Navajo(com.dexels.navajo.document.Navajo) ClockTime(com.dexels.navajo.document.types.ClockTime) Test(org.junit.Test)

Example 25 with ImmutableMessage

use of com.dexels.immutable.api.ImmutableMessage in project navajo by Dexels.

the class ReactiveReply method toMessage.

public ImmutableMessage toMessage() {
    // TODO don't need to recreate the map. Fix the Map<String,Object> signature
    Map<String, String> r = responseHeaders();
    Map<String, String> types = new HashMap<>();
    Map<String, Object> values = new HashMap<>();
    r.keySet().forEach(e -> {
        values.put(e, r.get(e));
        types.put(e, "string");
    });
    ImmutableMessage headers = ImmutableFactory.create(values, types);
    return ImmutableFactory.empty().with("status", response.getStatus(), Property.INTEGER_PROPERTY).withSubMessage("headers", headers);
}
Also used : HashMap(java.util.HashMap) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage)

Aggregations

ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)36 Message (com.dexels.navajo.document.Message)23 Navajo (com.dexels.navajo.document.Navajo)18 Operand (com.dexels.navajo.document.Operand)17 Optional (java.util.Optional)17 Selection (com.dexels.navajo.document.Selection)12 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)12 TipiLink (com.dexels.navajo.expression.api.TipiLink)12 Access (com.dexels.navajo.script.api.Access)12 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)12 Test (org.junit.Test)12 List (java.util.List)9 Property (com.dexels.navajo.document.Property)7 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)6 HashMap (java.util.HashMap)6 ImmutableFactory (com.dexels.immutable.factory.ImmutableFactory)5 ArrayList (java.util.ArrayList)5 DataItem (com.dexels.navajo.document.stream.DataItem)4 StreamScriptContext (com.dexels.navajo.document.stream.api.StreamScriptContext)4 ReactiveParameters (com.dexels.navajo.reactive.api.ReactiveParameters)4