Search in sources :

Example 6 with IActionInput

use of org.pentaho.actionsequence.dom.IActionInput in project pentaho-platform by pentaho.

the class ResultSetCompareComponentTest method createResultSetCompareAction.

private static ResultSetCompareAction createResultSetCompareAction(IPentahoResultSet resultSet1, IPentahoResultSet resultSet2, Integer compareColumnNum, boolean outputMismatches, boolean stopOnError) {
    ResultSetCompareAction resultSetCompareAction = mock(ResultSetCompareAction.class);
    IActionInput resultSetInput1 = ActionInputConstant.NULL_INPUT;
    if (resultSet1 != null) {
        resultSetInput1 = mock(IActionInput.class);
        when(resultSetInput1.getValue()).thenReturn(resultSet1);
    }
    when(resultSetCompareAction.getResultSet1()).thenReturn(resultSetInput1);
    IActionInput resultSetInput2 = ActionInputConstant.NULL_INPUT;
    if (resultSet2 != null) {
        resultSetInput2 = mock(IActionInput.class);
        when(resultSetInput2.getValue()).thenReturn(resultSet2);
    }
    when(resultSetCompareAction.getResultSet2()).thenReturn(resultSetInput2);
    IActionInput compareColumnNumInput = ActionInputConstant.NULL_INPUT;
    if (compareColumnNum != null) {
        compareColumnNumInput = mock(IActionInput.class);
        when(compareColumnNumInput.getStringValue()).thenReturn(String.valueOf(compareColumnNum));
    }
    when(resultSetCompareAction.getCompareColumnNum()).thenReturn(compareColumnNumInput);
    IActionInput outputMismatchesInput = mock(IActionInput.class);
    when(outputMismatchesInput.getStringValue()).thenReturn(String.valueOf(outputMismatches));
    when(resultSetCompareAction.getOutputMismatches()).thenReturn(outputMismatchesInput);
    IActionInput stopOnErrorInput = mock(IActionInput.class);
    when(stopOnErrorInput.getStringValue()).thenReturn(String.valueOf(stopOnError));
    when(resultSetCompareAction.getStopOnError()).thenReturn(stopOnErrorInput);
    return resultSetCompareAction;
}
Also used : IActionInput(org.pentaho.actionsequence.dom.IActionInput) ResultSetCompareAction(org.pentaho.actionsequence.dom.actions.ResultSetCompareAction)

Example 7 with IActionInput

use of org.pentaho.actionsequence.dom.IActionInput in project pentaho-platform by pentaho.

the class SQLBaseComponent method validateAction.

/**
 * validates the action. checks to verify inputs are available to execute
 *
 * - verify query is available - verify connection is available, via jndi, connection string, or prepared component -
 * verify output is specified
 */
@Override
public boolean validateAction() {
    boolean result = true;
    IActionDefinition actionDefinition = getActionDefinition();
    String actionName = getActionName();
    if (actionDefinition instanceof AbstractRelationalDbAction) {
        AbstractRelationalDbAction relationalDbAction = (AbstractRelationalDbAction) actionDefinition;
        IActionInput query = relationalDbAction.getQuery();
        IActionInput dbUrl = relationalDbAction.getDbUrl();
        IActionInput jndi = relationalDbAction.getJndi();
        IActionInput sharedConnection = relationalDbAction.getSharedConnection();
        if (query == ActionInputConstant.NULL_INPUT) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0001_QUERY_NOT_SPECIFIED", actionName));
            result = false;
        }
        if ((jndi == ActionInputConstant.NULL_INPUT) && (dbUrl == ActionInputConstant.NULL_INPUT) && (sharedConnection == ActionInputConstant.NULL_INPUT)) {
            error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0002_CONNECTION_NOT_SPECIFIED", // $NON-NLS-1$
            actionName));
            result = false;
        }
    } else if (actionDefinition instanceof SqlConnectionAction) {
        SqlConnectionAction sqlConnectionAction = (SqlConnectionAction) actionDefinition;
        IActionInput dbUrl = sqlConnectionAction.getDbUrl();
        IActionInput jndi = sqlConnectionAction.getJndi();
        if ((jndi == ActionInputConstant.NULL_INPUT) && (dbUrl == ActionInputConstant.NULL_INPUT)) {
            error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0002_CONNECTION_NOT_SPECIFIED", // $NON-NLS-1$
            actionName));
            result = false;
        }
    } else {
        error(Messages.getInstance().getErrorString("ComponentBase.ERROR_0001_UNKNOWN_ACTION_TYPE", // $NON-NLS-1$
        actionDefinition.getElement().asXML()));
        result = false;
    }
    return result;
}
Also used : IActionInput(org.pentaho.actionsequence.dom.IActionInput) IActionDefinition(org.pentaho.actionsequence.dom.IActionDefinition) SqlConnectionAction(org.pentaho.actionsequence.dom.actions.SqlConnectionAction) AbstractRelationalDbAction(org.pentaho.actionsequence.dom.actions.AbstractRelationalDbAction)

