Search in sources :

Example 1 with ActionInitializationException

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

the class RuntimeContext method executeAction.

private void executeAction(final ISolutionActionDefinition actionDefinition, final Map pParameterProviders, final IActionCompleteListener doneListener, final IExecutionListener execListener, final boolean async) throws ActionInitializationException, ActionExecutionException, UnresolvedParameterException {
    this.parameterProviders = pParameterProviders;
    // TODO get audit setting from action definition
    long start = new Date().getTime();
    if (audit) {
        // $NON-NLS-1$
        audit(MessageTypes.COMPONENT_EXECUTE_START, MessageTypes.START, "", 0);
    }
    try {
        // resolve the parameters
        resolveParameters();
    } catch (UnresolvedParameterException ex) {
        audit(MessageTypes.COMPONENT_EXECUTE_FAILED, MessageTypes.VALIDATION, Messages.getInstance().getErrorString("RuntimeContext.ERROR_0013_BAD_PARAMETERS"), // $NON-NLS-1$
        0);
        if (doneListener != null) {
            doneListener.actionComplete(this);
        }
        status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
        ex.setActionClass(actionDefinition.getComponentName());
        ex.setStepDescription(actionDefinition.getDescription());
        throw ex;
    }
    status = IRuntimeContext.RUNTIME_CONTEXT_RESOLVE_OK;
    if (RuntimeContext.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("RuntimeContext.DEBUG_PRE-EXECUTE_AUDIT"));
    }
    List auditPre = actionDefinition.getPreExecuteAuditList();
    audit(auditPre);
    // initialize the component
    IComponent component = actionDefinition.getComponent();
    if (RuntimeContext.debug) {
        debug(Messages.getInstance().getString("RuntimeContext.DEBUG_SETTING_LOGGING", // $NON-NLS-1$
        Logger.getLogLevelName(loggingLevel)));
    }
    component.setLoggingLevel(loggingLevel);
    if (RuntimeContext.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("RuntimeContext.DEBUG_INITIALIZING_COMPONENT"));
    }
    boolean initResult = false;
    try {
        initResult = component.init();
    /*
       * 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 ActionInitializationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "RuntimeContext.ERROR_0016_COMPONENT_INITIALIZE_FAILED"), // $NON-NLS-1$
        t, session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
    }
    if (!initResult) {
        status = IRuntimeContext.RUNTIME_STATUS_INITIALIZE_FAIL;
        audit(MessageTypes.COMPONENT_EXECUTE_FAILED, MessageTypes.VALIDATION, Messages.getInstance().getErrorString("RuntimeContext.ERROR_0016_COMPONENT_INITIALIZE_FAILED"), // $NON-NLS-1$
        0);
        if (doneListener != null) {
            doneListener.actionComplete(this);
        }
        throw new ActionInitializationException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "RuntimeContext.ERROR_0016_COMPONENT_INITIALIZE_FAILED"), session.getName(), instanceId, getActionSequence().getSequenceName(), component.getActionDefinition());
    }
    try {
        executeComponent(actionDefinition);
    } catch (ActionExecutionException ex) {
        if (doneListener != null) {
            doneListener.actionComplete(this);
        }
        throw ex;
    }
    if (RuntimeContext.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("RuntimeContext.DEBUG_POST-EXECUTE_AUDIT"));
    }
    List auditPost = actionDefinition.getPostExecuteAuditList();
    audit(auditPost);
    if (audit) {
        long end = new Date().getTime();
        // $NON-NLS-1$
        audit(MessageTypes.COMPONENT_EXECUTE_END, MessageTypes.END, "", (int) (end - start));
    }
    if (doneListener != null) {
        doneListener.actionComplete(this);
    }
    if (execListener != null) {
        execListener.action(this, actionDefinition);
    }
}
Also used : UnresolvedParameterException(org.pentaho.platform.api.engine.UnresolvedParameterException) ActionInitializationException(org.pentaho.platform.api.engine.ActionInitializationException) IComponent(org.pentaho.platform.api.engine.IComponent) List(java.util.List) ArrayList(java.util.ArrayList) ActionExecutionException(org.pentaho.platform.api.engine.ActionExecutionException) Date(java.util.Date)

Aggregations

ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 ActionExecutionException (org.pentaho.platform.api.engine.ActionExecutionException)1 ActionInitializationException (org.pentaho.platform.api.engine.ActionInitializationException)1 IComponent (org.pentaho.platform.api.engine.IComponent)1 UnresolvedParameterException (org.pentaho.platform.api.engine.UnresolvedParameterException)1