use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class ForAll 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.FALSE;
}
}
} catch (SystemException ex) {
logger.error("Error: ", ex);
}
}
} catch (NavajoException ex) {
throw new TMLExpressionException(this, "Error evaluating message path");
}
return Boolean.TRUE;
}
use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class GetPropertyAttribute method getAttribute.
public Object getAttribute(Object operand, String attribute) throws com.dexels.navajo.expression.api.TMLExpressionException {
Property p = null;
if (operand instanceof Property) {
p = (Property) operand;
} else {
String propertyName = operand.toString();
p = (getCurrentMessage() != null ? getCurrentMessage().getProperty(propertyName) : this.getNavajo().getProperty(propertyName));
}
if (p == null) {
throw new TMLExpressionException(this, "Property " + operand.toString() + " not found");
}
if (attribute.equals("direction")) {
return p.getDirection();
}
if (attribute.equals("type")) {
return p.getType();
}
if (attribute.equals("cardinality")) {
return p.getCardinality();
}
try {
throw new TMLExpressionException(this, "attribute " + attribute + " not found for property " + p.getFullPropertyName());
} catch (NavajoException e) {
throw new TMLExpressionException(this, "attribute " + attribute + " not found for unknown property ");
}
}
use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class NavajoMap method setAppendParms.
/**
* @param b
* @throws UserException
*
* if messageOffset is '/', the messages of the received Doc will be appended to the root param block or to the current param message.
*/
public final void setAppendParms(String messageOffset) throws UserException {
waitForResult();
try {
Message parm = (access.getCompiledScript().getCurrentParamMsg() == null ? access.getInDoc().getMessage("__parms__") : access.getCompiledScript().getCurrentParamMsg());
List<Message> list = null;
// If append message equals '/'.
if (messageOffset.equals(Navajo.MESSAGE_SEPARATOR)) {
list = inDoc.getAllMessages();
} else if (inDoc.getMessage(messageOffset) == null) {
return;
} else if (inDoc.getMessage(messageOffset).getType().equals(Message.MSG_TYPE_ARRAY)) {
list = new ArrayList<>();
list.add(inDoc.getMessage(messageOffset));
} else {
list = inDoc.getMessages(messageOffset);
}
for (int i = 0; i < list.size(); i++) {
Message inMsg = list.get(i);
// Clone message and append it to currentMsg if it exists, else
// directly under currentDoc.
// currentDoc.importMessage(inMsg)
Message clone = inDoc.copyMessage(inMsg, parm.getRootDoc());
parm.addMessage(clone, true);
}
} catch (NavajoException ne) {
throw new UserException(-1, ne.getMessage());
}
}
use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class AuditLogEvent method getEventNavajo.
@Override
public Navajo getEventNavajo() {
Navajo input = NavajoFactory.getInstance().createNavajo();
Message event = NavajoFactory.getInstance().createMessage(input, "__event__");
try {
input.addMessage(event);
Property eventMessage = NavajoFactory.getInstance().createProperty(input, "Message", Property.STRING_PROPERTY, getMessage(), 0, "", Property.DIR_OUT);
Property eventLevel = NavajoFactory.getInstance().createProperty(input, "Level", Property.STRING_PROPERTY, getLevel().getName(), 0, "", Property.DIR_OUT);
Property eventSubsystem = NavajoFactory.getInstance().createProperty(input, "Subsystem", Property.STRING_PROPERTY, getSubSystem(), 0, "", Property.DIR_OUT);
event.addProperty(eventMessage);
event.addProperty(eventLevel);
event.addProperty(eventSubsystem);
} catch (NavajoException e) {
logger.error("Error: ", e);
}
return input;
}
use of com.dexels.navajo.document.NavajoException in project navajo by Dexels.
the class Dispatcher method errorHandler.
/**
* Handles errors.
*
* @param access
* @param e
* @param inMessage
* @return the response error Navajo document.
*
* @throws FatalException
*/
private final Navajo errorHandler(Access access, Throwable e, Navajo inMessage) throws FatalException {
String message = "";
if (access != null) {
try {
message = e.getClass().toString() + ": " + e.getMessage() + ", " + e.toString() + ", " + e.getLocalizedMessage();
if (message.equalsIgnoreCase("")) {
message = "Undefined Error";
}
StringWriter swriter = new StringWriter();
PrintWriter writer = new PrintWriter(swriter);
e.printStackTrace(writer);
message += swriter.getBuffer().toString();
message += "\n";
swriter = new StringWriter();
writer = new PrintWriter(swriter);
// Remove some messages that might contain sensitive info.
if (inMessage != null) {
inMessage.removeInternalMessages();
}
inMessage.write(writer);
message += swriter.getBuffer().toString();
} catch (NavajoException tbe) {
throw new FatalException(tbe.getMessage());
}
} else {
// if no access was created, use the throwable message to be able to
// say *anything*
message += e.getMessage();
}
try {
Navajo out = generateErrorMessage(access, message, SystemException.SYSTEM_ERROR, 1, e);
if (access != null) {
access.setOutputDoc(out);
}
return out;
} catch (Exception ne) {
throw new FatalException(ne.getMessage(), ne);
}
}
Aggregations