use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class ResultSetExportComponentIT method testRSExportComponent.
public void testRSExportComponent() {
startTest();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IRuntimeContext context = run("/test/rules/ResultSetExportTest.xaction");
assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
context.getStatus());
// $NON-NLS-1$
IActionParameter rtn = context.getOutputParameter("EXPORTRESULT");
// $NON-NLS-1$
assertNotNull("Result is null", rtn);
// Check that the data, Eastern, is in the result set
String content = rtn.getStringValue();
// $NON-NLS-1$
assertNotNull("Exported content is null", content);
// $NON-NLS-1$
int containsEastern = content.indexOf("Eastern");
// $NON-NLS-1$
assertEquals("ResultSet export does not contain 'Eastern'", Math.max(containsEastern, -1), containsEastern);
finishTest();
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class ResultsetCompareIT method testRSCompareNotOK1.
public void testRSCompareNotOK1() {
startTest();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
IRuntimeContext context = run("/test/rules/ResultSetCompareTest_error1.xaction");
// $NON-NLS-1$
IActionParameter rtn = context.getOutputParameter("COMPARERESULT");
assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
context.getStatus());
assertNotNull(rtn);
String compareResult = rtn.getStringValue();
// $NON-NLS-1$
assertEquals(compareResult, "Eastern");
finishTest();
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class ParameterManager method setCurrentParameters.
public void setCurrentParameters(final ISolutionActionDefinition actionDefinition) {
currentInputs.clear();
currentOutputs.clear();
currentResources.clear();
if (actionDefinition == null) {
currentInputs = resetMap(sequenceInputNames, allParams);
currentResources = resetMap(sequenceResourceNames, allParams);
for (Iterator it = sequenceOutputDefs.entrySet().iterator(); it.hasNext(); ) {
Map.Entry entry = (Map.Entry) it.next();
String outputName = (String) entry.getKey();
IActionParameter param = (IActionParameter) allParams.get(outputName);
if (((IActionParameter) entry.getValue()).isOutputParameter()) {
if (param == null) {
currentOutputs.put(outputName, entry.getValue());
} else {
currentOutputs.put(outputName, param);
}
}
}
return;
}
String key;
Object value;
for (Iterator it = actionDefinition.getActionInputDefinitions().keySet().iterator(); it.hasNext(); ) {
key = (String) it.next();
value = allParams.get(actionDefinition.getMappedInputName(key));
if (value == null) {
value = actionDefinition.getActionInputDefinitions().get(key);
if (!((ActionParameter) value).hasDefaultValue()) {
// Only use if there is a default value;
value = null;
}
}
if (value != null) {
currentInputs.put(key, value);
}
}
// currentOutputs.putAll(actionDefinition.getActionOutputDefinitions());
// only put output parameters
Map outParams = actionDefinition.getActionOutputDefinitions();
for (Object outKey : outParams.keySet()) {
ActionParameter param = (ActionParameter) outParams.get(outKey);
if (param.isOutputParameter()) {
currentOutputs.put(outKey, param);
}
}
// This enables the old behavior - It should eventually be removed
if (!actionDefinition.hasActionResources()) {
currentResources.putAll(allResources);
} else {
for (Iterator it = actionDefinition.getActionResourceDefinitionNames().iterator(); it.hasNext(); ) {
key = (String) it.next();
String key2 = actionDefinition.getMappedResourceName(key);
value = allResources.get(key2);
currentResources.put(key, value);
}
}
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class RuntimeContext method getOutputContentItem.
public IContentItem getOutputContentItem(final String outputName, final String mimeType) {
IContentItem contentItem = null;
IActionParameter parameter = (IActionParameter) actionSequence.getOutputDefinitions().get(outputName);
if (parameter == null) {
warn(Messages.getInstance().getErrorString("RuntimeContext.ERROR_0021_INVALID_OUTPUT_REQUEST", outputName, // $NON-NLS-1$
actionSequence.getSequenceName()));
} else {
List destinationsList = parameter.getVariables();
Iterator destinationsIterator = destinationsList.iterator();
if (destinationsList.size() > 1) {
contentItem = new MultiContentItem();
}
while (destinationsIterator.hasNext()) {
ActionParameterSource destination = (ActionParameterSource) destinationsIterator.next();
String objectName = destination.getSourceName();
String contentName = destination.getValue();
contentName = TemplateUtil.applyTemplate(contentName, this);
outputHandler.setSession(session);
IContentItem tmpContentItem = outputHandler.getOutputContentItem(objectName, contentName, instanceId, mimeType);
addOutputContentItem(tmpContentItem);
if (contentItem instanceof MultiContentItem) {
((MultiContentItem) contentItem).addContentItem(tmpContentItem);
} else {
contentItem = tmpContentItem;
break;
}
}
}
return contentItem;
}
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 IPentahoResultSet loopSet, final IActionSequence sequence, final IActionCompleteListener doneListener, final IExecutionListener execListener, final boolean async, boolean peekOnly) throws ActionSequenceException {
// execute the actions
int loopCount = -1;
// to the first record. This is to resolve multiple levels of looping on resultset.
if (loopSet.isScrollable()) {
loopSet.beforeFirst();
}
if (peekOnly && !(loopSet instanceof IPeekable)) {
throw new ActionExecutionException(Messages.getInstance().getErrorString(// $NON-NLS-1$
"RuntimeContext.ERROR_0033_NOT_PEEKABLE"), session.getName(), instanceId, getActionSequence().getSequenceName(), null);
}
Object[] row = peekOnly ? ((IPeekable) loopSet).peek() : loopSet.next();
Object[][] headerSet = loopSet.getMetaData().getColumnHeaders();
// TODO handle OLAP result sets
Object[] headers = headerSet[0];
while (row != null) {
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);
}
if (loopParm != null) {
IActionParameter ap;
for (int columnNo = 0; columnNo < headers.length; columnNo++) {
String name = headers[columnNo].toString();
Object value = row[columnNo];
String type = null;
if (value instanceof String) {
type = IActionParameter.TYPE_STRING;
} else if (value instanceof Date) {
type = IActionParameter.TYPE_DATE;
} else if ((value instanceof Long) || (value instanceof Integer)) {
type = IActionParameter.TYPE_INTEGER;
} else if ((value instanceof BigDecimal) || (value instanceof Double) || (value instanceof Float)) {
type = IActionParameter.TYPE_DECIMAL;
} else if (value instanceof String[]) {
type = IActionParameter.TYPE_STRING;
} else if (value == null) {
// $NON-NLS-1$
warn(Messages.getInstance().getString("RuntimeContext.WARN_VARIABLE_IN_LOOP_IS_NULL", name));
} else {
type = IActionParameter.TYPE_OBJECT;
warn(Messages.getInstance().getString("RuntimeContext.WARN_VARIABLE_IN_LOOP_NOT_RECOGNIZED", name, // $NON-NLS-1$
value.getClass().toString()));
}
// TODO make sure any previous loop values are removed
ap = paramManager.getInput(name);
if (ap == null) {
ap = new ActionParameter(name, type, value, null, null);
addInputParameter(name, ap);
} else {
ap.dispose();
ap.setValue(value);
}
}
}
try {
performActions(sequence, doneListener, execListener, async);
} catch (ActionSequenceException e) {
e.setLoopIndex(loopCount);
throw e;
}
row = peekOnly ? ((IPeekable) loopSet).peek() : loopSet.next();
}
status = IRuntimeContext.RUNTIME_STATUS_SUCCESS;
}
Aggregations