Search in sources :

Example 1 with ActionValidationException

use of org.pentaho.platform.api.engine.ActionValidationException in project pentaho-platform by pentaho.

the class RuntimeContext method validateComponents.

private void validateComponents(final IActionSequence sequence, final IExecutionListener execListener) throws ActionValidationException {
    List defList = sequence.getActionDefinitionsAndSequences();
    Object listItem;
    for (Iterator it = defList.iterator(); it.hasNext(); ) {
        listItem = it.next();
        if (listItem instanceof IActionSequence) {
            validateComponents((IActionSequence) listItem, execListener);
        } else if (listItem instanceof ISolutionActionDefinition) {
            ISolutionActionDefinition actionDef = (ISolutionActionDefinition) listItem;
            if (RuntimeContext.debug) {
                // $NON-NLS-1$
                debug(Messages.getInstance().getString("RuntimeContext.DEBUG_VALIDATING_COMPONENT", actionDef.getComponentName()));
            }
            IComponent component = null;
            try {
                component = resolveComponent(actionDef, instanceId, processId, session);
                component.setLoggingLevel(loggingLevel);
                // allow the ActionDefinition to cache the component
                actionDef.setComponent(component);
                paramManager.setCurrentParameters(actionDef);
            /*
           * We need to catch checked and unchecked exceptions here so we can create an ActionSequeceException with
           * contextual information, including the root cause. Allowing unchecked exceptions to pass through would
           * prevent valuable feedback in the log or response.
           */
            } catch (Throwable ex) {
                ActionDefinition actionDefinition = new ActionDefinition((Element) actionDef.getNode(), null);
                throw new ActionValidationException(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0009_COULD_NOT_CREATE_COMPONENT", // $NON-NLS-1$
                actionDef.getComponentName().trim()), // $NON-NLS-1$
                ex, session.getName(), instanceId, getActionSequence().getSequenceName(), actionDefinition.getDescription(), actionDefinition.getComponentName());
            }
            int validateResult = IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_OK;
            try {
                validateResult = component.validate();
            /*
           * We need to catch checked and unchecked exceptions here so we can create an ActionSequeceException with
           * contextual information, including the root cause. Allowing unchecked exceptions to pass through would
           * prevent valuable feedback in the log or response.
           */
            } catch (Throwable t) {
                throw new ActionValidationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
                "RuntimeContext.ERROR_0035_ACTION_VALIDATION_FAILED"), // $NON-NLS-1$
                t, session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
            }
            if (validateResult != IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_OK) {
                throw new ActionValidationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
                "RuntimeContext.ERROR_0035_ACTION_VALIDATION_FAILED"), session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
            }
            paramManager.addOutputParameters(actionDef);
            // $NON-NLS-1$
            setCurrentComponent("");
            setCurrentActionDef(null);
        }
    }
    if (execListener != null) {
        execListener.validated(this);
    }
}
Also used : IActionSequence(org.pentaho.platform.api.engine.IActionSequence) ISolutionActionDefinition(org.pentaho.platform.api.engine.ISolutionActionDefinition) ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) IComponent(org.pentaho.platform.api.engine.IComponent) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) ActionDefinition(org.pentaho.actionsequence.dom.actions.ActionDefinition) ISolutionActionDefinition(org.pentaho.platform.api.engine.ISolutionActionDefinition)

Example 2 with ActionValidationException

use of org.pentaho.platform.api.engine.ActionValidationException in project pentaho-platform by pentaho.

the class MessageFormatterTest method shouldNotAddStacktraceWhenShowStacktraceIsFalse.

