use of com.dexels.navajo.document.stream.api.Msg in project navajo by Dexels.
the class StreamDocument method replicationToMessage.
public static Message replicationToMessage(ImmutableMessage msg, String name, boolean isArrayElement) {
Navajo n = NavajoFactory.getInstance().createNavajo();
Message m = NavajoFactory.getInstance().createMessage(n, name, isArrayElement ? Message.MSG_TYPE_ARRAY_ELEMENT : Message.MSG_TYPE_SIMPLE);
List<Property> pp = msg.columnNames().stream().map(e -> {
String type = msg.columnType(e);
Optional<Object> value = msg.value(e);
Property p = NavajoFactory.getInstance().createProperty(n, e, type, "", 0, "", Property.DIR_OUT);
if (value.isPresent()) {
p.setAnyValue(value.get());
}
return p;
}).collect(Collectors.toList());
pp.stream().forEach(p -> m.addProperty(p));
msg.subMessageListMap().forEach((msgName, submessages) -> {
Message subArray = NavajoFactory.getInstance().createMessage(n, msgName, Message.MSG_TYPE_ARRAY_ELEMENT);
submessages.forEach(repl -> {
subArray.addElement(replicationToMessage(repl, msgName, true));
});
m.addMessage(subArray);
});
msg.subMessageMap().forEach((msgName, subMessage) -> m.addMessage(replicationToMessage(subMessage, msgName, false)));
return m;
}
use of com.dexels.navajo.document.stream.api.Msg in project navajo by Dexels.
the class NavajoEventToImmutableProcessor method event.
public void event(NavajoStreamEvent event) {
switch(event.type()) {
case ARRAY_STARTED:
arrayCounter.set(0);
currentArray.clear();
case MESSAGE_STARTED:
case MESSAGE_DEFINITION_STARTED:
// TODO ignore definition messages?
pathStack.push(event.path());
case ARRAY_ELEMENT_STARTED:
break;
case MESSAGE:
case ARRAY_ELEMENT:
Msg m = (Msg) event.body();
arrayCounter.incrementAndGet();
m.toImmutableMessage();
break;
case NAVAJO_DONE:
case NAVAJO_STARTED:
case BINARY_STARTED:
case BINARY_CONTENT:
case BINARY_DONE:
case ARRAY_DONE:
case MESSAGE_DEFINITION:
return;
default:
throw new UnsupportedOperationException("Unknown event found in NAVADOC: " + event.type());
}
// }
}
use of com.dexels.navajo.document.stream.api.Msg in project navajo by Dexels.
the class NavajoStreamEvent method toString.
@SuppressWarnings("unchecked")
public String toString() {
if (type == NavajoEventTypes.NAVAJO_STARTED) {
NavajoHead h = (NavajoHead) body;
return "Type: " + type + " path: " + path + " attributes: {" + attributes + "} - RPCNAME: " + h.name() + " user: " + h.username();
}
if (type == NavajoEventTypes.MESSAGE) {
Msg msgBody = (Msg) body;
List<Prop> contents = msgBody.properties();
StringBuilder sb = new StringBuilder("Message detected. Name: " + path + " with mode: " + this.attributes.get("mode") + "\n");
for (Prop prop : contents) {
sb.append("Prop: " + prop.name() + " = " + prop.value() + " value type: " + prop.type() + "with direction: " + prop.direction() + "\n");
if (prop.value() != null) {
sb.append(" -> value class: " + prop.value().getClass() + "\n");
}
}
return sb.toString();
}
if (type == NavajoEventTypes.NAVAJO_DONE) {
List<String> methods = (List<String>) body;
return "Navajo Done. Methods: " + methods;
}
return "Type: " + type + " path: " + path + " attributes: {" + attributes + "} " + body;
}
Aggregations