Search in sources :

Example 66 with IActionParameter

use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.

the class SubActionComponent method executeAction.

@SuppressWarnings("deprecation")
@Override
protected boolean executeAction() throws Throwable {
    SubActionAction subAction = (SubActionAction) getActionDefinition();
    List<Object> ignoreParameters = new ArrayList<Object>();
    String actionPath = buildActionPath(subAction.getSolution().getStringValue(), subAction.getPath().getStringValue(), subAction.getAction().getStringValue());
    // see if we are supposed to proxy the session
    IPentahoSession session = getSession();
    if (subAction.getSessionProxy() != ActionInputConstant.NULL_INPUT) {
        String sessionName = subAction.getSessionProxy().getStringValue();
        // TODO support user-by-user locales
        PentahoSessionParameterProvider params = new PentahoSessionParameterProvider(session);
        session = new UserSession(sessionName, LocaleHelper.getLocale(), params);
    }
    // create a parameter provider
    HashMap<String, Object> parameters = new HashMap<String, Object>();
    Iterator<?> iterator = getInputNames().iterator();
    while (iterator.hasNext()) {
        String inputName = (String) iterator.next();
        if (!StandardSettings.SOLUTION.equals(inputName) && !StandardSettings.PATH.equals(inputName) && !StandardSettings.ACTION.equals(inputName)) {
            Object value = getInputValue(inputName);
            ignoreParameters.add(value);
            parameters.put(inputName, value);
        }
    }
    parameters.put(StandardSettings.ACTION_URL_COMPONENT, getInputStringValue(StandardSettings.ACTION_URL_COMPONENT));
    // get the ouptut stream
    // TODO verify this with MB and JD
    // getDefaultOutputStream();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    ISolutionEngine solutionEngine = null;
    try {
        solutionEngine = SolutionHelper.execute(getProcessId(), session, actionPath, parameters, outputStream, null, true, false);
        if (outputStream.size() > 0) {
            getDefaultOutputStream(null).write(outputStream.toByteArray());
        }
        int status = solutionEngine.getStatus();
        if (status == IRuntimeContext.RUNTIME_STATUS_SUCCESS) {
            // now pass any outputs back
            Iterator<?> it = this.getOutputNames().iterator();
            while (it.hasNext()) {
                String outputName = (String) it.next();
                IActionParameter param = solutionEngine.getExecutionContext().getOutputParameter(outputName);
                if (param != null) {
                    setOutputValue(outputName, param.getValue());
                    ignoreParameters.add(param.getValue());
                }
            }
            return true;
        } else {
            return false;
        }
    } finally {
        if (solutionEngine != null) {
            solutionEngine.getExecutionContext().dispose(ignoreParameters);
        }
    }
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) PentahoSessionParameterProvider(org.pentaho.platform.engine.core.solution.PentahoSessionParameterProvider) HashMap(java.util.HashMap) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UserSession(org.pentaho.platform.engine.core.system.UserSession) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) SubActionAction(org.pentaho.actionsequence.dom.actions.SubActionAction)

Example 67 with IActionParameter

use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.

the class JavaScriptResultSetIT method testRSCompareOK.

public void testRSCompareOK() {
    startTest();
    IRuntimeContext context = run("/samples/rules/ResultSetTest.xaction");
    assertEquals(IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus());
    IActionParameter rtn = context.getOutputParameter("COMPARERESULT");
    assertNotNull(rtn);
    String compareResult = rtn.getStringValue();
    assertEquals(compareResult, "No Mismatches");
    finishTest();
}
Also used : IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 68 with IActionParameter

use of org.pentaho.platform.api.engine.IActionParameter in project pentaho-platform by pentaho.

the class SubActionComponentIT method testSuccessPaths.

public void testSuccessPaths() {
    startTest();
    // $NON-NLS-1$
    String testName = CO_TEST_NAME + "string_" + System.currentTimeMillis();
    SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
    parameterProvider.setParameter(SOLUTION_NAME_PARAM, SOLUTION_NAME);
    parameterProvider.setParameter(SOLUTION_PATH_PARAM, "platform");
    parameterProvider.setParameter(SUBACTION_PARAM, SUBACTION);
    parameterProvider.setParameter(TEST_INPUT_PARAM, TEST_STRING);
    IRuntimeContext context = run("/" + SOLUTION_NAME + "/platform/" + TEST_XACTION, parameterProvider, testName, CO_TEST_EXTN);
    assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
    context.getStatus());
    IActionParameter rtn = context.getOutputParameter(TEST_OUTPUT_PARAM);
    Object value = rtn.getValue();
    assertEquals(TEST_STRING, value);
    finishTest();
}
Also used : IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

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