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