Search in sources :

Example 36 with Selection

use of com.dexels.navajo.document.Selection 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 37 with Selection

use of com.dexels.navajo.document.Selection 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 38 with Selection

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

Example 39 with Selection

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

the class ExistsSelectionValue method evaluate.

@Override
@SuppressWarnings("unchecked")
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    if (getOperands().size() != 2) {
        throw new TMLExpressionException(this, "Invalid function call, need two parameters");
    }
    Object o = getOperand(0);
    if (o == null) {
        throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: First parameter null");
    }
    Object v = getOperand(1);
    if (v == null) {
        throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: Second parameter null");
    }
    if (!(v instanceof String)) {
        throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: Second parameter not a string");
    }
    if (o instanceof Property) {
        Property p = (Property) o;
        try {
            Selection s = p.getSelectionByValue((String) v);
            return !s.getValue().equals(Selection.DUMMY_ELEMENT);
        } catch (NavajoException ne) {
            throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: First parameter not a selection property");
        }
    }
    if (!(o instanceof List)) {
        throw new TMLExpressionException(this, "Invalid function call in ExistsSelectionValue: First parameter not a selection property");
    }
    List<Selection> l = (List<Selection>) o;
    for (Selection selection : l) {
        if (v.equals(selection.getValue())) {
            return true;
        }
    }
    return false;
}
Also used : Selection(com.dexels.navajo.document.Selection) NavajoException(com.dexels.navajo.document.NavajoException) List(java.util.List) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Property(com.dexels.navajo.document.Property)

Example 40 with Selection

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

the class GetSelectedValue method evaluate.

@Override
@SuppressWarnings("unchecked")
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
    if (getOperands().size() != 1) {
        throw new TMLExpressionException(this, "Invalid function call, need one parameter");
    }
    Object o = operand(0).value;
    if (o == null) {
        throw new TMLExpressionException(this, "Invalid function call in GetSelectedValue: Parameter null");
    }
    if (o instanceof Property) {
        Property p = (Property) o;
        if (p.getSelected() != null) {
            return (p.getAllSelectedSelections().size() > 0 ? p.getSelected().getValue() : null);
        } else {
            return null;
        }
    }
    if (!(o instanceof List)) {
        throw new TMLExpressionException(this, "Invalid function call in GetSelectedValue: Not a selection property");
    }
    List<Selection> l = (List<Selection>) o;
    for (Selection selection : l) {
        if (selection.isSelected()) {
            return selection.getValue();
        }
    }
    return null;
}
Also used : Selection(com.dexels.navajo.document.Selection) List(java.util.List) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Property(com.dexels.navajo.document.Property)

Aggregations

Selection (com.dexels.navajo.document.Selection)78 Property (com.dexels.navajo.document.Property)36 Test (org.junit.Test)32 Message (com.dexels.navajo.document.Message)24 Navajo (com.dexels.navajo.document.Navajo)21 Access (com.dexels.navajo.script.api.Access)14 ImmutableMessage (com.dexels.immutable.api.ImmutableMessage)13 ContextExpression (com.dexels.navajo.expression.api.ContextExpression)12 TipiLink (com.dexels.navajo.expression.api.TipiLink)12 MappableTreeNode (com.dexels.navajo.script.api.MappableTreeNode)12 ArrayList (java.util.ArrayList)12 Optional (java.util.Optional)12 Operand (com.dexels.navajo.document.Operand)11 TMLExpressionException (com.dexels.navajo.expression.api.TMLExpressionException)11 List (java.util.List)8 NavajoException (com.dexels.navajo.document.NavajoException)6 UserException (com.dexels.navajo.script.api.UserException)4 Binary (com.dexels.navajo.document.types.Binary)3 FunctionClassification (com.dexels.navajo.expression.api.FunctionClassification)3 StringTokenizer (java.util.StringTokenizer)3