Search in sources :

Example 21 with Property

use of com.dexels.navajo.document.Property 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)

Example 22 with Property

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

the class DomainObjectMapperTest method testStoreWithSelectionProperty.

@Test
public void testStoreWithSelectionProperty() 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", "1", "", "in");
    m.addProperty(p1);
    m.addProperty(p2);
    // Add selections...
    Selection s1 = NavajoFactory.getInstance().createSelection(doc, "aap", "AAP", false);
    Selection s2 = NavajoFactory.getInstance().createSelection(doc, "noot", "NOOT", true);
    p2.addSelection(s1);
    p2.addSelection(s2);
    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");
    dom2.store();
    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)

Example 23 with Property

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

the class DomainObjectMapperTest method testSetExcludedProperties.

@Test
public void testSetExcludedProperties() throws Exception {
    // TestPOJO tp = new TestPOJO();
    DomainObjectMapper dom = new DomainObjectMapper();
    dom.setObjectName("com.dexels.navajo.mapping.bean.TestPOJO");
    Navajo doc = NavajoFactory.getInstance().createNavajo();
    Message m = NavajoFactory.getInstance().createMessage(doc, "Test");
    System.err.println("m = " + m);
    doc.addMessage(m);
    Property p1 = NavajoFactory.getInstance().createProperty(doc, "name", Property.STRING_PROPERTY, "nice", 0, "", "out");
    m.addProperty(p1);
    java.util.Date d = new java.util.Date();
    Property p2 = NavajoFactory.getInstance().createProperty(doc, "birthdate", Property.DATE_PROPERTY, null, 0, "", "out");
    p2.setAnyValue(d);
    m.addProperty(p2);
    Property p3 = NavajoFactory.getInstance().createProperty(doc, "something", Property.STRING_PROPERTY, "notnice", 0, "", "out");
    m.addProperty(p3);
    Access a = new Access();
    a.setInDoc(doc);
    a.setOutputDoc(NavajoFactory.getInstance().createNavajo());
    dom.load(a);
    dom.setExcludedProperties("something");
    dom.setCurrentMessageName("Test");
    dom.store();
    TestPOJO tp = (TestPOJO) dom.getMyObject();
    assertEquals("nice", tp.getName());
    assertEquals(d, tp.getBirthdate());
    assertNull(tp.getSomething());
}
Also used : Message(com.dexels.navajo.document.Message) Access(com.dexels.navajo.script.api.Access) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Example 24 with Property

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

the class TestRun method testTimestamp.

@Test
public void testTimestamp() {
    ImmutableMessage msg = ReplicationFactory.getInstance().parseStream(getClass().getResourceAsStream("test3.json")).message();
    Navajo nn = JsonTmlFactory.getInstance().toFlatNavajo("Match", msg);
    Message match = nn.getMessage("Match");
    assertNotNull(match.getProperty("matchtime"));
    Property matchtime = match.getProperty("matchtime");
    assertEquals(Property.DATE_PROPERTY, matchtime.getType());
    Date matchtimeobj = (Date) matchtime.getTypedValue();
    Calendar cal = Calendar.getInstance();
    cal.setTime(matchtimeobj);
    assertEquals(1971, cal.get(Calendar.YEAR));
    assertEquals(12, cal.get(Calendar.HOUR_OF_DAY));
    assertEquals(0, cal.get(Calendar.MINUTE));
    Property matchtime2 = match.getProperty("matchtime2");
    assertEquals(Property.CLOCKTIME_PROPERTY, matchtime2.getType());
}
Also used : Message(com.dexels.navajo.document.Message) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Calendar(java.util.Calendar) Navajo(com.dexels.navajo.document.Navajo) Property(com.dexels.navajo.document.Property) Date(java.util.Date) Test(org.junit.Test)

Example 25 with Property

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

the class NavajoStreamToMutableMessageStream method createTmlProperty.

// private String currentPath() {
// StringBuilder sb = new StringBuilder();
// for (String path : tagStack) {
// sb.append(path);
// sb.append('/');
// }
// int len = sb.length();
// if(sb.charAt(len-1)=='/') {
// sb.deleteCharAt(len-1);
// }
// return sb.toString();
// }
private Property createTmlProperty(Prop p) {
    Property result;
    if (Property.SELECTION_PROPERTY.equals(p.type())) {
        result = NavajoFactory.getInstance().createProperty(null, p.name(), p.cardinality().orElse(null), p.description(), p.direction().orElse(null));
        for (Select s : p.selections()) {
            Selection sel = NavajoFactory.getInstance().createSelection(null, s.name(), s.value(), s.selected());
            result.addSelection(sel);
        }
    } else {
        result = NavajoFactory.getInstance().createProperty(null, p.name(), p.type() == null ? Property.STRING_PROPERTY : p.type(), null, p.length(), p.description(), p.direction().orElse(null));
        if (p.value() != null) {
            result.setAnyValue(p.value());
        }
        if (p.type() != null) {
            result.setType(p.type());
        }
    }
    return result;
}
Also used : Selection(com.dexels.navajo.document.Selection) Select(com.dexels.navajo.document.stream.api.Select) Property(com.dexels.navajo.document.Property)

Aggregations

Property (com.dexels.navajo.document.Property)253 Message (com.dexels.navajo.document.Message)148 Test (org.junit.Test)88 Navajo (com.dexels.navajo.document.Navajo)84 Selection (com.dexels.navajo.document.Selection)36 NavajoException (com.dexels.navajo.document.NavajoException)30 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)17 ArrayList (java.util.ArrayList)17 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)16 Binary (com.dexels.navajo.document.types.Binary)16 UserException (com.dexels.navajo.script.api.UserException)16 Access (com.dexels.navajo.script.api.Access)15 StringWriter (java.io.StringWriter)13 List (java.util.List)11 Operand (com.dexels.navajo.document.Operand)10 MappableException (com.dexels.navajo.script.api.MappableException)9 IOException (java.io.IOException)9 Writer (java.io.Writer)9 StringTokenizer (java.util.StringTokenizer)9 JSONTML (com.dexels.navajo.document.json.JSONTML)8