use of org.pentaho.platform.api.engine.IRuntimeContext in project pentaho-platform by pentaho.
the class XactionUtil method executeHtml.
@SuppressWarnings({ "unchecked", "rawtypes" })
public static String executeHtml(RepositoryFile file, HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, IPentahoSession userSession, IMimeTypeListener mimeTypeListener) throws Exception {
IParameterProvider requestParams = new HttpRequestParameterProvider(httpServletRequest);
IRuntimeContext runtime = null;
try {
HttpSessionParameterProvider sessionParameters = new HttpSessionParameterProvider(userSession);
HttpRequestParameterProvider requestParameters = new HttpRequestParameterProvider(httpServletRequest);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
boolean doMessages = "true".equalsIgnoreCase(requestParams.getStringParameter("debug", "false"));
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
boolean doWrapper = "true".equalsIgnoreCase(requestParams.getStringParameter("wrapper", "true"));
IOutputHandler outputHandler = createOutputHandler(httpServletResponse, getOutputStream(httpServletResponse, doMessages));
// disposition is set on the response header
if (mimeTypeListener == null) {
mimeTypeListener = new HttpMimeTypeListener(httpServletRequest, httpServletResponse, null);
}
outputHandler.setMimeTypeListener(mimeTypeListener);
outputHandler.setSession(userSession);
Map parameterProviders = new HashMap();
// $NON-NLS-1$
parameterProviders.put("request", requestParameters);
// $NON-NLS-1$
parameterProviders.put("session", sessionParameters);
createOutputFileName(file, outputHandler);
int outputPreference = IOutputHandler.OUTPUT_TYPE_DEFAULT;
outputHandler.setOutputPreference(outputPreference);
// $NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$
boolean forcePrompt = "true".equalsIgnoreCase(requestParams.getStringParameter("prompt", "false"));
List messages = new ArrayList();
runtime = executeInternal(file, requestParams, httpServletRequest, outputHandler, parameterProviders, userSession, forcePrompt, messages);
String str = postExecute(runtime, doMessages, doWrapper, outputHandler, parameterProviders, httpServletRequest, httpServletResponse, messages, true);
return str;
} catch (Exception e) {
// $NON-NLS-1$
logger.error(Messages.getInstance().getString("XactionUtil.ERROR_EXECUTING_ACTION_SEQUENCE", file.getName()), e);
throw e;
} finally {
if (runtime != null) {
runtime.dispose();
}
}
}
use of org.pentaho.platform.api.engine.IRuntimeContext in project pentaho-platform by pentaho.
the class HttpWebService method doGetFixMe.
public void doGetFixMe(final HttpServletRequest request, final HttpServletResponse response) throws ServletException, IOException {
try {
// $NON-NLS-1$
String actionPath = request.getParameter("path");
String solutionName = actionPath.substring(0, actionPath.indexOf('/', 1));
String actionName = actionPath.substring(actionPath.lastIndexOf('/'));
String actionSeqPath = ActionInfo.buildSolutionPath(solutionName, actionPath, actionName);
// $NON-NLS-1$
String component = request.getParameter("component");
String content = getPayloadAsString(request);
IParameterProvider parameterProvider = null;
HashMap parameters = new HashMap();
if ((content != null) && (content.length() > 0)) {
Document doc = XmlDom4JHelper.getDocFromString(content, new PentahoEntityResolver());
// $NON-NLS-1$
List parameterNodes = doc.selectNodes("//SOAP-ENV:Body/*/*");
for (int i = 0; i < parameterNodes.size(); i++) {
Node parameterNode = (Node) parameterNodes.get(i);
String parameterName = parameterNode.getName();
String parameterValue = parameterNode.getText();
// if( "xml-data".equalsIgnoreCase( ) )
if ("action".equals(parameterName)) {
// $NON-NLS-1$
ActionInfo info = ActionInfo.parseActionString(parameterValue);
solutionName = info.getSolutionName();
actionPath = info.getPath();
actionName = info.getActionName();
} else if ("component".equals(parameterName)) {
// $NON-NLS-1$
component = parameterValue;
} else {
parameters.put(parameterName, parameterValue);
}
}
parameterProvider = new SimpleParameterProvider(parameters);
} else {
parameterProvider = new HttpRequestParameterProvider(request);
}
// $NON-NLS-1$
response.setContentType("text/xml");
response.setCharacterEncoding(LocaleHelper.getSystemEncoding());
// PentahoHttpSession userSession = new PentahoHttpSession(
// request.getRemoteUser(), request.getSession(),
// request.getLocale() );
IPentahoSession userSession = getPentahoSession(request);
// $NON-NLS-1$
String instanceId = request.getParameter("instance-id");
String processId = this.getClass().getName();
OutputStream contentStream = new ByteArrayOutputStream();
SimpleOutputHandler outputHandler = new SimpleOutputHandler(contentStream, false);
// send the header of the message to prevent time-outs while we are
// working
OutputStream outputStream = response.getOutputStream();
if ((component == null) || "action".equals(component)) {
// $NON-NLS-1$
// assume this is an action sequence execute
HttpWebServiceRequestHandler requestHandler = new HttpWebServiceRequestHandler(userSession, null, outputHandler, parameterProvider, null);
requestHandler.setParameterProvider(IParameterProvider.SCOPE_SESSION, new HttpSessionParameterProvider(userSession));
requestHandler.setInstanceId(instanceId);
requestHandler.setProcessId(processId);
requestHandler.setActionPath(actionSeqPath);
if (ServletBase.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("HttpWebService.DEBUG_WEB_SERVICE_START"));
}
IRuntimeContext runtime = null;
try {
runtime = requestHandler.handleActionRequest(0, 0);
Document responseDoc = SoapHelper.createSoapResponseDocument(runtime, outputHandler, contentStream, requestHandler.getMessages());
XmlDom4JHelper.saveDom(responseDoc, outputStream, PentahoSystem.getSystemSetting("web-service-encoding", "utf-8"), true);
} finally {
if (runtime != null) {
runtime.dispose();
}
}
} else if ("dial".equals(component)) {
// $NON-NLS-1$
doDial(solutionName, actionPath, actionName, parameterProvider, outputStream, userSession);
} else if ("chart".equals(component)) {
// $NON-NLS-1$
doChart(actionPath, parameterProvider, outputStream, userSession);
} else if ("xaction-parameter".equals(component)) {
// $NON-NLS-1$
doParameter(solutionName, actionPath, actionName, parameterProvider, outputStream, userSession, response);
}
} catch (Throwable t) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("HttpWebService.ERROR_0001_ERROR_DURING_WEB_SERVICE"), t);
}
if (ServletBase.debug) {
// $NON-NLS-1$
debug(Messages.getInstance().getString("HttpWebService.DEBUG_WEB_SERVICE_END"));
}
}
use of org.pentaho.platform.api.engine.IRuntimeContext in project pentaho-platform by pentaho.
the class PMDUIComponent method getLookup.
public Document getLookup() {
// Create a document that describes the result
Document doc = DocumentHelper.createDocument();
// $NON-NLS-1$
Element root = doc.addElement("metadata");
if (domainName == null) {
// we can't do this without a model
// $NON-NLS-1$ //$NON-NLS-2$
root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_NO_DOMAIN_SPECIFIED"));
return doc;
}
if (modelId == null) {
// we can't do this without a view
// $NON-NLS-1$ //$NON-NLS-2$
root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_NO_MODEL_SPECIFIED"));
return doc;
}
if (columnId == null) {
// we can't do this without a view
// $NON-NLS-1$ //$NON-NLS-2$
root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_NO_COLUMN_SPECIFIED"));
return doc;
}
Domain domain = getMetadataRepository().getDomain(domainName);
String locale = LocaleHelper.getClosestLocale(LocaleHelper.getLocale().toString(), domain.getLocaleCodes());
// This is the business view that was selected.
LogicalModel model = domain.findLogicalModel(modelId);
if (model == null) {
// $NON-NLS-1$ //$NON-NLS-2$
root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_MODEL_LOADING_ERROR", modelId));
return doc;
}
LogicalColumn column = model.findLogicalColumn(columnId);
if (column == null) {
// $NON-NLS-1$ //$NON-NLS-2$
root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_COLUMN_NOT_FOUND"));
return doc;
}
// Temporary hack to get the BusinessCategory. When fixed properly, you should be able to interrogate the
// business column thingie for it's containing BusinessCategory.
Category view = null;
for (Category category : model.getCategories()) {
for (LogicalColumn col : category.getLogicalColumns()) {
if (col.getId().equals(column.getId())) {
view = category;
break;
}
}
}
if (view == null) {
// $NON-NLS-1$ //$NON-NLS-2$
root.addElement("message").setText(Messages.getInstance().getString("PMDUIComponent.USER_VIEW_NOT_FOUND"));
return doc;
}
String mql = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"<mql><domain_type>relational</domain_type><domain_id>" + domainName + "</domain_id><model_id>" + modelId + "</model_id>";
if (column.getProperty("lookup") == null) {
// $NON-NLS-1$
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
mql += "<selection><view>" + view.getId() + "</view><column>" + column.getId() + "</column></selection>";
mql += // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"<orders><order><direction>asc</direction><view_id>" + view.getId() + "</view_id><column_id>" + column.getId() + "</column_id></order></orders>";
} else {
// $NON-NLS-1$
String lookup = (String) column.getProperty("lookup");
// assume model and view are the same...
// $NON-NLS-1$
StringTokenizer tokenizer1 = new StringTokenizer(lookup, ";");
while (tokenizer1.hasMoreTokens()) {
// $NON-NLS-1$
StringTokenizer tokenizer2 = new StringTokenizer(tokenizer1.nextToken(), ".");
if (tokenizer2.countTokens() == 2) {
String lookupViewId = tokenizer2.nextToken();
String lookupColumnId = tokenizer2.nextToken();
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
mql += "<selection><view>" + lookupViewId + "</view><column>" + lookupColumnId + "</column></selection>";
}
}
}
// $NON-NLS-1$
mql += "</mql>";
ArrayList messages = new ArrayList();
SimpleParameterProvider lookupParameters = new SimpleParameterProvider();
// $NON-NLS-1$
lookupParameters.setParameter("mql", mql);
IRuntimeContext runtime = SolutionHelper.doAction("/system/metadata/PickList.xaction", "lookup-list", lookupParameters, getSession(), messages, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
this);
IPentahoResultSet results = null;
if (runtime != null) {
if (runtime.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS) {
if (runtime.getOutputNames().contains("data")) {
// $NON-NLS-1$
// $NON-NLS-1$
results = runtime.getOutputParameter("data").getValueAsResultSet();
Object[][] columnHeaders = results.getMetaData().getColumnHeaders();
boolean hasColumnHeaders = columnHeaders != null;
Element rowElement;
// $NON-NLS-1$
Element dataElement = root.addElement("data");
if (hasColumnHeaders) {
for (int rowNo = 0; rowNo < columnHeaders.length; rowNo++) {
// $NON-NLS-1$
rowElement = dataElement.addElement("COLUMN-HDR-ROW");
for (int columnNo = 0; columnNo < columnHeaders[rowNo].length; columnNo++) {
// $NON-NLS-1$
Object nameAttr = results.getMetaData().getAttribute(rowNo, columnNo, "name");
if ((nameAttr != null) && (nameAttr instanceof LocalizedString)) {
LocalizedString str = (LocalizedString) nameAttr;
String name = str.getLocalizedString(locale);
if (name != null) {
// $NON-NLS-1$
rowElement.addElement("COLUMN-HDR-ITEM").setText(name);
} else {
// $NON-NLS-1$
rowElement.addElement("COLUMN-HDR-ITEM").setText(columnHeaders[rowNo][columnNo].toString());
}
} else {
// $NON-NLS-1$
rowElement.addElement("COLUMN-HDR-ITEM").setText(columnHeaders[rowNo][columnNo].toString());
}
}
}
}
Object[] row = results.next();
while (row != null) {
// $NON-NLS-1$
rowElement = dataElement.addElement("DATA-ROW");
for (Object element : row) {
if (element == null) {
// $NON-NLS-1$ //$NON-NLS-2$
rowElement.addElement("DATA-ITEM").setText("");
} else {
// $NON-NLS-1$
rowElement.addElement("DATA-ITEM").setText(element.toString());
}
}
row = results.next();
}
}
}
}
return doc;
}
use of org.pentaho.platform.api.engine.IRuntimeContext in project pentaho-platform by pentaho.
the class ContentOutputComponentIT method testSuccessPaths.
public void testSuccessPaths() {
startTest();
// $NON-NLS-1$
String testName = CO_TEST_NAME + "string_" + System.currentTimeMillis();
SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
IRuntimeContext context = // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
run("/test/platform/ContentOutputTest.xaction", parameterProvider, testName, CO_TEST_EXTN);
assertEquals(Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS, // $NON-NLS-1$
context.getStatus());
// $NON-NLS-1$
IActionParameter rtn = context.getOutputParameter("content");
assertNotNull(rtn);
InputStream is = this.getInputStreamFromOutput(testName, CO_TEST_EXTN);
// Did the test execute properly...
assertNotNull(is);
// $NON-NLS-1$
String lookingFor = "This is sample output from the content-output component.";
String wasRead = FileHelper.getStringFromInputStream(is);
assertTrue(wasRead.startsWith(lookingFor));
// Test different path - Byte Array Output Stream
// $NON-NLS-1$
lookingFor = "This is as sample bytearray output stream";
ByteArrayOutputStream baos = new ByteArrayOutputStream();
try {
baos.write(lookingFor.getBytes());
} catch (Exception ex) {
fail();
}
// $NON-NLS-1$
testName = CO_TEST_NAME + "ByteArrayOutputStream_" + System.currentTimeMillis();
// $NON-NLS-1$
parameterProvider.setParameter("CONTENTOUTPUT", baos);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
context = run("/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN);
assertEquals(IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus());
is = this.getInputStreamFromOutput(testName, CO_TEST_EXTN);
// Did the test execute properly...
assertNotNull(is);
wasRead = FileHelper.getStringFromInputStream(is);
FileHelper.getStringFromFile(new File(PentahoSystem.getApplicationContext().getSolutionPath(// $NON-NLS-1$
"test/datasource/books.xml")));
try {
FileHelper.getBytesFromFile(new File(PentahoSystem.getApplicationContext().getSolutionPath(// $NON-NLS-1$
"test/datasource/books.xml")));
} catch (IOException io) {
// do nothing
}
File f = null;
FileHelper.getStringFromFile(f);
assertTrue(wasRead.startsWith(lookingFor));
// Test different path - InputStream
// $NON-NLS-1$
testName = CO_TEST_NAME + "ByteArrayInputStream_" + System.currentTimeMillis();
// $NON-NLS-1$
lookingFor = "This is as a simple bytearray input stream";
ByteArrayInputStream bais = new ByteArrayInputStream(lookingFor.getBytes());
// $NON-NLS-1$
parameterProvider.setParameter("CONTENTOUTPUT", bais);
// $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
context = run("/test/platform/ContentOutputTest_Bytearray.xaction", parameterProvider, testName, CO_TEST_EXTN);
assertEquals(IRuntimeContext.RUNTIME_STATUS_SUCCESS, context.getStatus());
is = this.getInputStreamFromOutput(testName, CO_TEST_EXTN);
// Did the test execute properly...
assertNotNull(is);
String newText = FileHelper.getStringFromInputStream(is);
// $NON-NLS-1$
System.out.println("Read Text from the input stream" + newText);
String newTextFromIS = FileHelper.getStringFromInputStream(is);
// $NON-NLS-1$
System.out.println("Read Text from the input stream" + newTextFromIS);
assertTrue(newText.startsWith(lookingFor));
finishTest();
}
use of org.pentaho.platform.api.engine.IRuntimeContext in project pentaho-platform by pentaho.
the class CleanRepoPublisher method publish.
@Override
public String publish(final IPentahoSession localSession) {
try {
HashMap<String, String> parameters = new HashMap<String, String>();
ISolutionEngine engine = // $NON-NLS-1$//$NON-NLS-2$
SolutionHelper.execute(// $NON-NLS-1$//$NON-NLS-2$
"publisher", // $NON-NLS-1$//$NON-NLS-2$
localSession, // $NON-NLS-1$//$NON-NLS-2$
"admin/clean_repository.xaction", parameters, null);
IRuntimeContext context = engine.getExecutionContext();
int status = context.getStatus();
if (status != IRuntimeContext.RUNTIME_STATUS_SUCCESS) {
// $NON-NLS-1$
return Messages.getInstance().getString("CleanRepoPublisher.ERROR_0001_CLEAN_REPO_FAILED");
}
} catch (Throwable t) {
error(Messages.getInstance().getErrorString("CleanRepoPublisher.ERROR_0001_CLEAN_REPO_FAILED", t.getMessage()), // $NON-NLS-1$
t);
return Messages.getInstance().getString("CleanRepoPublisher.ERROR_0001_CLEAN_REPO_FAILED", // $NON-NLS-1$
t.getLocalizedMessage());
}
// $NON-NLS-1$
return Messages.getInstance().getString("CleanRepoPublisher.CLEAN_REPO_DONE");
}
Aggregations