Search in sources :

Example 46 with IActionParameter

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();
}
Also used : IActionSequence(org.pentaho.platform.api.engine.IActionSequence) DefaultElement(org.dom4j.tree.DefaultElement) Element(org.dom4j.Element) Document(org.dom4j.Document) XMLWriter(org.dom4j.io.XMLWriter) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) XmlParseException(org.pentaho.platform.api.util.XmlParseException) ActionSequenceJCRHelper(org.pentaho.platform.engine.services.ActionSequenceJCRHelper) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) HashMap(java.util.HashMap) Map(java.util.Map)

Example 47 with IActionParameter

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);
}
Also used : IActionParameter(org.pentaho.platform.api.engine.IActionParameter) Test(org.junit.Test)

Example 48 with IActionParameter

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);
}
Also used : IActionParameter(org.pentaho.platform.api.engine.IActionParameter) Test(org.junit.Test)

Example 49 with IActionParameter

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;
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 50 with IActionParameter

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);
}
Also used : IActionParameter(org.pentaho.platform.api.engine.IActionParameter) Test(org.junit.Test)

Aggregations

IActionParameter (org.pentaho.platform.api.engine.IActionParameter)68 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)24 ArrayList (java.util.ArrayList)22 HashMap (java.util.HashMap)22 Iterator (java.util.Iterator)19 Map (java.util.Map)14 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)14 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)13 List (java.util.List)9 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)9 Set (java.util.Set)8 IContentItem (org.pentaho.platform.api.repository.IContentItem)8 IOException (java.io.IOException)7 OutputStream (java.io.OutputStream)6 Test (org.junit.Test)6 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)6 ActionParameter (org.pentaho.platform.engine.services.actionsequence.ActionParameter)6 Document (org.dom4j.Document)5 IPreparedComponent (org.pentaho.platform.api.data.IPreparedComponent)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4