Search in sources :

Example 1 with IPreProcessingAction

use of org.pentaho.platform.api.action.IPreProcessingAction in project pentaho-platform by pentaho.

the class ActionDelegate method validateAction.

/**
 * Validation of Action input values should happen in the {@link IAction#execute()} This method is used as a pre
 * execution hook where we setup as much runtime information as possible prior to the actual execute call.
 */
@Override
protected boolean validateAction() {
    if (actionBean == null) {
        throw new IllegalArgumentException(Messages.getInstance().getErrorString(// $NON-NLS-1$
        "ActionDelegate.ERROR_0007_NO_ACTION_BEAN_SPECIFIED"));
    }
    // 
    if (actionBean instanceof ILoggingAction) {
        ((ILoggingAction) actionBean).setLogger(LogFactory.getLog(actionBean.getClass()));
    }
    // 
    if (actionBean instanceof ISessionAwareAction) {
        ((ISessionAwareAction) actionBean).setSession(getSession());
    }
    actionDefintionInputs = getActionDefinition().getInputs();
    actionDefintionOutputs = getActionDefinition().getOutputs();
    // 
    // If an Action is action-definition aware, then here is the place (prior to
    // execution) to tell it about the action definition.
    // 
    List<String> inputNames = new ArrayList<String>();
    for (IActionInput input : actionDefintionInputs) {
        inputNames.add(input.getName());
    }
    List<String> outputNames = new ArrayList<String>();
    for (IActionOutput output : actionDefintionOutputs) {
        outputNames.add(output.getName());
    }
    if (actionBean instanceof IDefinitionAwareAction) {
        IDefinitionAwareAction definitionAwareAction = (IDefinitionAwareAction) actionBean;
        definitionAwareAction.setInputNames(inputNames);
        definitionAwareAction.setOutputNames(outputNames);
    }
    // 
    if (actionBean instanceof IPreProcessingAction) {
        try {
            ((IPreProcessingAction) actionBean).doPreExecution();
        } catch (ActionPreProcessingException e) {
            throw new RuntimeException(e);
        }
    }
    // we do not use the return value to indicate failure.
    return true;
}
Also used : IActionInput(org.pentaho.actionsequence.dom.IActionInput) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) ILoggingAction(org.pentaho.platform.api.action.ILoggingAction) ArrayList(java.util.ArrayList) ActionPreProcessingException(org.pentaho.platform.api.action.ActionPreProcessingException) ISessionAwareAction(org.pentaho.platform.api.action.ISessionAwareAction) IDefinitionAwareAction(org.pentaho.platform.api.action.IDefinitionAwareAction) IPreProcessingAction(org.pentaho.platform.api.action.IPreProcessingAction)

Aggregations

ArrayList (java.util.ArrayList)1 IActionInput (org.pentaho.actionsequence.dom.IActionInput)1 IActionOutput (org.pentaho.actionsequence.dom.IActionOutput)1 ActionPreProcessingException (org.pentaho.platform.api.action.ActionPreProcessingException)1 IDefinitionAwareAction (org.pentaho.platform.api.action.IDefinitionAwareAction)1 ILoggingAction (org.pentaho.platform.api.action.ILoggingAction)1 IPreProcessingAction (org.pentaho.platform.api.action.IPreProcessingAction)1 ISessionAwareAction (org.pentaho.platform.api.action.ISessionAwareAction)1