use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class HttpWebService method doParameter.
private void doParameter(final String solutionName, final String actionPath, final String actionName, final IParameterProvider parameterProvider, final OutputStream outputStream, final IPentahoSession userSession, final HttpServletResponse response) throws IOException {
final IActionSequence actionSequence = new ActionSequenceJCRHelper().getActionSequence(ActionInfo.buildSolutionPath(solutionName, actionPath, actionName), PentahoSystem.loggingLevel, RepositoryFilePermission.READ);
if (actionSequence == null) {
logger.debug(Messages.getInstance().getString("HttpWebService.ERROR_0002_NOTFOUND", solutionName, actionPath, actionName));
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
final Document document = DocumentHelper.createDocument();
try {
final Element parametersElement = document.addElement("parameters");
// noinspection unchecked
final Map<String, IActionParameter> params = actionSequence.getInputDefinitionsForParameterProvider(IParameterProvider.SCOPE_REQUEST);
for (final Map.Entry<String, IActionParameter> entry : params.entrySet()) {
final String paramName = entry.getKey();
final IActionParameter paramDef = entry.getValue();
final String value = paramDef.getStringValue();
final Class type;
// defined as constant (string)
if (IActionParameter.TYPE_LIST.equalsIgnoreCase(paramDef.getType())) {
type = String[].class;
} else {
type = String.class;
}
final String label = paramDef.getSelectionDisplayName();
final String[] values;
if (StringUtils.isEmpty(value)) {
values = new String[0];
} else {
values = new String[] { value };
}
createParameterElement(parametersElement, paramName, type, label, "user", "parameters", values);
}
// built in parameters: solution, path, action, prompt, instance-id
createParameterElement(parametersElement, "solution", String.class, null, "system", "system", new String[] { solutionName });
createParameterElement(parametersElement, "path", String.class, null, "system", "system", new String[] { actionPath });
createParameterElement(parametersElement, "action", String.class, null, "system", "system", new String[] { actionName });
createParameterElement(parametersElement, "prompt", String.class, null, "system", "system", new String[] { "yes", "no" });
createParameterElement(parametersElement, "instance-id", String.class, null, "system", "system", new String[] { parameterProvider.getStringParameter("instance-id", null) });
} catch (Exception e) {
logger.warn(Messages.getInstance().getString("HttpWebService.ERROR_0003_UNEXPECTED"), e);
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
return;
}
// no close, as far as I know tomcat does not like it that much ..
final XMLWriter writer = new XMLWriter(outputStream, OutputFormat.createPrettyPrint());
writer.write(document);
writer.flush();
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class ConditionalExecutionTest method testShouldExecute_returns_true_for_result_with_rows.
@Test
public void testShouldExecute_returns_true_for_result_with_rows() throws Exception {
ConditionalExecution conditionalExecution = new ConditionalExecution();
conditionalExecution.setScript("resultElement;");
IActionParameter parameter = createParameterWithResult(1);
boolean actualResult = conditionalExecution.shouldExecute(Collections.singletonMap("resultElement", parameter), logger);
assertTrue(actualResult);
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class ConditionalExecutionTest method testShouldExecute_returns_false_for_result_without_rows.
@Test
public void testShouldExecute_returns_false_for_result_without_rows() throws Exception {
ConditionalExecution conditionalExecution = new ConditionalExecution();
conditionalExecution.setScript("resultElement;");
IActionParameter parameter = createParameterWithResult(0);
boolean actualResult = conditionalExecution.shouldExecute(Collections.singletonMap("resultElement", parameter), logger);
assertFalse(actualResult);
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class ScriptableConditionTest method createParameterWithResult.
private static IActionParameter createParameterWithResult(int rowsCount) {
IActionParameter parameter = mock(IActionParameter.class);
IPentahoResultSet resultSet = mock(IPentahoResultSet.class);
when(resultSet.getRowCount()).thenReturn(rowsCount);
when(parameter.getValue()).thenReturn(resultSet);
return parameter;
}
use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.
the class ScriptableConditionTest method shouldExecute_returns_false_for_result_without_rows.
@Test
public void shouldExecute_returns_false_for_result_without_rows() throws Exception {
ScriptableCondition conditionalExecution = new ScriptableCondition();
conditionalExecution.setScript(RESULT_ELEMENT_SCRIPT);
IActionParameter parameter = createParameterWithResult(0);
boolean actualResult = conditionalExecution.shouldExecute(Collections.singletonMap(RESULT_ELEMENT, parameter), logger);
assertFalse(actualResult);
}
Aggregations