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();
}
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);
}
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;
}
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;
}
}
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);*/
}
Aggregations