Search in sources :

Example 11 with UserException

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;
    }
}
Also used : ConditionData(com.dexels.navajo.server.ConditionData) Message(com.dexels.navajo.document.Message) Operand(com.dexels.navajo.document.Operand) ArrayList(java.util.ArrayList) NavajoException(com.dexels.navajo.document.NavajoException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException) SystemException(com.dexels.navajo.script.api.SystemException) ConditionErrorException(com.dexels.navajo.server.ConditionErrorException) CompilationException(com.dexels.navajo.script.api.CompilationException) UserException(com.dexels.navajo.script.api.UserException) Property(com.dexels.navajo.document.Property)

Example 12 with UserException

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);
    }
}
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 13 with UserException

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

Example 14 with UserException

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());
    }
}
Also used : UserException(com.dexels.navajo.script.api.UserException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException)

Example 15 with UserException

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());
    }
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) OutputStreamWriter(java.io.OutputStreamWriter) Binary(com.dexels.navajo.document.types.Binary) UserException(com.dexels.navajo.script.api.UserException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) UserException(com.dexels.navajo.script.api.UserException) MappableException(com.dexels.navajo.script.api.MappableException)

Aggregations

UserException (com.dexels.navajo.script.api.UserException)113 MappableException (com.dexels.navajo.script.api.MappableException)54 IOException (java.io.IOException)33 NavajoException (com.dexels.navajo.document.NavajoException)25 Message (com.dexels.navajo.document.Message)22 SQLException (java.sql.SQLException)19 SystemException (com.dexels.navajo.script.api.SystemException)18 Binary (com.dexels.navajo.document.types.Binary)14 ConditionErrorException (com.dexels.navajo.server.ConditionErrorException)13 Property (com.dexels.navajo.document.Property)12 ArrayList (java.util.ArrayList)12 Navajo (com.dexels.navajo.document.Navajo)11 AuthorizationException (com.dexels.navajo.script.api.AuthorizationException)11 ResultSet (java.sql.ResultSet)11 MappingException (com.dexels.navajo.script.api.MappingException)10 ResultSetMetaData (java.sql.ResultSetMetaData)9 Element (org.w3c.dom.Element)8 CompilationException (com.dexels.navajo.script.api.CompilationException)7 File (java.io.File)7 NodeList (org.w3c.dom.NodeList)7