use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class RuntimeContext method resolveParameters.
private void resolveParameters() throws UnresolvedParameterException {
Set inputNames = getInputNames();
Iterator inputNamesIterator = inputNames.iterator();
IActionParameter actionParameter;
List variables;
Iterator variablesIterator;
ActionParameterSource variable;
String sourceName;
String sourceValue;
Object variableValue = null;
IParameterProvider parameterProvider;
while (inputNamesIterator.hasNext()) {
variableValue = null;
String inputName = (String) inputNamesIterator.next();
actionParameter = paramManager.getCurrentInput(inputName);
if (actionParameter == null) {
throw new UnresolvedParameterException(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0031_INPUT_NOT_FOUND", // $NON-NLS-1$
inputName), session.getName(), instanceId, getActionSequence().getSequenceName(), null);
}
variables = actionParameter.getVariables();
variablesIterator = variables.iterator();
while (variablesIterator.hasNext()) {
variable = (ActionParameterSource) variablesIterator.next();
sourceName = variable.getSourceName();
sourceValue = variable.getValue();
variableValue = null;
// e.g. runtme.parent
if ("runtime".equals(sourceName)) {
// $NON-NLS-1$
// first check the standard variables
variableValue = getStringParameter(sourceValue, null);
if (variableValue == null) {
// now check the runtime data
variableValue = runtimeData.getStringProperty(sourceValue, null);
}
if (variableValue != null) {
break;
}
} else {
parameterProvider = (IParameterProvider) parameterProviders.get(sourceName);
if (parameterProvider == null) {
warn(Messages.getInstance().getString("RuntimeContext.WARN_REQUESTED_PARAMETER_SOURCE_NOT_AVAILABLE", sourceName, // $NON-NLS-1$
inputName));
} else {
variableValue = parameterProvider.getParameter(sourceValue);
if (variableValue != null) {
break;
}
}
}
}
if (variableValue == null) {
if (actionParameter.getValue() != null) {
if (actionParameter.hasDefaultValue()) {
if (PentahoSystem.trace) {
// $NON-NLS-1$
trace(Messages.getInstance().getString("RuntimeContext.TRACE_USING_DEFAULT_PARAMETER_VALUE", inputName));
}
} else {
if (PentahoSystem.trace) {
trace(Messages.getInstance().getString(// $NON-NLS-1$
"RuntimeContext.TRACE_INFO_USING_CURRENT_PARAMETER_VALUE" + inputName));
}
}
} else if ("content".equals(actionParameter.getType())) {
// $NON-NLS-1$
// $NON-NLS-1$
variableValue = "";
}
} else {
actionParameter.setValue(variableValue);
}
}
// while
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class RuntimeContext method executeLoop.
private void executeLoop(final IActionParameter loopParm, final List loopList, final IActionSequence sequence, final IActionCompleteListener doneListener, final IExecutionListener execListener, final boolean async) throws ActionSequenceException {
// execute the actions
int loopCount = -1;
for (Iterator it = loopList.iterator(); it.hasNext(); ) {
loopCount++;
if (RuntimeContext.debug) {
debug(Messages.getInstance().getString("RuntimeContext.DEBUG_EXECUTING_ACTION", // $NON-NLS-1$
Integer.toString(loopCount)));
}
if (execListener != null) {
execListener.loop(this, loopCount);
}
Object loopVar = it.next();
if (loopParm != null) {
IActionParameter ap;
if (loopVar instanceof Map) {
// $NON-NLS-1$
ap = new ActionParameter(loopParm.getName(), "property-map", loopVar, null, null);
} else {
// $NON-NLS-1$
ap = new ActionParameter(loopParm.getName(), "string", loopVar, null, null);
}
addInputParameter(loopParm.getName(), ap);
}
try {
performActions(sequence, doneListener, execListener, async);
} catch (ActionSequenceException e) {
e.setLoopIndex(loopCount);
throw e;
}
if (promptStatus == IRuntimeContext.PROMPT_NOW) {
return;
}
}
status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class ActionFilterDefinition method getResultSet.
/**
* If the <data-output> element is present in the xml file, its text specifies the name of the output parameter
* in the runtime context containing the result set.
*
* However, the <data-output> element is not required. If this element is not in the xml file, then the first
* parameter in the runtime context's output of type "resultset" contains the result set.
*/
@Override
protected IPentahoResultSet getResultSet(final Map parameterProviders) {
// create an instance of the solution engine to execute the specified
// action
// TODO we need to ensure that this data is cached (not live) so that we
// can validate selections
// $NON-NLS-1$
String solution = XmlDom4JHelper.getNodeText("data-solution", node);
// $NON-NLS-1$
String actionPath = XmlDom4JHelper.getNodeText("data-path", node);
// $NON-NLS-1$
String actionName = XmlDom4JHelper.getNodeText("data-action", node);
// $NON-NLS-1$
String listSource = XmlDom4JHelper.getNodeText("data-output", node);
ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
solutionEngine.setLoggingLevel(ILogger.DEBUG);
solutionEngine.init(session);
OutputStream outputStream = null;
SimpleOutputHandler outputHandler = null;
outputHandler = new SimpleOutputHandler(outputStream, false);
ArrayList messages = new ArrayList();
String processId = this.getClass().getName();
String instanceId = null;
IRuntimeContext context = null;
try {
String actionSeqPath = ActionInfo.buildSolutionPath(solution, actionPath, actionName);
context = solutionEngine.execute(actionSeqPath, processId, false, true, instanceId, false, parameterProviders, outputHandler, null, null, messages);
if (listSource != null) {
if (context.getOutputNames().contains(listSource)) {
IActionParameter output = context.getOutputParameter(listSource);
IPentahoResultSet results = output.getValueAsResultSet();
if (results != null) {
results = results.memoryCopy();
}
return results;
} else {
// this is an error
return null;
}
} else {
// return the first list that we find...
Iterator it = context.getOutputNames().iterator();
while (it.hasNext()) {
IActionParameter output = (IActionParameter) it.next();
if (output.getType().equalsIgnoreCase(IActionParameter.TYPE_RESULT_SET)) {
IPentahoResultSet results = output.getValueAsResultSet();
if (results != null) {
results = results.memoryCopy();
}
return results;
}
}
}
return null;
} finally {
if (context != null) {
context.dispose();
}
}
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class AbstractChartComponent method getActionData.
/**
* Gets a IPentahoResultSet from the action output
*
* @return IPentahoResultSet
*/
public IPentahoResultSet getActionData() {
// create an instance of the solution engine to execute the specified
// action
ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, getSession());
solutionEngine.setLoggingLevel(ILogger.DEBUG);
solutionEngine.init(getSession());
HashMap parameterProviders = getParameterProviders();
OutputStream outputStream = null;
SimpleOutputHandler outputHandler = null;
outputHandler = new SimpleOutputHandler(outputStream, false);
ArrayList messages = new ArrayList();
String processId = this.getClass().getName();
context = // $NON-NLS-1$ //$NON-NLS-2$
solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
actionPath, // $NON-NLS-1$ //$NON-NLS-2$
processId, // $NON-NLS-1$ //$NON-NLS-2$
false, // $NON-NLS-1$ //$NON-NLS-2$
true, // $NON-NLS-1$ //$NON-NLS-2$
instanceId, // $NON-NLS-1$ //$NON-NLS-2$
false, parameterProviders, outputHandler, null, urlFactory, messages);
if (context == null) {
// this went badly wrong
return null;
}
if (actionOutput != null) {
if (context.getOutputNames().contains(actionOutput)) {
IActionParameter output = context.getOutputParameter(actionOutput);
IPentahoResultSet results = output.getValueAsResultSet();
if (results != null) {
results = results.memoryCopy();
}
return results;
} else {
// this is an error
return null;
}
} else {
for (Object objAp : context.getOutputNames()) {
IActionParameter output = (IActionParameter) objAp;
if (output.getType().equalsIgnoreCase(IActionParameter.TYPE_RESULT_SET)) {
IPentahoResultSet results = output.getValueAsResultSet();
if (results != null) {
results = results.memoryCopy();
}
return results;
}
}
}
return null;
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class SequenceDefinition method getInputDefinitionsForParameterProvider.
public Map getInputDefinitionsForParameterProvider(final String parameterProviderName) {
Map rtnMap = new ListOrderedMap();
Map paramList = getInputDefinitions();
for (Iterator it = paramList.values().iterator(); it.hasNext(); ) {
IActionParameter actionParameter = (IActionParameter) it.next();
List vars = actionParameter.getVariables();
for (int i = 0; i < vars.size(); i++) {
ActionParameterSource source = (ActionParameterSource) (vars.get(i));
if (source.getSourceName().equals(parameterProviderName)) {
rtnMap.put(source.getValue(), actionParameter);
}
}
}
return (rtnMap);
}
Aggregations