@Test
public void shouldNotAddStacktraceWhenShowStacktraceIsFalse() throws Exception {
    MessageFormatter mf = new MessageFormatter() {

        @Override
        String getTemplate(StringBuffer messageBuffer) {
            try {
                return IOUtils.toString(this.getClass().getResourceAsStream("viewActionErrorTestTemplate.html"), "UTF-8");
            } catch (IOException e) {
                return null;
            }
        }
    };
    StringBuffer messageBuffer = new StringBuffer();
    mf.formatExceptionMessage(MessageFormatter.HTML_MIME_TYPE, new ActionValidationException("Test Error"), messageBuffer, false);
    // details controls are hidden
    // stacktrace is not added
    assertEquals("<div id=\"controls\" hidden>" + "<a href=\"#\" id=\"details-show\" class=\"showLink\" onclick=\"showHide('details');return false;\">View " + "Details</a>" + "<a href=\"#\" id=\"details-hide\" class=\"hideLink\" onclick=\"showHide('details');return false;\">Hide " + "Details</a>" + "</div>" + "<div id=\"details\" class=\"details\"><span class=\"label\">%STACK_TRACE_LABEL%</span><pre " + "class=\"stackTrace\">%STACK_TRACE%<pre></div>", messageBuffer.toString());
}
Also used : ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) IOException(java.io.IOException) Test(org.junit.Test)

Example 3 with ActionValidationException

use of org.pentaho.platform.api.engine.ActionValidationException in project pentaho-platform by pentaho.

the class MessageFormatterTest method shouldAddStacktraceWhenShowStacktraceIsTrue.

@Test
public void shouldAddStacktraceWhenShowStacktraceIsTrue() throws Exception {
    MessageFormatter mf = new MessageFormatter() {

        @Override
        String getTemplate(StringBuffer messageBuffer) {
            try {
                return IOUtils.toString(this.getClass().getResourceAsStream("viewActionErrorTestTemplate.html"), "UTF-8");
            } catch (IOException e) {
                return null;
            }
        }

        @Override
        String getStacktrace(ActionSequenceException exception) {
            return "Error stacktrace";
        }
    };
    StringBuffer messageBuffer = new StringBuffer();
    mf.formatExceptionMessage(MessageFormatter.HTML_MIME_TYPE, new ActionValidationException("Test Error"), messageBuffer, true);
    // details controls are not hidden
    // stacktrace is added
    assertEquals("<div id=\"controls\">" + "<a href=\"#\" id=\"details-show\" class=\"showLink\" onclick=\"showHide('details');return false;\">View " + "Details</a>" + "<a href=\"#\" id=\"details-hide\" class=\"hideLink\" onclick=\"showHide('details');return false;\">Hide " + "Details</a>" + "</div>" + "<div id=\"details\" class=\"details\"><span class=\"label\">Stack Trace:</span><pre " + "class=\"stackTrace\">Error stacktrace<pre></div>", messageBuffer.toString());
}
Also used : ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) IOException(java.io.IOException) Test(org.junit.Test)

Example 4 with ActionValidationException

use of org.pentaho.platform.api.engine.ActionValidationException in project pentaho-platform by pentaho.

the class RuntimeContext method executeSequence.

