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;
}
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();
}
}
}
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;
}
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);
}
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();
}
Aggregations