Search in sources :

Example 1 with ActionSequenceException

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

the class RuntimeContext method executeLoop.

private void executeLoop(final IActionParameter loopParm, final IPentahoResultSet loopSet, final IActionSequence sequence, final IActionCompleteListener doneListener, final IExecutionListener execListener, final boolean async, boolean peekOnly) throws ActionSequenceException {
    // execute the actions
    int loopCount = -1;
    // to the first record. This is to resolve multiple levels of looping on resultset.
    if (loopSet.isScrollable()) {
        loopSet.beforeFirst();
    }
    if (peekOnly && !(loopSet instanceof IPeekable)) {
        throw new ActionExecutionException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "RuntimeContext.ERROR_0033_NOT_PEEKABLE"), session.getName(), instanceId, getActionSequence().getSequenceName(), null);
    }
    Object[] row = peekOnly ? ((IPeekable) loopSet).peek() : loopSet.next();
    Object[][] headerSet = loopSet.getMetaData().getColumnHeaders();
    // TODO handle OLAP result sets
    Object[] headers = headerSet[0];
    while (row != null) {
        loopCount++;
        if (RuntimeContext.debug) {
            debug(Messages.getInstance().getString("RuntimeContext.DEBUG_EXECUTING_ACTION", // $NON-NLS-1$
            Integer.toString(loopCount)));
        }
        if (execListener != null) {
            execListener.loop(this, loopCount);
        }
        if (loopParm != null) {
            IActionParameter ap;
            for (int columnNo = 0; columnNo < headers.length; columnNo++) {
                String name = headers[columnNo].toString();
                Object value = row[columnNo];
                String type = null;
                if (value instanceof String) {
                    type = IActionParameter.TYPE_STRING;
                } else if (value instanceof Date) {
                    type = IActionParameter.TYPE_DATE;
                } else if ((value instanceof Long) || (value instanceof Integer)) {
                    type = IActionParameter.TYPE_INTEGER;
                } else if ((value instanceof BigDecimal) || (value instanceof Double) || (value instanceof Float)) {
                    type = IActionParameter.TYPE_DECIMAL;
                } else if (value instanceof String[]) {
                    type = IActionParameter.TYPE_STRING;
                } else if (value == null) {
                    // $NON-NLS-1$
                    warn(Messages.getInstance().getString("RuntimeContext.WARN_VARIABLE_IN_LOOP_IS_NULL", name));
                } else {
                    type = IActionParameter.TYPE_OBJECT;
                    warn(Messages.getInstance().getString("RuntimeContext.WARN_VARIABLE_IN_LOOP_NOT_RECOGNIZED", name, // $NON-NLS-1$
                    value.getClass().toString()));
                }
                // TODO make sure any previous loop values are removed
                ap = paramManager.getInput(name);
                if (ap == null) {
                    ap = new ActionParameter(name, type, value, null, null);
                    addInputParameter(name, ap);
                } else {
                    ap.dispose();
                    ap.setValue(value);
                }
            }
        }
        try {
            performActions(sequence, doneListener, execListener, async);
        } catch (ActionSequenceException e) {
            e.setLoopIndex(loopCount);
            throw e;
        }
        row = peekOnly ? ((IPeekable) loopSet).peek() : loopSet.next();
    }
    status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
}
Also used : ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) ActionParameter(org.pentaho.platform.engine.services.actionsequence.ActionParameter) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) Date(java.util.Date) BigDecimal(java.math.BigDecimal) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IPeekable(org.pentaho.commons.connection.IPeekable)

Example 2 with ActionSequenceException

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

the class RuntimeContext method performActions.

