Search in sources :

Example 6 with IActionOutput

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

the class ActionDelegate method executeAction.

/**
 * Wires up inputs outputs and resources to an Action and executes it.
 */
@Override
protected boolean executeAction() throws Throwable {
    // 
    // Set inputs
    // 
    InputErrorCallback errorCallback = new InputErrorCallback();
    for (IActionInput input : getActionDefinition().getInputs()) {
        Object inputValue = input.getValue();
        if (input instanceof ActionInputConstant) {
            // if the input is coming from the component definition section,
            // do parameter replacement on the string and the result of that
            // is the input value
            inputValue = input.getStringValue(true);
        }
        errorCallback.setValue(inputValue);
        actionHarness.setValue(input.getName(), inputValue, errorCallback, COMPATIBILITY_FORMATTER, ALTERNATE_INDEX_FORMATTER);
    }
    // 
    // Set resources
    // 
    ResourceCallback resourceCallback = new ResourceCallback();
    for (IActionResource res : getActionDefinition().getResources()) {
        actionHarness.setValue(res.getName(), res.getInputStream(), resourceCallback, COMPATIBILITY_FORMATTER, ALTERNATE_INDEX_FORMATTER);
    }
    // 
    // Provide output stream for the streaming action. We are going to look for all outputs where
    // type = "content", and derive output streams to hand to the IStreamingAction.
    // 
    Map<String, IContentItem> outputContentItems = new HashMap<String, IContentItem>();
    StreamOutputErrorCallback streamingOutputCallback = new StreamOutputErrorCallback();
    OuputStreamGenerator outputStreamGenerator = new OuputStreamGenerator(outputContentItems);
    IActionOutput[] contentOutputs = getActionDefinition().getOutputs(ActionSequenceDocument.CONTENT_TYPE);
    if (contentOutputs.length > 0) {
        for (IActionOutput contentOutput : contentOutputs) {
            outputStreamGenerator.setContentOutput(contentOutput);
            actionHarness.setValue(contentOutput.getName(), outputStreamGenerator, streamingOutputCallback, STREAM_APPENDER_FORMATTER, COMPATIBILITY_FORMATTER, ALTERNATE_INDEX_FORMATTER);
        }
    }
    // 
    if (actionBean instanceof IAction) {
        ((IAction) actionBean).execute();
    }
    // 
    for (IActionOutput output : actionDefintionOutputs) {
        String outputName = output.getName();
        outputName = COMPATIBILITY_FORMATTER.format(outputName);
        // if streaming output, add it to the context and don't try to get it from the Action bean
        if (outputContentItems.containsKey(outputName)) {
            IContentItem contentItem = outputContentItems.get(outputName);
            if (!(contentItem instanceof SimpleContentItem)) {
                // this is a special output for streaming actions and does not require a bean accessor
                output.setValue(contentItem);
            }
        } else if (actionHarness.isReadable(outputName)) {
            Object outputVal = actionHarness.getValue(outputName);
            output.setValue(outputVal);
        } else {
            if (loggingLevel <= ILogger.WARN) {
                warn(// $NON-NLS-1$
                Messages.getInstance().getString(// $NON-NLS-1$
                "ActionDelegate.WARN_OUTPUT_NOT_READABLE", outputName, output.getType(), actionBean.getClass().getSimpleName()));
            }
        }
    }
    return true;
}
Also used : IAction(org.pentaho.platform.api.action.IAction) HashMap(java.util.HashMap) ActionInputConstant(org.pentaho.actionsequence.dom.ActionInputConstant) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) SimpleContentItem(org.pentaho.platform.engine.core.output.SimpleContentItem) IActionResource(org.pentaho.actionsequence.dom.IActionResource) IActionInput(org.pentaho.actionsequence.dom.IActionInput) IContentItem(org.pentaho.platform.api.repository.IContentItem)

Example 7 with IActionOutput

use of org.pentaho.actionsequence.dom.IActionOutput 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 8 with IActionOutput

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

the class MDXBaseComponent method runQuery.

