use of com.dexels.navajo.document.Message in project navajo by Dexels.
the class NavajoStreamToMutableMessageStream method processNavajoEvent.
public Flowable<Message> processNavajoEvent(NavajoStreamEvent n) {
switch(n.type()) {
case NAVAJO_STARTED:
return Flowable.empty();
case MESSAGE_STARTED:
Message prMessage = null;
if (!messageStack.isEmpty()) {
prMessage = messageStack.peek();
}
String mode = (String) n.attribute("mode");
Message msg = NavajoFactory.getInstance().createMessage(null, n.path(), Message.MSG_TYPE_SIMPLE);
msg.setMode(mode);
if (prMessage == null) {
// assemble.addMessage(msg);
// currentMessage.set(msg);
} else {
prMessage.addMessage(msg);
}
messageStack.push(msg);
tagStack.push(n.path());
return Flowable.empty();
case MESSAGE:
// if(messageStack.isEmpty())
Message msgParent = null;
if (messageStack.isEmpty()) {
msgParent = NavajoFactory.getInstance().createMessage(null, n.path(), Message.MSG_TYPE_SIMPLE);
} else {
msgParent = messageStack.pop();
}
Msg mm = (Msg) n.body();
List<Prop> msgProps = mm.properties();
for (Prop e : msgProps) {
msgParent.addProperty(createTmlProperty(e));
}
if (emitStack()) {
tagStack.pop();
return Flowable.just(msgParent);
}
tagStack.pop();
return Flowable.empty();
case ARRAY_STARTED:
tagStack.push(n.path());
Message parentMessage = null;
if (!messageStack.isEmpty()) {
parentMessage = messageStack.peek();
}
Message arr = NavajoFactory.getInstance().createMessage(null, n.path(), Message.MSG_TYPE_ARRAY);
if (parentMessage == null) {
// assemble.addMessage(arr);
} else {
parentMessage.addMessage(arr);
}
messageStack.push(arr);
return Flowable.empty();
case ARRAY_DONE:
// String apath = currentPath();
// arrayCounts.remove(apath);
this.messageStack.pop();
return Flowable.empty();
case ARRAY_ELEMENT_STARTED:
String arrayElementName = tagStack.peek();
Message newElt = NavajoFactory.getInstance().createMessage(null, arrayElementName, Message.MSG_TYPE_ARRAY_ELEMENT);
Message arrParent = messageStack.peek();
arrParent.addElement(newElt);
messageStack.push(newElt);
return Flowable.empty();
case ARRAY_ELEMENT:
Message elementParent = messageStack.pop();
Msg msgElement = (Msg) n.body();
List<Prop> elementProps = msgElement.properties();
for (Prop e : elementProps) {
elementParent.addProperty(createTmlProperty(e));
}
if (emitStack()) {
// tagStack.pop();
return Flowable.just(elementParent);
}
// tagStack.pop();
return Flowable.empty();
case MESSAGE_DEFINITION_STARTED:
return Flowable.empty();
case MESSAGE_DEFINITION:
// deferredMessages.get(stripIndex(n.path())).setDefinitionMessage((Message) n.body());
return Flowable.empty();
case NAVAJO_DONE:
return Flowable.empty();
default:
return Flowable.empty();
}
}
use of com.dexels.navajo.document.Message 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.Message 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.Message in project navajo by Dexels.
the class Exists method evaluate.
@Override
public Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
/**
*@todo Implement this com.dexels.navajo.parser.FunctionInterface abstract method
*/
Message arrayMessage = null;
String messagePath = null;
if (getOperand(0) instanceof Message) {
arrayMessage = (Message) getOperand(0);
} else {
messagePath = (String) getOperand(0);
}
String expression = (String) getOperand(1);
String filter = null;
if (getOperands().size() > 2) {
filter = (String) getOperand(2);
}
Message parent = getCurrentMessage();
Navajo doc = getNavajo();
// try {
try {
List<Message> arrayMsg = null;
if (arrayMessage != null) {
arrayMsg = arrayMessage.getAllMessages();
} else {
arrayMsg = (parent != null ? parent.getMessages(messagePath) : doc.getMessages(messagePath));
}
if (arrayMsg == null) {
throw new TMLExpressionException(this, "Empty or non existing array message: " + messagePath);
}
for (int i = 0; i < arrayMsg.size(); i++) {
Message current = arrayMsg.get(i);
try {
boolean evaluate = (filter != null ? Condition.evaluate(filter, doc, null, current, getAccess()) : true);
if (evaluate) {
Operand result = Expression.evaluate(expression, doc, null, current);
if (result == null) {
throw new TMLExpressionException(this, "Error evaluating expression: " + expression + " in message: " + current.getFullMessageName());
}
if (result.value == null) {
throw new TMLExpressionException(this, "Error evaluating expression: " + expression + " in message: " + current.getFullMessageName());
}
String res2 = "" + result.value;
Operand result2 = Expression.evaluate(res2, doc, null, current);
if (result2 == null) {
throw new TMLExpressionException(this, "Error evaluating expression: " + res2 + " in message: " + current.getFullMessageName());
}
if (result2.value == null) {
throw new TMLExpressionException(this, "Error evaluating expression: " + res2 + " in message: " + current.getFullMessageName());
}
boolean res = ((Boolean) result2.value).booleanValue();
if (res) {
return Boolean.TRUE;
}
}
} catch (SystemException ex) {
logger.error("Error: ", ex);
}
}
} catch (NavajoException ex) {
throw new TMLExpressionException(this, "Error evaluating message path");
}
return Boolean.FALSE;
}
use of com.dexels.navajo.document.Message 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