use of com.dexels.navajo.server.ConditionErrorException in project navajo by Dexels.
the class NavajoMap method continueAfterRun.
public void continueAfterRun() throws UserException, ConditionErrorException, AuthorizationException {
try {
// Get task if if trigger was specified.
if (trigger != null) {
taskId = inDoc.getHeader().getSchedule();
logger.info("************************************************* TASKID: {}", taskId);
}
// Call sorted.
if (performOrderBy) {
inDoc.performOrdering();
}
Message error = inDoc.getMessage("error");
if (error != null && breakOnException) {
String errMsg = error.getProperty("message").getValue();
String errCode = error.getProperty("code").getValue();
int errorCode = -1;
try {
errorCode = Integer.parseInt(errCode);
} catch (NumberFormatException e) {
e.printStackTrace(Access.getConsoleWriter(access));
}
throw new UserException(errorCode, errMsg);
} else if (error != null) {
logger.debug("EXCEPTIONERROR OCCURED, BUT WAS EXCEPTION HANDLING WAS SET TO FALSE, RETURNING....");
return;
}
boolean authenticationError = false;
Message aaaError = inDoc.getMessage(AuthorizationException.AUTHENTICATION_ERROR_MESSAGE);
if (aaaError == null) {
aaaError = inDoc.getMessage(AuthorizationException.AUTHORIZATION_ERROR_MESSAGE);
} else {
authenticationError = true;
}
if (aaaError != null) {
AuditLog.log("NavajoMap", "THROWING AUTHORIZATIONEXCEPTION IN NAVAJOMAP" + aaaError.getProperty("User").getValue(), Level.WARNING, access.accessID);
throw new AuthorizationException(authenticationError, !authenticationError, aaaError.getProperty("User").getValue(), aaaError.getProperty("Message").getValue());
}
if (breakOnConditionError && inDoc.getMessage("ConditionErrors") != null) {
logger.debug("BREAKONCONDITIONERROR WAS SET TO TRUE, RETURNING CONDITION ERROR");
throw new ConditionErrorException(inDoc);
} else if (inDoc.getMessage("ConditionErrors") != null) {
logger.debug("BREAKONCONDITIONERROR WAS SET TO FALSE, RETURNING....");
return;
}
// Set property directions.
processPropertyDirections(inDoc);
// Suppress properties.
processSuppressedProperties(inDoc);
// Show properties.
processShowProperties(inDoc);
// Reset property directives
this.suppressProperties = null;
this.inputProperties = null;
this.outputProperties = null;
this.showProperties = null;
if (!compare.equals("")) {
Message other = inMessage.getMessage(compare);
Message rec = inDoc.getMessage(compare);
if (other == null || rec == null) {
isEqual = false;
} else {
isEqual = other.isEqual(rec, this.skipProperties);
}
} else {
outDoc = inDoc;
}
} finally {
synchronized (waitForResult) {
waitForResult.notify();
}
if (myResponseListener != null) {
myResponseListener.onNavajoResponse(this);
}
}
}
use of com.dexels.navajo.server.ConditionErrorException in project navajo by Dexels.
the class ArticleBaseServlet method writeJSONErrorResponse.
public static void writeJSONErrorResponse(APIException exception, HttpServletResponse response) throws IOException {
ObjectMapper mapper = new ObjectMapper();
ObjectNode rootNode = mapper.createObjectNode();
ObjectNode error = mapper.createObjectNode();
// We want all condition errors to be returned to the user.
if (exception.getCause() != null && exception.getCause() instanceof ConditionErrorException) {
ConditionErrorException conditionErrorException = (ConditionErrorException) exception.getCause();
ArrayNode messages = mapper.createArrayNode();
for (Message message : conditionErrorException.getNavajo().getMessage("ConditionErrors").getElements()) {
ObjectNode conditionError = mapper.createObjectNode();
// It should always be there
String id = message.getProperty("Id").getValue();
conditionError.put("id", id);
// Try to find the localized description.
String description = resourceBundle.getValidationDescription(id, null, VALIDATION_DESCRIPTION_LANG);
if (description != null) {
conditionError.put("description", description);
} else {
conditionError.put("description", message.getProperty("Description").getValue());
}
messages.add(conditionError);
}
error.set("messages", messages);
} else {
error.put("message", exception.getErrorCode().getDescription());
}
error.put("code", exception.getErrorCode().getExternalCode());
rootNode.set("error", error);
response.setStatus(exception.getErrorCode().getHttpStatusCode());
PrintWriter pw = response.getWriter();
mapper.writer().writeValue(pw, rootNode);
response.getWriter().close();
}
Aggregations