Search in sources :

Example 16 with Message

use of com.dexels.navajo.document.Message 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;
}
Also used : Message(com.dexels.navajo.document.Message) ReplicationMessage(com.dexels.replication.api.ReplicationMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) List(java.util.List) ClockTime(com.dexels.navajo.document.types.ClockTime) Property(com.dexels.navajo.document.Property)

Example 17 with Message

use of com.dexels.navajo.document.Message 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;
}
Also used : Message(com.dexels.navajo.document.Message) ReplicationMessage(com.dexels.replication.api.ReplicationMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Property(com.dexels.navajo.document.Property)

Example 18 with Message

use of com.dexels.navajo.document.Message 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;
}
Also used : Message(com.dexels.navajo.document.Message) ReplicationMessage(com.dexels.replication.api.ReplicationMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Property(com.dexels.navajo.document.Property)

Example 19 with Message

use of com.dexels.navajo.document.Message in project navajo by Dexels.

the class SerializationUtilTest method testRemove3.

@Test
public void testRemove3() {
    Navajo n = NavajoFactory.getInstance().createNavajo();
    Message m = NavajoFactory.getInstance().createMessage(n, "TestMessage");
    n.addMessage(m);
    String name = SerializationUtil.serializeNavajo(n, "TestNavajo");
    Assert.assertEquals(true, SerializationUtil.existsNavajo("TestNavajo"));
    SerializationUtil.removeNavajo("Apenoot");
    Assert.assertEquals(false, SerializationUtil.existsNavajo("Apenoot"));
    SerializationUtil.removeNavajo(name);
    Assert.assertEquals(false, SerializationUtil.existsNavajo("TestNavajo"));
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) Test(org.junit.Test)

Example 20 with Message

use of com.dexels.navajo.document.Message in project navajo by Dexels.

the class DomainObjectMapperTest method testStoreWithMultipleSelectionProperty.

@Test
public void testStoreWithMultipleSelectionProperty() throws Exception {
    // The other way around, with an input Navajo with property that does
    // have an associated attribute.
    Navajo doc = NavajoFactory.getInstance().createNavajo();
    Message m = NavajoFactory.getInstance().createMessage(doc, "MyMessage");
    doc.addMessage(m);
    Property p1 = NavajoFactory.getInstance().createProperty(doc, "Id", "string", "hello", 0, "", "in");
    Property p2 = NavajoFactory.getInstance().createProperty(doc, "Selection", "+", "", "in");
    m.addProperty(p1);
    m.addProperty(p2);
    // Add selections...
    Selection s1 = NavajoFactory.getInstance().createSelection(doc, "aap", "AAP", true);
    Selection s2 = NavajoFactory.getInstance().createSelection(doc, "noot", "NOOT", true);
    Selection s3 = NavajoFactory.getInstance().createSelection(doc, "mies", "MIES", false);
    p2.addSelection(s1);
    p2.addSelection(s2);
    p2.addSelection(s3);
    Access a = new Access();
    a.setInDoc(doc);
    DomainObjectMapper dom2 = new DomainObjectMapper();
    dom2.setCurrentMessageName("MyMessage");
    dom2.load(a);
    dom2.setObjectName("com.dexels.navajo.mapping.bean.Relation");
    boolean exception = false;
    try {
        dom2.store();
    } catch (Exception e) {
        exception = true;
    }
    // Multiple cardinality is not yet supported, hence exception.
    assertTrue(exception);
// Object o = dom2.getMyObject();
// assertNotNull(o);
// assertEquals(Relation.class, o.getClass());
// assertEquals("hello", ((Relation) o).getId());
// assertEquals("NOOT", ((Relation) o).getSelection());
}
Also used : Message(com.dexels.navajo.document.Message) Selection(com.dexels.navajo.document.Selection) Access(com.dexels.navajo.script.api.Access) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Aggregations

Message (com.dexels.navajo.document.Message)312 Property (com.dexels.navajo.document.Property)149 Navajo (com.dexels.navajo.document.Navajo)127 Test (org.junit.Test)95 NavajoException (com.dexels.navajo.document.NavajoException)39 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)35 Access (com.dexels.navajo.script.api.Access)27 UserException (com.dexels.navajo.script.api.UserException)27 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)26 Selection (com.dexels.navajo.document.Selection)25 Operand (com.dexels.navajo.document.Operand)22 IOException (java.io.IOException)19 ArrayList (java.util.ArrayList)19 MappableException (com.dexels.navajo.script.api.MappableException)18 Ignore (org.junit.Ignore)17 SystemException (com.dexels.navajo.script.api.SystemException)16 Optional (java.util.Optional)15 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)13 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)13 HashMap (java.util.HashMap)13