use of com.dexels.replication.api.ReplicationMessage in project navajo by Dexels.
the class JsonTmlConverterImpl method toReplicationNavajo.
/* (non-Javadoc)
* @see com.dexels.navajo.document.json.impl.JsonTmlConferter#toNavajo(com.dexels.replication.api.ReplicationMessage, java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public Navajo toReplicationNavajo(ReplicationMessage message, String tenant, String table, Optional<String> datasource) {
try {
Navajo n = NavajoFactory.getInstance().createNavajo();
Message msg = createTransactionMessage(message, tenant, table, datasource, n);
n.addMessage(msg);
// Add PK values.
Message pM = createPrimaryKeyMessage(message, n);
msg.addMessage(pM);
// Add column values.
Message cV = createColumnsMessage(message, n);
msg.addMessage(cV);
// }
return n;
} catch (Exception e) {
logger.error("Error: ", e);
}
return null;
}
use of com.dexels.replication.api.ReplicationMessage in project navajo by Dexels.
the class TestProtobufConversion method testConversion.
@Test
public void testConversion() throws JsonGenerationException, JsonMappingException, IOException {
ReplicationMessage createReplicationMessage = createReplicationMessage();
// convert to protobuf
byte[] serializedMessage = ReplicationFactory.getInstance().serialize(createReplicationMessage);
System.out.println(new String(serializedMessage));
assertNotNull(serializedMessage);
// parse protobuf
ReplicationMessage rmsg = ReplicationFactory.getInstance().parseBytes(Optional.empty(), serializedMessage);
System.err.println("Rescribe: " + new String(rmsg.toBytes(new JSONReplicationMessageParserImpl())));
Navajo rr = JsonTmlFactory.getInstance().toReplicationNavajo(rmsg, "Tenant", "Table", Optional.of("Datasource"));
rr.write(System.out);
// Check
Assert.assertEquals(6, rr.getMessage("Transaction/Columns").getArraySize());
}
use of com.dexels.replication.api.ReplicationMessage 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.replication.api.ReplicationMessage 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;
}
use of com.dexels.replication.api.ReplicationMessage in project navajo by Dexels.
the class JsonTmlConverterImpl method createPrimaryKeyMessage.
private Message createPrimaryKeyMessage(ReplicationMessage message, Navajo n) {
Message pM = NavajoFactory.getInstance().createMessage(n, "PrimaryKey");
pM.setType(Message.MSG_TYPE_ARRAY);
for (String primaryKey : message.primaryKeys()) {
Message vM = NavajoFactory.getInstance().createMessage(n, "PrimaryKey");
pM.addElement(vM);
Object value = message.columnValue(primaryKey);
Property colPropName = NavajoFactory.getInstance().createProperty(n, "Name", Property.STRING_PROPERTY, primaryKey, 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 pM;
}
Aggregations