Example 8 with IActionInput

use of org.pentaho.actionsequence.dom.IActionInput in project pentaho-platform by pentaho.

the class SQLBaseComponent method executeAction.

/**
 * determines state of component, and executes accordingly.
 *
 * various inputs that impact the state include:
 *
 * live - returns a live result set vs. an in memory copy transform - transform a result set based on additional
 * inputs prepared_component - if available, use existing connection from prepared component max_rows - sets the
 * number of rows that should be returned in result sets
 *
 * The specified output also impacts the state of the execution. If prepared_component is defined as an output, setup
 * the query but delay execution.
 */
@Override
protected boolean executeAction() {
    IActionDefinition actionDefinition = getActionDefinition();
    try {
        if (actionDefinition instanceof AbstractRelationalDbAction) {
            AbstractRelationalDbAction relationalDbAction = (AbstractRelationalDbAction) actionDefinition;
            // Added by Arijit Chatterjee
            IActionInput queryTimeoutInput = relationalDbAction.getQueryTimeout();
            IActionInput maxRowsInput = relationalDbAction.getMaxRows();
            IActionInput readOnlyInput = relationalDbAction.getReadOnly();
            String baseQuery = getQuery();
            if (baseQuery == null) {
                error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0001_QUERY_NOT_SPECIFIED", // $NON-NLS-1$
                actionDefinition.getDescription()));
                return false;
            }
            IPreparedComponent sharedConnection = (IPreparedComponent) relationalDbAction.getSharedConnection().getValue();
            if (readOnlyInput != ActionInputConstant.NULL_INPUT) {
                this.setReadOnly(readOnlyInput.getBooleanValue());
            }
            if (sharedConnection != null) {
                connectionOwner = false;
                IPentahoConnection conn = sharedConnection.shareConnection();
                if (conn == null) {
                    error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0002_CONNECTION_NOT_AVAILABLE", // $NON-NLS-1$
                    getActionName()));
                    return false;
                } else if (conn.getDatasourceType() == IPentahoConnection.SQL_DATASOURCE) {
                    connection = conn;
                } else {
                    error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0001_INVALID_CONNECTION_TYPE", // $NON-NLS-1$
                    getActionName()));
                    return false;
                }
            } else {
                dispose();
                connection = getDatasourceConnection();
            }
            if (connection == null) {
                return false;
            }
            // query and set this component as the output. This query will be run later from a subreport.
            if (relationalDbAction.getOutputPreparedStatement() != null) {
                prepareQuery(baseQuery);
                IActionOutput actionOutput = relationalDbAction.getOutputPreparedStatement();
                if (actionOutput != null) {
                    actionOutput.setValue(this);
                }
                return true;
            }
            // int maxRows = relationalDbAction.getMaxRows().getIntValue(-1);
            if (maxRowsInput != ActionInputConstant.NULL_INPUT) {
                this.setMaxRows(maxRowsInput.getIntValue());
            }
            // Added by Arijit Chatterjee.Sets the value of timeout. Default is -1, if parameter not found.
            if (queryTimeoutInput != ActionInputConstant.NULL_INPUT) {
                this.setQueryTimeout(queryTimeoutInput.getIntValue());
            }
            if (relationalDbAction.getPerformTransform().getBooleanValue(false)) {
                // The side effect of
                runQuery(baseQuery, false);
                // transform rSet here
                rSet = PentahoDataTransmuter.crossTab(rSet, relationalDbAction.getTransformPivotColumn().getIntValue(-1) - 1, relationalDbAction.getTransformMeasuresColumn().getIntValue(-1) - 1, relationalDbAction.getTransformSortColumn().getIntValue(0) - 1, (Format) relationalDbAction.getTransformPivotDataFormat().getValue(), (Format) relationalDbAction.getTransformSortDataFormat().getValue(), relationalDbAction.getTransformOrderOutputColumns().getBooleanValue(false));
                IActionOutput actionOutput = relationalDbAction.getOutputResultSet();
                if (actionOutput != null) {
                    actionOutput.setValue(rSet);
                }
                return true;
            } else {
                return runQuery(baseQuery, relationalDbAction.getLive().getBooleanValue(false));
            }
        } else if (actionDefinition instanceof SqlConnectionAction) {
            SqlConnectionAction sqlConnectionAction = (SqlConnectionAction) actionDefinition;
            dispose();
            connection = getDatasourceConnection();
            if (connection == null) {
                return false;
            } else {
                IActionOutput actionOutput = sqlConnectionAction.getOutputConnection();
                if (actionOutput != null) {
                    actionOutput.setValue(this);
                    return true;
                } else {
                    return false;
                }
            }
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), e);
    }
    return false;
}
Also used : IPentahoConnection(org.pentaho.commons.connection.IPentahoConnection) Format(java.text.Format) IActionInput(org.pentaho.actionsequence.dom.IActionInput) IActionDefinition(org.pentaho.actionsequence.dom.IActionDefinition) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) SqlConnectionAction(org.pentaho.actionsequence.dom.actions.SqlConnectionAction) IPreparedComponent(org.pentaho.platform.api.data.IPreparedComponent) AbstractRelationalDbAction(org.pentaho.actionsequence.dom.actions.AbstractRelationalDbAction)

