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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations