Search in sources :

Example 6 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 List loopList, final IActionSequence sequence, final IActionCompleteListener doneListener, final IExecutionListener execListener, final boolean async) throws ActionSequenceException {
    // execute the actions
    int loopCount = -1;
    for (Iterator it = loopList.iterator(); it.hasNext(); ) {
        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);
        }
        Object loopVar = it.next();
        if (loopParm != null) {
            IActionParameter ap;
            if (loopVar instanceof Map) {
                // $NON-NLS-1$
                ap = new ActionParameter(loopParm.getName(), "property-map", loopVar, null, null);
            } else {
                // $NON-NLS-1$
                ap = new ActionParameter(loopParm.getName(), "string", loopVar, null, null);
            }
            addInputParameter(loopParm.getName(), ap);
        }
        try {
            performActions(sequence, doneListener, execListener, async);
        } catch (ActionSequenceException e) {
            e.setLoopIndex(loopCount);
            throw e;
        }
        if (promptStatus == IRuntimeContext.PROMPT_NOW) {
            return;
        }
    }
    status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
}
Also used : ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) Iterator(java.util.Iterator) ActionParameter(org.pentaho.platform.engine.services.actionsequence.ActionParameter) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) Map(java.util.Map) HashMap(java.util.HashMap)

Example 7 with ActionSequenceException

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

the class SolutionEngine method executeInternal.

@SuppressWarnings({ "unchecked" })
protected IRuntimeContext executeInternal(final String sequencePath, final String processId, final boolean async, final boolean instanceEnds, final Map parameterProviderMap, final String actionSequenceXML) {
    long start = System.currentTimeMillis();
    parameterProviders.putAll(parameterProviderMap);
    parameterProviders.put(PentahoSystem.SCOPE_GLOBAL, PentahoSystem.getGlobalParameters());
    // load the solution action document
    if (debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("SolutionEngine.DEBUG_LOADING_ACTION_DEFINITION"));
    }
    IActionSequence actionSequence = null;
    if (actionSequenceXML != null) {
        actionSequence = createActionSequenceFromXml(actionSequenceXML);
    } else {
        actionSequence = createActionSequence(sequencePath);
    }
    if (actionSequence == null) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("SolutionEngine.ERROR_0007_ACTION_EXECUTION_FAILED"));
        status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
        long end = System.currentTimeMillis();
        AuditHelper.audit(session.getId(), session.getName(), sequencePath, getObjectName(), processId, MessageTypes.INSTANCE_FAILED, runtime.getInstanceId(), Messages.getInstance().getErrorString("SolutionEngine.ERROR_0007_ACTION_EXECUTION_FAILED"), ((float) (end - start) / 1000), // $NON-NLS-1$
        this);
        return runtime;
    }
    runtime.setActionSequence(actionSequence);
    if (parameterXsl != null) {
        runtime.setParameterXsl(parameterXsl);
    }
    if (forcePrompt) {
        runtime.setPromptStatus(IRuntimeContext.PROMPT_WAITING);
    } else {
        runtime.setPromptStatus(IRuntimeContext.PROMPT_NO);
    }
    boolean validating = true;
    try {
        runtime.validateSequence(FilenameUtils.getName(sequencePath), execListener);
        validating = false;
        runtime.executeSequence(doneListener, execListener, async);
        if (instanceEnds) {
            long end = System.currentTimeMillis();
            AuditHelper.audit(session.getId(), session.getName(), sequencePath, getObjectName(), processId, MessageTypes.INSTANCE_END, runtime.getInstanceId(), "", ((float) (end - start) / 1000), // $NON-NLS-1$
            this);
        }
        status = runtime.getStatus();
    } catch (ActionSequenceException ex) {
        String errorMsg = null;
        status = validating ? IRuntimeContext.RUNTIME_CONTEXT_VALIDATE_FAIL : IRuntimeContext.RUNTIME_STATUS_FAILURE;
        // This next line is a bit of a workaround, to make up for a deficiency in the SolutionEngine api.
        // What would be nice is to have the exception that is being caught here actually be thrown out of this
        // method. However, the ISolutionEngine interface that this class implements doesn't allow exceptions to be
        // thrown from this method. Since we can't change the signature of public API's with a minor release we need
        // a
        // workaround. We've created an new error method in PentahoMessenger that takes the exception and stuffs it
        // in
        // the messages list maintained within PentahoMessenger. Callers of this method that want to know if an
        // ActionSequenceException occurred should first call getStatus(). If the status does not
        // indicate success then call getMessages() and check if there is an exception in the list of messages.
        error(ex);
        long end = System.currentTimeMillis();
        AuditHelper.audit(session.getId(), session.getName(), sequencePath, getObjectName(), processId, MessageTypes.INSTANCE_FAILED, runtime.getInstanceId(), errorMsg, ((float) (end - start) / 1000), // $NON-NLS-1$
        this);
    }
    return runtime;
}
Also used : ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) IActionSequence(org.pentaho.platform.api.engine.IActionSequence)

Example 8 with ActionSequenceException

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

the class MessageFormatter method formatFailureMessage.

@Override
public void formatFailureMessage(final String mimeType, final IRuntimeContext context, final StringBuffer messageBuffer, final List defaultMessages, final boolean showStacktrace) {
    if ((context == null) && (defaultMessages == null)) {
        // something went badly wrong
        formatErrorMessage(mimeType, Messages.getInstance().getString("MessageFormatter.ERROR_0001_REQUEST_FAILED"), Messages.getInstance().getString("MessageFormatter.ERROR_0002_COULD_NOT_PROCESS"), // $NON-NLS-1$ //$NON-NLS-2$
        messageBuffer);
    } else {
        if (context == null) {
            // $NON-NLS-1$
            formatErrorMessage(mimeType, "Failed", defaultMessages, messageBuffer);
        } else {
            // By convention, if the solution engine encounters an exception while trying to execute and xaction,
            // the engine will stick the caught exception in the runtime context messages. Here we're looking through
            // the messages to see if an an action sequence exception was caught and stored with the messages.
            // If so we'll format and return an exception message.
            ActionSequenceException theFailureException = null;
            List theMessages = context.getMessages();
            for (Object msg : theMessages) {
                if (msg instanceof ActionSequenceException) {
                    theFailureException = (ActionSequenceException) msg;
                    break;
                }
            }
            if (theFailureException != null) {
                formatExceptionMessage(mimeType, theFailureException, messageBuffer, showStacktrace);
            } else {
                // $NON-NLS-1$
                formatErrorMessage(mimeType, "Failed", theMessages, messageBuffer);
            }
        }
    }
}
Also used : ActionSequenceException(org.pentaho.platform.api.engine.ActionSequenceException) ArrayList(java.util.ArrayList) List(java.util.List)

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