Search in sources :

Example 6 with ConditionErrorException

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);
        }
    }
}
Also used : ConditionErrorException(com.dexels.navajo.server.ConditionErrorException) Message(com.dexels.navajo.document.Message) AuthorizationException(com.dexels.navajo.script.api.AuthorizationException) UserException(com.dexels.navajo.script.api.UserException)

Example 7 with ConditionErrorException

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();
}
Also used : ConditionErrorException(com.dexels.navajo.server.ConditionErrorException) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) Message(com.dexels.navajo.document.Message) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) PrintWriter(java.io.PrintWriter)

Aggregations

ConditionErrorException (com.dexels.navajo.server.ConditionErrorException)7 UserException (com.dexels.navajo.script.api.UserException)6 Message (com.dexels.navajo.document.Message)4 AuthorizationException (com.dexels.navajo.script.api.AuthorizationException)4 MappableException (com.dexels.navajo.script.api.MappableException)3 SystemException (com.dexels.navajo.script.api.SystemException)3 Navajo (com.dexels.navajo.document.Navajo)2 NavajoException (com.dexels.navajo.document.NavajoException)2 IOException (java.io.IOException)2 APIException (com.dexels.navajo.article.APIException)1 AsyncClient (com.dexels.navajo.client.async.AsyncClient)1 ManualAsyncClient (com.dexels.navajo.client.async.ManualAsyncClient)1 Binary (com.dexels.navajo.document.types.Binary)1 CompilationException (com.dexels.navajo.script.api.CompilationException)1 FatalException (com.dexels.navajo.script.api.FatalException)1 ConditionData (com.dexels.navajo.server.ConditionData)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 PrintWriter (java.io.PrintWriter)1