Search in sources :

Example 26 with Property

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

the class ExpressionTest method setup.

@Before
public void setup() {
    NavajoFactory.getInstance().setExpressionEvaluator(new CachedExpressionEvaluator());
    testDoc = NavajoFactory.getInstance().createNavajo();
    topMessage = NavajoFactory.getInstance().createMessage(testDoc, "MyTop");
    testDoc.addMessage(topMessage);
    Property pt = NavajoFactory.getInstance().createProperty(testDoc, "TopProp", "1", "", Property.DIR_IN);
    testSelection = NavajoFactory.getInstance().createSelection(testDoc, "option1", "value1", true);
    pt.addSelection(testSelection);
    topMessage.addProperty(pt);
    Message a = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage", "array");
    topMessage.addMessage(a);
    for (int i = 0; i < 5; i++) {
        Message a1 = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage");
        a.addMessage(a1);
        Property p = NavajoFactory.getInstance().createProperty(testDoc, "MyProp", "string", "noot" + i, 0, "", "in");
        a1.addProperty(p);
        Property p2 = NavajoFactory.getInstance().createProperty(testDoc, "MyProp2", "string", "aap" + i, 0, "", "in");
        a1.addProperty(p2);
    }
    Map<String, Object> values = new HashMap<>();
    Map<String, String> types = new HashMap<>();
    values.put("SomeString", "Tralala");
    types.put("SomeString", "string");
    values.put("SomeInteger", 3);
    types.put("SomeInteger", "integer");
    immutableMessage = ReplicationFactory.createReplicationMessage(Optional.empty(), Optional.empty(), Optional.empty(), null, 0, Operation.NONE, Collections.emptyList(), types, values, Collections.emptyMap(), Collections.emptyMap(), Optional.empty(), Optional.empty()).message();
    Map<String, Object> valueparams = new HashMap<>();
    Map<String, String> typeparams = new HashMap<>();
    valueparams.put("SomeString", "Tralala2");
    typeparams.put("SomeString", "string");
    valueparams.put("SomeInteger", 4);
    typeparams.put("SomeInteger", "integer");
    paramMessage = ReplicationFactory.createReplicationMessage(Optional.empty(), Optional.empty(), Optional.empty(), null, 0, Operation.NONE, Collections.emptyList(), typeparams, valueparams, Collections.emptyMap(), Collections.emptyMap(), Optional.empty(), Optional.empty()).message();
}
Also used : ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Message(com.dexels.navajo.document.Message) HashMap(java.util.HashMap) CachedExpressionEvaluator(com.dexels.navajo.parser.compiled.api.CachedExpressionEvaluator) Property(com.dexels.navajo.document.Property) Before(org.junit.Before)

Example 27 with Property

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

the class ExpressionTest method testExpression.

@Test
public void testExpression() throws Exception {
    ExpressionEvaluator ee = NavajoFactory.getInstance().getExpressionEvaluator();
    Operand o = ee.evaluate("1+1", null, null, null);
    assertEquals(2, o.value);
    o = ee.evaluate("TODAY + 0#0#2#0#0#0", null, null, null);
    System.err.println(o.value);
    Navajo testDoc = NavajoFactory.getInstance().createNavajo();
    Message m = NavajoFactory.getInstance().createMessage(testDoc, "MyTop");
    testDoc.addMessage(m);
    Message a = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage", "array");
    m.addMessage(a);
    for (int i = 0; i < 5; i++) {
        Message a1 = NavajoFactory.getInstance().createMessage(testDoc, "MyArrayMessage");
        a.addMessage(a1);
        Property p = NavajoFactory.getInstance().createProperty(testDoc, "MyProp", "string", "noot" + i, 0, "", "in");
        a1.addProperty(p);
        Property p2 = NavajoFactory.getInstance().createProperty(testDoc, "MyProp2", "string", "aap" + i, 0, "", "in");
        a1.addProperty(p2);
    }
    o = ee.evaluate("'hallo:' + [/MyTop/MyArrayMessage@MyProp=noot1/MyProp2]", testDoc, null, null);
    assertEquals("hallo:aap1", o.value);
    o = ee.evaluate("'hallo:' + [/MyTop/MyArrayMessage@2/MyProp2]", testDoc, null, null);
    assertEquals("hallo:aap2", o.value);
}
Also used : ImmutableMessage(com.dexels.immutable.api.ImmutableMessage) Message(com.dexels.navajo.document.Message) Operand(com.dexels.navajo.document.Operand) Navajo(com.dexels.navajo.document.Navajo) ExpressionEvaluator(com.dexels.navajo.document.ExpressionEvaluator) CachedExpressionEvaluator(com.dexels.navajo.parser.compiled.api.CachedExpressionEvaluator) Property(com.dexels.navajo.document.Property) Test(org.junit.Test)

Example 28 with Property

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

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

the class GetSelectedValues 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 one or two parameters");
    }
    Object o = operand(0).value;
    if (o == null) {
        throw new TMLExpressionException(this, "Invalid function call in GetSelectedValues: Parameter null");
    }
    boolean outputAsStringList = false;
    if (getOperands().size() > 1) {
        outputAsStringList = getBooleanOperand(1);
    }
    List<Object> values = new ArrayList<Object>();
    if (o instanceof Property) {
        Property p = (Property) o;
        if (p.getSelected() != null) {
            if (p.getAllSelectedSelections().size() > 0) {
                values.add(p.getAllSelectedSelections());
            }
        }
    } else if (o instanceof String) {
        values.add(o);
    } else {
        if (!(o instanceof List)) {
            throw new TMLExpressionException(this, "Invalid function call in GetSelectedValues: Not a selection property");
        }
        if (((List<Object>) o).size() != 0) {
            List<Object> l = (List<Object>) o;
            if (outputAsStringList) {
                for (Object selection : l) {
                    values.add(selection.toString());
                }
            } else {
                values.add(l);
            }
        }
    }
    // Outputtype...
    if (outputAsStringList && values.size() != 0) {
        String output = "";
        for (Object item : values) {
            output += item.toString() + ";";
        }
        return output;
    } else {
        return values;
    }
}
Also used : ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) TMLExpressionException(com.dexels.navajo.expression.api.TMLExpressionException) Property(com.dexels.navajo.document.Property)

Example 30 with Property

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

the class EvaluateParameters method main.

public static void main(String[] args) throws Exception {
    // Navajo n = NavajoFactory.getInstance().createNavajo();
    // Message noot = NavajoFactory.getInstance().createMessage(n, "Noot");
    // 
    // n.addMessage(noot);
    // noot.addProperty(ai);
    String expression = "test [/mies/ActivityId]";
    Navajo m = NavajoFactory.getInstance().createNavajo();
    Message mies = NavajoFactory.getInstance().createMessage(m, "mies");
    Property ai = NavajoFactory.getInstance().createProperty(m, "ActivityId", "string", "4792834", 10, "Ac", "in");
    mies.addProperty(ai);
    Property p = NavajoFactory.getInstance().createProperty(m, "exp", "string", expression, 10, "Ac", "in");
    m.addMessage(mies);
    mies.addProperty(p);
    System.err.println(Expression.evaluate("EvaluateParameters([/mies/exp])", m).value);
/*
		EvaluateParameters ce = new EvaluateParameters();
		ce.reset();
		ce.currentMessage = noot;	
		ce.insertOperand(Expression.evaluate("[/mies/exp]", m).value);
		String result = (String) ce.evaluate();
		System.err.println("result:");
		System.err.println(result);*/
}
Also used : Message(com.dexels.navajo.document.Message) Navajo(com.dexels.navajo.document.Navajo) 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