Example 9 with IActionInput

use of org.pentaho.actionsequence.dom.IActionInput in project pentaho-platform by pentaho.

the class XQueryBaseComponent method executeAction.

@Override
protected boolean executeAction() {
    boolean result = false;
    IActionDefinition actionDefinition = getActionDefinition();
    // int queryTimeout = -1;
    if (actionDefinition instanceof XQueryAction) {
        XQueryAction xQueryAction = (XQueryAction) actionDefinition;
        // Not implemented yet
        // IActionInput queryTimeoutInput = xQueryAction.getQueryTimeout();
        IActionInput maxRowsInput = xQueryAction.getMaxRows();
        if (maxRowsInput != ActionInputConstant.NULL_INPUT) {
            this.setMaxRows(maxRowsInput.getIntValue());
        }
        IPreparedComponent sharedConnection = (IPreparedComponent) xQueryAction.getSharedConnection().getValue();
        if (sharedConnection != null) {
            connectionOwner = false;
            connection = sharedConnection.shareConnection();
        } else {
            connection = getConnection();
        }
        if (connection == null) {
            error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0002_CONNECTION_NOT_AVAILABLE", // $NON-NLS-1$
            getActionName()));
        } else if (connection.getDatasourceType() != IPentahoConnection.XML_DATASOURCE) {
            error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0001_INVALID_CONNECTION_TYPE", // $NON-NLS-1$
            getActionName()));
        } else {
            result = runQuery(connection, xQueryAction.getQuery().getStringValue());
        }
    } else if (actionDefinition instanceof XQueryConnectionAction) {
        XQueryConnectionAction xQueryConnectionAction = (XQueryConnectionAction) getActionDefinition();
        connection = getConnection();
        if (connection == null) {
            error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0002_CONNECTION_NOT_AVAILABLE", // $NON-NLS-1$
            getActionName()));
        } else if (connection.getDatasourceType() != IPentahoConnection.XML_DATASOURCE) {
            error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0001_INVALID_CONNECTION_TYPE", // $NON-NLS-1$
            getActionName()));
        } else {
            xQueryConnectionAction.getOutputConnection().setValue(this);
            result = true;
        }
    }
    return result;
}
Also used : IActionInput(org.pentaho.actionsequence.dom.IActionInput) IActionDefinition(org.pentaho.actionsequence.dom.IActionDefinition) XQueryConnectionAction(org.pentaho.actionsequence.dom.actions.XQueryConnectionAction) XQueryAction(org.pentaho.actionsequence.dom.actions.XQueryAction) IPreparedComponent(org.pentaho.platform.api.data.IPreparedComponent)

Example 10 with IActionInput

use of org.pentaho.actionsequence.dom.IActionInput 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

IActionInput (org.pentaho.actionsequence.dom.IActionInput)15 IActionOutput (org.pentaho.actionsequence.dom.IActionOutput)5 JFreeReportAction (org.pentaho.actionsequence.dom.actions.JFreeReportAction)4 TableModel (javax.swing.table.TableModel)3 IActionDefinition (org.pentaho.actionsequence.dom.IActionDefinition)3 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)3 PentahoTableModel (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableModel)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 ActionInput (org.pentaho.actionsequence.dom.ActionInput)2 IActionResource (org.pentaho.actionsequence.dom.IActionResource)2 AbstractRelationalDbAction (org.pentaho.actionsequence.dom.actions.AbstractRelationalDbAction)2 SqlConnectionAction (org.pentaho.actionsequence.dom.actions.SqlConnectionAction)2 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)2 PentahoTableDataFactory (org.pentaho.platform.plugin.action.jfreereport.helper.PentahoTableDataFactory)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1