private void performActions(final IActionSequence sequence, final IActionCompleteListener doneListener, final IExecutionListener execListener, final boolean async) throws ActionSequenceException {
    IConditionalExecution conditional = sequence.getConditionalExecution();
    if (conditional != null) {
        try {
            if (!conditional.shouldExecute(paramManager.getAllParameters(), RuntimeContext.logger)) {
                // audit(MessageTypes.ACTION_SEQUENCE_EXECUTE_CONDITIONAL, MessageTypes.NOT_EXECUTED, "", 0); //$NON-NLS-1$ //$NON-NLS-2$
                if (RuntimeContext.debug) {
                    // $NON-NLS-1$
                    this.debug(Messages.getInstance().getString("RuntimeContext.INFO_ACTION_NOT_EXECUTED"));
                }
                status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
                return;
            }
        } catch (Exception ex) {
            // $NON-NLS-1$
            currentComponent = "";
            status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
            throw new ActionExecutionException(Messages.getInstance().getErrorString(// $NON-NLS-1$
            "RuntimeContext.ERROR_0032_CONDITIONAL_EXECUTION_FAILED"), // $NON-NLS-1$
            ex, session.getName(), instanceId, getActionSequence().getSequenceName(), null);
        }
    }
    List defList = sequence.getActionDefinitionsAndSequences();
    Object listItem;
    for (Iterator actIt = defList.iterator(); actIt.hasNext(); ) {
        listItem = actIt.next();
        if (listItem instanceof IActionSequence) {
            executeSequence((IActionSequence) listItem, doneListener, execListener, async);
        } else if (listItem instanceof ISolutionActionDefinition) {
            ISolutionActionDefinition actionDef = (ISolutionActionDefinition) listItem;
            currentComponent = actionDef.getComponentName();
            paramManager.setCurrentParameters(actionDef);
            try {
                executeAction(actionDef, parameterProviders, doneListener, execListener, async);
                paramManager.addOutputParameters(actionDef);
            } catch (ActionSequenceException ex) {
                // $NON-NLS-1$
                currentComponent = "";
                status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
                throw ex;
            }
        }
        if (promptStatus == IRuntimeContext.PROMPT_NOW) {
            break;
        }
        // $NON-NLS-1$
        currentComponent = "";
    }
    status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
}
Also used : ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) IActionSequence(org.pentaho.platform.api.engine.IActionSequence) ISolutionActionDefinition(org.pentaho.platform.api.engine.ISolutionActionDefinition) IConditionalExecution(org.pentaho.platform.api.engine.IConditionalExecution) Iterator(java.util.Iterator) List(java.util.List) ArrayList(java.util.ArrayList) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) InvalidParameterException(org.pentaho.platform.api.engine.InvalidParameterException) ActionValidationException(org.pentaho.platform.api.engine.ActionValidationException) ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) ActionInitializationException(org.pentaho.platform.api.engine.ActionInitializationException) ActionSequencePromptException(org.pentaho.platform.api.engine.ActionSequencePromptException) FileNotFoundException(java.io.FileNotFoundException) XmlParseException(org.pentaho.platform.api.util.XmlParseException) UnresolvedParameterException(org.pentaho.platform.api.engine.UnresolvedParameterException) PluginBeanException(org.pentaho.platform.api.engine.PluginBeanException) IOException(java.io.IOException)

Example 3 with ActionSequenceException

use of org.pentaho.platform.api.engine.ActionSequenceException 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 ActionSequenceException

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

the class ActionDelegateTest method execute.

@SuppressWarnings("unchecked")
private void execute(String actionSequenceFile, boolean exceptionOnError, IAction... actions) throws ActionSequenceException {
    TestPluginManager pm = (TestPluginManager) PentahoSystem.get(IPluginManager.class);
    for (IAction action : actions) {
        pm.addAction(action);
    }
    // content outputs will write to this stream
    out = new ByteArrayOutputStream();
    // create SimpleOutputHandler (to handle outputs of type "response.content")
    outputHandler = new SimpleOutputHandler(out, false);
    outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
    IPentahoSession session = new StandaloneSession("system");
    ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
    outputHandler.setSession(session);
    String xactionStr = ServiceTestHelper.getXAction("src/test/resources/solution/test/ActionDelegateTest", actionSequenceFile);
    // execute the action sequence, providing the outputHandler created above
    IRuntimeContext rc = solutionEngine.execute(xactionStr, actionSequenceFile, "action sequence to test the TestAction", false, true, null, false, new HashMap(), outputHandler, null, new SimpleUrlFactory(""), new ArrayList());
    int status = rc.getStatus();
    if (status == IRuntimeContext.PARAMETERS_FAIL || status == IRuntimeContext.RUNTIME_CONTEXT_RESOLVE_FAIL || status == IRuntimeContext.RUNTIME_STATUS_FAILURE || status == IRuntimeContext.RUNTIME_STATUS_INITIALIZE_FAIL || status == IRuntimeContext.RUNTIME_STATUS_SETUP_FAIL) {
        throw new ActionSequenceException("Action sequence failed!");
    }
}
Also used : ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IAction(org.pentaho.platform.api.action.IAction) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HashMap(java.util.HashMap) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IPluginManager(org.pentaho.platform.api.engine.IPluginManager) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext)

Example 5 with ActionSequenceException

use of org.pentaho.platform.api.engine.ActionSequenceException 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

ActionSequenceException (org.pentaho.platform.api.engine.ActionSequenceException)8 ArrayList (java.util.ArrayList)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 Iterator (java.util.Iterator)3 List (java.util.List)3 ActionValidationException (org.pentaho.platform.api.engine.ActionValidationException)3 Date (java.util.Date)2 Map (java.util.Map)2 ActionExecutionException (org.pentaho.platform.api.engine.ActionExecutionException)2 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)2 IActionSequence (org.pentaho.platform.api.engine.IActionSequence)2 UnresolvedParameterException (org.pentaho.platform.api.engine.UnresolvedParameterException)2 ActionParameter (org.pentaho.platform.engine.services.actionsequence.ActionParameter)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 BigDecimal (java.math.BigDecimal)1 Test (org.junit.Test)1 IPeekable (org.pentaho.commons.connection.IPeekable)1 IAction (org.pentaho.platform.api.action.IAction)1