use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class TableCommand method replaceTokens.
private String replaceTokens(String text, Message msg) throws APIException {
Pattern pattern = Pattern.compile("\\$\\{(.+?)\\}");
Matcher matcher = pattern.matcher(text);
StringBuffer buffer = new StringBuffer();
while (matcher.find()) {
final String group = matcher.group(1);
Property p = msg.getProperty(group);
if (p == null) {
throw new APIException("Error resolving target. Referenced property: " + group + " not found in message", null, APIErrorCode.InternalError);
}
String replacement = p.getValue();
if (replacement != null) {
matcher.appendReplacement(buffer, "");
buffer.append(replacement);
}
}
matcher.appendTail(buffer);
return buffer.toString();
}
use of com.dexels.navajo.document.Property in project navajo by Dexels.
the class TableCommand method execute.
@Override
public JsonNode execute(ArticleRuntime runtime, ArticleContext context, Map<String, String> parameters, XMLElement element) throws APIException {
String service = parameters.get("service");
if (service == null) {
throw new APIException("No service parameter supplied for table. We need to know which navajo you want to use.", null, APIErrorCode.InternalError);
}
Navajo navajo = runtime.getNavajo(service);
if (navajo == null) {
throw new APIException("Navajo: " + service + " was not found in the current runtime.", null, APIErrorCode.InternalError);
}
String path = parameters.get("path");
if (path == null) {
throw new APIException("No path parameter supplied. Which message do you want to listen to.", null, APIErrorCode.InternalError);
}
Message message = navajo.getMessage(path);
if (message == null) {
throw new APIException("Message: " + path + " not found", null, APIErrorCode.InternalError);
}
runtime.setMimeType("application/json; charset=utf-8");
ArrayNode nodes = runtime.getObjectMapper().createArrayNode();
for (Message data : message.getElements()) {
ObjectNode node = runtime.getObjectMapper().createObjectNode();
for (XMLElement XMLElement : element.getChildren()) {
final String id = XMLElement.getStringAttribute("id");
final String type = XMLElement.getStringAttribute("type");
final String target = XMLElement.getStringAttribute("target");
if (target != null) {
// A target is a link, they do not have navajo value.
node.put(id, resolveTarget(target, runtime, data));
} else {
// We default back to the id for the propertyName if not explicit set.
final String propertyName = XMLElement.getStringAttribute("propertyName", id);
Property property = data.getProperty(propertyName);
APIValue.setValueOnNodeForType(node, id, type, property, runtime);
}
}
nodes.add(node);
}
return nodes;
}
use of com.dexels.navajo.document.Property 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.Property 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.Property 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;
}
Aggregations