use of com.dexels.navajo.document.Navajo 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());
}
use of com.dexels.navajo.document.Navajo 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());
}
use of com.dexels.navajo.document.Navajo 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.Navajo 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.Navajo in project navajo by Dexels.
the class JsonToTml method evaluate.
@Override
public final Object evaluate() throws com.dexels.navajo.expression.api.TMLExpressionException {
Object s = this.getOperands().get(0);
Object m = null;
if (getOperands().size() != 1) {
m = this.getOperands().get(1);
}
if (s == null) {
return null;
}
if (s instanceof String) {
Navajo n;
try {
Reader r = new StringReader((String) s);
if (m == null) {
n = JSONTMLFactory.getInstance().parse(r);
} else {
n = JSONTMLFactory.getInstance().parse(r, m.toString());
}
return n;
} catch (Exception e) {
return null;
}
}
return null;
}
Aggregations