public void executeSequence(final IActionCompleteListener doneListener, final IExecutionListener execListener, final boolean async) throws ActionSequenceException {
    paramManager.resetParameters();
    long start = new Date().getTime();
    status = IRuntimeContext.RUNTIME_STATUS_RUNNING;
    // create an IActionDef object
    List actionDefinitions = actionSequence.getActionDefinitionsAndSequences();
    if (actionDefinitions == null) {
        audit(MessageTypes.ACTION_SEQUENCE_FAILED, MessageTypes.VALIDATION, Messages.getInstance().getErrorString("RuntimeContext.ERROR_0011_NO_VALID_ACTIONS"), // $NON-NLS-1$
        0);
        status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
        throw new ActionValidationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "RuntimeContext.ERROR_0011_NO_VALID_ACTIONS"), session.getName(), instanceId, getActionSequence().getSequenceName(), null);
    }
    setLoggingLevel(loggingLevel);
    if (RuntimeContext.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("RuntimeContext.DEBUG_EXECUTING_ACTIONS"));
    }
    paramManager.setCurrentParameters(null);
    try {
        resolveParameters();
        if (execListener != null) {
            execListener.loaded(this);
        }
        executeSequence(actionSequence, doneListener, execListener, async);
        if (this.feedbackAllowed() && ((promptStatus != IRuntimeContext.PROMPT_NO) || (xformBody.length() > 0) || (parameterTemplate != null))) {
            sendFeedbackForm();
        }
        paramManager.setCurrentParameters(null);
        if (audit) {
            // $NON-NLS-1$
            audit(MessageTypes.ACTION_SEQUENCE_END, MessageTypes.END, "", (int) (new Date().getTime() - start));
        }
        if (!isPromptPending()) {
            Map returnParamMap = paramManager.getReturnParameters();
            for (Iterator it = returnParamMap.entrySet().iterator(); it.hasNext(); ) {
                Map.Entry mapEntry = (Map.Entry) it.next();
                String paramName = (String) mapEntry.getKey();
                ParameterManager.ReturnParameter returnParam = (ParameterManager.ReturnParameter) mapEntry.getValue();
                if (returnParam == null) {
                    // $NON-NLS-1$
                    error(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0029_SAVE_PARAM_NOT_FOUND", paramName));
                } else {
                    if (IParameterProvider.SCOPE_SESSION.equals(returnParam.destinationName)) {
                        session.setAttribute(returnParam.destinationParameter, returnParam.value);
                        if (RuntimeContext.debug) {
                            // $NON-NLS-1$
                            debug(paramName + " - session - " + returnParam.destinationParameter);
                        }
                    } else if ("response".equals(returnParam.destinationName)) {
                        // $NON-NLS-1$
                        if (outputHandler != null) {
                            outputHandler.setOutput(returnParam.destinationParameter, returnParam.value);
                        } else {
                            // $NON-NLS-1$
                            info(Messages.getInstance().getString("RuntimeContext.INFO_NO_OUTPUT_HANDLER"));
                        }
                        if (RuntimeContext.debug) {
                            // $NON-NLS-1$
                            debug(paramName + " - response - " + returnParam.destinationParameter);
                        }
                    } else if (PentahoSystem.SCOPE_GLOBAL.equals(returnParam.destinationName)) {
                        PentahoSystem.putInGlobalAttributesMap(returnParam.destinationParameter, returnParam.value);
                        if (RuntimeContext.debug) {
                            // $NON-NLS-1$
                            debug(paramName + " - global - " + returnParam.destinationParameter);
                        }
                    } else {
                        // Unrecognized scope
                        warn(Messages.getInstance().getString("RuntimeContext.WARN_UNRECOGNIZED_SCOPE", returnParam.destinationName, // $NON-NLS-1$
                        returnParam.destinationParameter));
                    }
                }
            }
        }
    } catch (UnresolvedParameterException ex) {
        status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
        audit(MessageTypes.ACTION_SEQUENCE_FAILED, MessageTypes.VALIDATION, Messages.getInstance().getErrorString("RuntimeContext.ERROR_0013_BAD_PARAMETERS"), // $NON-NLS-1$
        0);
        throw ex;
    } catch (ActionSequenceException ex) {
        status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
        // $NON-NLS-1$
        audit(MessageTypes.ACTION_SEQUENCE_FAILED, MessageTypes.EXECUTION, "", (int) (new Date().getTime() - start));
        throw ex;
    } catch (IOException ex) {
        status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
        // $NON-NLS-1$
        audit(MessageTypes.ACTION_SEQUENCE_FAILED, MessageTypes.EXECUTION, "", (int) (new Date().getTime() - start));
        throw new ActionSequenceException(ex);
    }
}
Also used : ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) UnresolvedParameterException(org.pentaho.platform.api.engine.UnresolvedParameterException) ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) IParameterManager(org.pentaho.platform.api.engine.IParameterManager) IOException(java.io.IOException) Date(java.util.Date) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) Map(java.util.Map) HashMap(java.util.HashMap)

Aggregations

ActionValidationException (org.pentaho.platform.api.engine.ActionValidationException)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Test (org.junit.Test)2 ActionSequenceException (org.pentaho.platform.api.engine.ActionSequenceException)2 Date (java.util.Date)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 ActionDefinition (org.pentaho.actionsequence.dom.actions.ActionDefinition)1 IActionSequence (org.pentaho.platform.api.engine.IActionSequence)1 IComponent (org.pentaho.platform.api.engine.IComponent)1 IParameterManager (org.pentaho.platform.api.engine.IParameterManager)1 ISolutionActionDefinition (org.pentaho.platform.api.engine.ISolutionActionDefinition)1 UnresolvedParameterException (org.pentaho.platform.api.engine.UnresolvedParameterException)1