Search in sources :

Example 51 with IRuntimeContext

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

the class ActionComponent method getContentAsStream.

protected ByteArrayOutputStream getContentAsStream(final String mimeType) {
    IPentahoSession userSession = getSession();
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true);
    outputHandler.setOutputPreference(outputPreference);
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, getSession());
    solutionEngine.setLoggingLevel(getLoggingLevel());
    solutionEngine.init(userSession);
    IRuntimeContext context = null;
    try {
        String actionSeqPath = ActionInfo.buildSolutionPath(solutionName, actionPath, actionName);
        context = solutionEngine.execute(actionSeqPath, Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_TEST"), false, true, instanceId, false, getParameterProviders(), outputHandler, null, urlFactory, // $NON-NLS-1$
        getMessages());
    } finally {
        if (context != null) {
            context.dispose();
        }
    }
    return outputStream;
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext)

Example 52 with IRuntimeContext

use of org.pentaho.platform.api.engine.IRuntimeContext 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();
        }
    }
}
Also used : IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 53 with IRuntimeContext

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

the class SolutionHelper method doAction.

/**
 * doAction executes an action within the bi platform and returns true if successful.
 *
 * Snagged from ChartHelper
 *
 * @param solutionName
 *          the solution name
 * @param actionPath
 *          the action path
 * @param actionName
 *          the action name
 * @param processId
 *          the process id
 * @param parameterProvider
 *          the collection of parameters to customize the chart
 * @param outputStream
 *          the output object
 * @param userSession
 *          the user session object
 * @param messages
 *          a collection to store error and logging messages
 * @param logger
 *          logging object
 *
 * @return the runtime context
 */
public static boolean doAction(String actionPath, final String processId, final IParameterProvider parameterProvider, final OutputStream outputStream, final IPentahoSession userSession, final ArrayList messages, final ILogger logger) {
    int status = IRuntimeContext.RUNTIME_STATUS_FAILURE;
    IRuntimeContext runtime = null;
    try {
        runtime = SolutionHelper.doActionInternal(actionPath, processId, parameterProvider, outputStream, userSession, messages, logger);
        if (runtime != null) {
            status = runtime.getStatus();
        }
    } finally {
        if (runtime != null) {
            runtime.dispose();
        }
    }
    return status == IRuntimeContext.RUNTIME_STATUS_SUCCESS;
}
Also used : IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext)

Example 54 with IRuntimeContext

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

the class ActionSequenceActionTest method setUp.

@Before
public void setUp() throws ObjectFactoryException {
    IRuntimeContext context = mock(IRuntimeContext.class);
    when(context.getOutputContentItems()).thenReturn(expectedContentItem);
    when(context.getStatus()).thenReturn(IRuntimeContext.RUNTIME_STATUS_SUCCESS);
    final ISolutionEngine engine = mock(ISolutionEngine.class);
    when(engine.execute(anyString(), anyString(), anyBoolean(), anyBoolean(), anyString(), anyBoolean(), anyMap(), any(IOutputHandler.class), any(IActionCompleteListener.class), any(IPentahoUrlFactory.class), anyList())).thenReturn(context);
    pentahoObjectFactory = mock(IPentahoObjectFactory.class);
    when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true);
    when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))).thenAnswer(new Answer<Object>() {

        @Override
        public ISolutionEngine answer(InvocationOnMock invocation) throws Throwable {
            return engine;
        }
    });
    PentahoSystem.registerObjectFactory(pentahoObjectFactory);
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) InvocationOnMock(org.mockito.invocation.InvocationOnMock) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionCompleteListener(org.pentaho.platform.api.engine.IActionCompleteListener) Before(org.junit.Before)

Example 55 with IRuntimeContext

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

the class MultipleComponentIT method testHelloWorldComponent.

public void testHelloWorldComponent() {
    startTest();
    String testName = HW_TEST_NAME + System.currentTimeMillis();
    SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    IRuntimeContext context = run("/test/platform/HelloWorld.xaction", parameterProvider, testName, HW_TEST_EXTN);
    assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
    context.getStatus());
    InputStream is = this.getInputStreamFromOutput(testName, HW_TEST_EXTN);
    // Did the test execute properly...
    assertNotNull(is);
    // $NON-NLS-1$ //$NON-NLS-2$
    String lookingFor = "\nHello World. (2B || !2B) That is the question\n";
    String wasRead = FileHelper.getStringFromInputStream(is);
    assertEquals(wasRead, lookingFor);
    finishTest();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Aggregations

IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)100 ArrayList (java.util.ArrayList)28 HashMap (java.util.HashMap)28 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)28 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)24 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)21 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)20 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)17 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)14 OutputStream (java.io.OutputStream)12 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)12 List (java.util.List)10 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)9 IOException (java.io.IOException)8 Map (java.util.Map)8 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 IOutputHandler (org.pentaho.platform.api.engine.IOutputHandler)7 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)6 Document (org.dom4j.Document)5