use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class CompiledScript method checkValidationRules.
/**
* Deprecated method to check validation errors. Use <validations> block
* inside webservice script instead.
*
* @param conditions
* @param inMessage
* @param outMessage
* @return
* @throws NavajoException
* @throws SystemException
* @throws UserException
*/
private final Message[] checkValidationRules(ConditionData[] conditions, Navajo inMessage, Navajo outMessage, Access a) throws SystemException, UserException {
if (conditions == null) {
return null;
}
List<Message> messages = new ArrayList<>();
int index = 0;
for (int i = 0; i < conditions.length; i++) {
ConditionData condition = conditions[i];
boolean valid = false;
try {
valid = com.dexels.navajo.parser.Condition.evaluate(condition.condition, inMessage, a);
} catch (com.dexels.navajo.expression.api.TMLExpressionException ee) {
throw new UserException(-1, "Invalid condition: " + ee.getMessage(), ee);
}
if (!valid) {
String eval = com.dexels.navajo.parser.Expression.replacePropertyValues(condition.condition, inMessage);
Message msg = NavajoFactory.getInstance().createMessage(outMessage, "failed" + (index++));
Property prop0 = NavajoFactory.getInstance().createProperty(outMessage, "Id", Property.STRING_PROPERTY, condition.id + "", 0, "", Property.DIR_OUT);
// Evaluate comment as expression.
String description = "";
try {
Operand o = Expression.evaluate(condition.comment, inMessage);
description = o.value + "";
} catch (Exception e) {
description = condition.comment;
}
Property prop1 = NavajoFactory.getInstance().createProperty(outMessage, "Description", Property.STRING_PROPERTY, description, 0, "", Property.DIR_OUT);
msg.addProperty(prop0);
msg.addProperty(prop1);
if (System.getenv("DEBUG_SCRIPTS") != null && System.getenv("DEBUG_SCRIPTS").equals("true")) {
Property prop2 = NavajoFactory.getInstance().createProperty(outMessage, "FailedExpression", Property.STRING_PROPERTY, condition.condition, 0, "", Property.DIR_OUT);
Property prop3 = NavajoFactory.getInstance().createProperty(outMessage, "EvaluatedExpression", Property.STRING_PROPERTY, eval, 0, "", Property.DIR_OUT);
msg.addProperty(prop2);
msg.addProperty(prop3);
}
messages.add(msg);
}
}
if (!messages.isEmpty()) {
Message[] msgArray = new Message[messages.size()];
messages.toArray(msgArray);
return msgArray;
} else {
return null;
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class ServiceCommand method handleError.
private void handleError(Navajo result) throws UserException, AuthorizationException, ConditionErrorException {
Message error = result.getMessage("error");
if (error != null) {
String errMsg = error.getProperty("message").getValue();
String errCode = error.getProperty("code").getValue();
int errorCode = -1;
try {
errorCode = Integer.parseInt(errCode);
} catch (NumberFormatException e) {
logger.error("Error: ", e);
}
throw new UserException(errorCode, errMsg);
}
boolean authenticationError = false;
Message aaaError = result.getMessage(AuthorizationException.AUTHENTICATION_ERROR_MESSAGE);
if (aaaError == null) {
aaaError = result.getMessage(AuthorizationException.AUTHORIZATION_ERROR_MESSAGE);
} else {
authenticationError = true;
}
if (aaaError != null) {
throw new AuthorizationException(authenticationError, !authenticationError, aaaError.getProperty("User").getValue(), aaaError.getProperty("Message").getValue());
}
if (result.getMessage("ConditionErrors") != null) {
throw new ConditionErrorException(result);
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class ServiceCommand method performCall.
protected Navajo performCall(ArticleRuntime runtime, String name, Navajo n, String instance) throws APIException {
try {
Navajo result = dispatcher.handle(n, instance, true);
handleError(result);
return result;
} catch (UserException | AuthorizationException | FatalException e) {
throw new APIException(e.getMessage(), e, APIErrorCode.InternalError);
} catch (ConditionErrorException e) {
throw new APIException(e.getMessage(), e, APIErrorCode.ConditionError);
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class XMLStreamMap method setNewline.
/**
* @param b
*/
public void setNewline(boolean b) throws UserException {
try {
newLineFlag = true;
xtw.writeCharacters("\n");
} catch (Exception e) {
throw new UserException(453, e.getMessage());
}
}
use of com.dexels.navajo.script.api.UserException in project navajo by Dexels.
the class XMLStreamMap method load.
// @Override
@Override
public void load(Access access) throws MappableException, UserException {
try {
content = new Binary();
OutputStream ob = content.getOutputStream();
XMLOutputFactory xof = XMLOutputFactory.newInstance();
OutputStreamWriter out = new OutputStreamWriter(ob, "UTF8");
xtw = xof.createXMLStreamWriter(out);
xtw.writeStartDocument("UTF-8", "1.0");
xtw.setPrefix("", docSpecUrl);
xtw.writeCharacters("\n");
} catch (Exception e) {
throw new UserException(450, e.getMessage());
}
}
Aggregations