protected boolean runQuery(final IPentahoConnection localConnection, final String rawQuery) {
    try {
        if (localConnection == null) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0008_NO_CONNECTION"));
            return false;
        }
        if (!localConnection.initialized()) {
            // $NON-NLS-1$
            error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0008_NO_CONNECTION"));
            return false;
        }
        if (rawQuery == null) {
            error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0001_QUERY_NOT_SPECIFIED", // $NON-NLS-1$
            getActionName()));
            return false;
        }
        if (ComponentBase.debug) {
            // $NON-NLS-1$
            debug(Messages.getInstance().getString("MDXBaseComponent.DEBUG_RUNNING_QUERY", rawQuery));
        }
        // execute the query, read the results and cache them
        IPentahoResultSet resultSet = localConnection.executeQuery(rawQuery);
        if (resultSet != null && resultSet instanceof MDXResultSet) {
            // BISERVER-3543 - set the result set to return formatted cell values
            boolean formattedCellValues = false;
            if (isDefinedInput(FORMATTED_CELL_VALUES)) {
                formattedCellValues = getInputBooleanValue(FORMATTED_CELL_VALUES, false);
            }
            ((MDXResultSet) resultSet).setFormattedCellValues(formattedCellValues);
        }
        rSet = resultSet;
        if (resultSet != null) {
            MdxQueryAction mdxQueryAction = (MdxQueryAction) getActionDefinition();
            IActionOutput actionOutput = mdxQueryAction.getOutputResultSet();
            if (actionOutput != null) {
                actionOutput.setValue(resultSet);
            }
            return true;
        } else {
            // close the connection
            error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0006_EXECUTE_FAILED", // $NON-NLS-1$
            getActionName()));
            localConnection.close();
            return false;
        }
    } catch (Exception e) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("MDXBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), e);
    }
    return false;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) MDXResultSet(org.pentaho.platform.plugin.services.connections.mondrian.MDXResultSet) MdxQueryAction(org.pentaho.actionsequence.dom.actions.MdxQueryAction) UnifiedRepositoryException(org.pentaho.platform.api.repository2.unified.UnifiedRepositoryException)

Example 9 with IActionOutput

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

Example 10 with IActionOutput

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

the class XQueryBaseComponent method runFinalQuery.

protected boolean runFinalQuery(final IPentahoConnection localConnection, final String rawQuery, final String[] columnTypes) {
    XQueryAction xQueryAction = (XQueryAction) getActionDefinition();
    boolean success = false;
    String finalQuery = applyInputsToFormat(rawQuery);
    // execute the query, read the results and cache them
    try {
        IPentahoResultSet resultSet = ((XQConnection) localConnection).executeQuery(finalQuery, columnTypes);
        if (resultSet != null) {
            if (!xQueryAction.getLive().getBooleanValue(true)) {
                resultSet = resultSet.memoryCopy();
            }
            try {
                IActionOutput resultSetOutput = xQueryAction.getOutputResultSet();
                if (resultSetOutput != null) {
                    resultSetOutput.setValue(resultSet);
                }
                success = true;
            } finally {
                resultSet.close();
            }
        }
    } catch (XPathException e) {
        error(Messages.getInstance().getErrorString("XQueryBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), // $NON-NLS-1$
        e);
    }
    return success;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) XQConnection(org.pentaho.platform.plugin.services.connections.xquery.XQConnection) XPathException(net.sf.saxon.trans.XPathException) IActionOutput(org.pentaho.actionsequence.dom.IActionOutput) XQueryAction(org.pentaho.actionsequence.dom.actions.XQueryAction)

Aggregations

IActionOutput (org.pentaho.actionsequence.dom.IActionOutput)15 IActionInput (org.pentaho.actionsequence.dom.IActionInput)5 ArrayList (java.util.ArrayList)3 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)3 HashMap (java.util.HashMap)2 AbstractRelationalDbAction (org.pentaho.actionsequence.dom.actions.AbstractRelationalDbAction)2 HQLQueryAction (org.pentaho.actionsequence.dom.actions.HQLQueryAction)2 JavascriptAction (org.pentaho.actionsequence.dom.actions.JavascriptAction)2 IPentahoConnection (org.pentaho.commons.connection.IPentahoConnection)2 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)2 IContentItem (org.pentaho.platform.api.repository.IContentItem)2 Format (java.text.Format)1 MessageFormat (java.text.MessageFormat)1 XPathException (net.sf.saxon.trans.XPathException)1 Context (org.mozilla.javascript.Context)1 NativeArray (org.mozilla.javascript.NativeArray)1 Scriptable (org.mozilla.javascript.Scriptable)1 ScriptableObject (org.mozilla.javascript.ScriptableObject)1 ActionInput (org.pentaho.actionsequence.dom.ActionInput)1 ActionInputConstant (org.pentaho.actionsequence.dom.ActionInputConstant)1