use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class ASTForAllNode method interpret.
/**
* FORALL(<EXPRESSION>, `[$x] <EXPRESSION>`) E.G.
* FORALL([/ClubMembership/ClubMemberships/ClubIdentifier],
* `CheckRelatieCode([$x])`)
*
* @return
*/
private final Operand interpret(Navajo doc, Message parentMsg, Message parentParamMsg, Selection parentSel, MappableTreeNode mapNode, TipiLink tipiLink, Access access, Optional<ImmutableMessage> immutableMessage, Optional<ImmutableMessage> paramMessage, ContextExpression a, ContextExpression b) {
boolean matchAll = true;
if (functionName.equals("FORALL"))
matchAll = true;
else
matchAll = false;
String msgList = (String) a.apply(doc, parentMsg, parentParamMsg, parentSel, mapNode, tipiLink, access, immutableMessage, paramMessage).value;
try {
List<Message> list = null;
if (parentMsg == null) {
list = doc.getMessages(msgList);
} else {
list = parentMsg.getMessages(msgList);
}
for (int i = 0; i < list.size(); i++) {
Object o = list.get(i);
parentMsg = (Message) o;
// ignore definition messages in the evaluation
if (parentMsg.getType().equals(Message.MSG_TYPE_DEFINITION))
continue;
Operand apply = b.apply(doc, parentMsg, parentParamMsg, parentSel, mapNode, tipiLink, access, immutableMessage, paramMessage);
boolean result = (Boolean) apply.value;
if ((!(result)) && matchAll)
return Operand.ofBoolean(false);
if ((result) && !matchAll)
return Operand.ofBoolean(true);
}
} catch (NavajoException ne) {
throw new TMLExpressionException("Invalid expression in FORALL construct: \n" + ne.getMessage());
}
return Operand.ofBoolean(matchAll);
}
use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class Expression method match.
public static final Message match(String matchString, Navajo inMessage, MappableTreeNode o, Message parent) throws SystemException {
try {
StringTokenizer tokens = new StringTokenizer(matchString, ";");
String matchSet = tokens.nextToken();
if (matchSet == null)
throw new TMLExpressionException("Invalid usage of match: match=\"[match set];[match value]\"");
String matchValue = tokens.nextToken();
if (matchValue == null)
throw new TMLExpressionException("Invalid usage of match: match=\"[match set];[match value]\"");
Operand value = evaluate(matchValue, inMessage, o, parent, null, null, null, null);
List<Property> properties;
if (parent == null)
properties = inMessage.getProperties(matchSet);
else
properties = parent.getProperties(matchSet);
for (int i = 0; i < properties.size(); i++) {
Property prop = properties.get(i);
Message parentMsg = prop.getParentMessage();
if (prop.getValue().equals(value.value))
return parentMsg;
}
} catch (NavajoException e) {
throw new SystemException(-1, e.getMessage(), e);
}
return null;
}
use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class SaxHandler method parseProperty.
private final void parseProperty(Map<String, String> h) throws NavajoException {
// logger.info("NAME: "+(String)h.get("name"));
String sLength = null;
String myName = h.get(Property.PROPERTY_NAME);
String myValue = h.get(Property.PROPERTY_VALUE);
String subType = h.get(Property.PROPERTY_SUBTYPE);
String description = h.get(Property.PROPERTY_DESCRIPTION);
String direction = h.get(Property.PROPERTY_DIRECTION);
String type = h.get(Property.PROPERTY_TYPE);
sLength = h.get(Property.PROPERTY_LENGTH);
String cardinality = h.get(Property.PROPERTY_CARDINALITY);
String extendsProp = h.get(Property.PROPERTY_EXTENDS);
String reference = h.get(Property.PROPERTY_REFERENCE);
String key = h.get(Property.PROPERTY_KEY);
String bind = h.get(Property.PROPERTY_BIND);
String method = h.get(Property.PROPERTY_METHOD);
Integer plength = null;
Property definitionProperty = null;
String subtype = null;
int length = 0;
try {
if (sLength != null) {
length = Integer.parseInt(sLength);
plength = Integer.valueOf(length);
}
} catch (Exception e1) {
// logger.info("ILLEGAL LENGTH IN PROPERTY " + myName + ": " +
// sLength);
}
if (myName == null) {
throw NavajoFactory.getInstance().createNavajoException("Can not parse property without a name ");
}
boolean isListType = (type != null && type.equals(Property.SELECTION_PROPERTY));
if (isListType) {
currentProperty = (BasePropertyImpl) NavajoFactory.getInstance().createProperty(currentDocument, myName, cardinality, description, direction);
} else {
currentProperty = (BasePropertyImpl) NavajoFactory.getInstance().createProperty(currentDocument, myName, type, myValue, length, description, direction, subtype);
}
if (messageStack.isEmpty()) {
throw NavajoFactory.getInstance().createNavajoException("Can not parse property without being inside a message, probably an input error");
}
Message current = messageStack.peek();
current.addProperty(currentProperty);
BaseMessageImpl arrayParent = (BaseMessageImpl) current.getArrayParentMessage();
if (arrayParent != null && arrayParent.isArrayMessage()) {
definitionProperty = arrayParent.getPropertyDefinition(myName);
if (definitionProperty != null) {
if (description == null || "".equals(description)) {
description = definitionProperty.getDescription();
}
if (direction == null || "".equals(direction)) {
direction = definitionProperty.getDirection();
}
if (type == null || "".equals(type)) {
type = definitionProperty.getType();
}
if (plength == null) {
length = definitionProperty.getLength();
}
if (subType == null) {
if (definitionProperty.getSubType() != null) {
currentProperty.setSubType(definitionProperty.getSubType());
}
} else {
if (definitionProperty.getSubType() != null) {
/**
* Concatenated subtypes. The if the same key of a subtype is present
* in both the property and the definition property.
*/
currentProperty.setSubType(definitionProperty.getSubType() + "," + subType);
}
}
}
}
if (subType == null && NavajoFactory.getInstance().getDefaultSubtypeForType(type) != null) {
currentProperty.setSubType(NavajoFactory.getInstance().getDefaultSubtypeForType(type));
} else {
currentProperty.setSubType(subType);
}
if (type == null && current.isArrayMessage()) {
logger.info("Found undefined property: " + currentProperty.getName());
}
isListType = (type != null && type.equals(Property.SELECTION_PROPERTY));
if (isListType && definitionProperty != null) {
if (cardinality == null) {
cardinality = definitionProperty.getCardinality();
}
type = Property.SELECTION_PROPERTY;
List<Selection> l = definitionProperty.getAllSelections();
for (int i = 0; i < l.size(); i++) {
BaseSelectionImpl s1 = (BaseSelectionImpl) l.get(i);
BaseSelectionImpl s2 = (BaseSelectionImpl) s1.copy(currentDocument);
currentProperty.addSelection(s2);
}
}
currentProperty.setType(type);
currentProperty.setDescription(description);
currentProperty.setDirection(direction);
currentProperty.setCardinality(cardinality);
currentProperty.setLength(length);
currentProperty.setExtends(extendsProp);
currentProperty.setKey(key);
currentProperty.setReference(reference);
currentProperty.setBind(bind);
currentProperty.setMethod(method);
}
use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class Access method setInDoc.
public void setInDoc(Navajo in) {
if (in == null) {
return;
}
this.inDoc = in;
if (in.getHeader() != null) {
// Check for parent access id header.
String s = in.getHeader().getHeaderAttribute("parentaccessid");
if (s != null && !s.equals("")) {
setParentAccessId(s);
}
}
// Check if __parms__ exists.
Message msg = inDoc.getMessage("__parms__");
if (msg == null) {
msg = NavajoFactory.getInstance().createMessage(inDoc, "__parms__");
try {
inDoc.addMessage(msg);
} catch (NavajoException e) {
logger.error("Error: ", e);
}
}
}
use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class ITAsyncClient method testAsync.
@Test
@Ignore
public void testAsync() throws Exception {
final ManualAsyncClient ac = new AsyncClientImpl();
String service = "club/InitUpdateClub";
System.err.println(TestConfig.NAVAJO_TEST_SERVER.getValue());
ac.setServer(TestConfig.NAVAJO_TEST_SERVER.getValue());
ac.setUsername(TestConfig.NAVAJO_TEST_USER.getValue());
ac.setPassword(TestConfig.NAVAJO_TEST_PASS.getValue());
Navajo input = NavajoFactory.getInstance().createNavajo();
final NavajoResponseHandler showOutput = new NavajoResponseHandler() {
@Override
public void onResponse(Navajo n) {
logger.info("Navajo finished!");
try {
StringWriter sw = new StringWriter();
n.write(sw);
logger.info("Response2 : {}", sw);
} catch (NavajoException e) {
logger.error("Error: ", e);
}
}
@Override
public void onFail(Throwable t) {
logger.error("whoops: ", t);
}
@Override
public Throwable getCaughtException() {
return null;
}
};
for (int i = 0; i < 10; i++) {
ac.callService(input, service, showOutput);
logger.info("Exchange sent");
}
Thread.sleep(10000);
}
Aggregations