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