use of org.pentaho.platform.api.engine.ISolutionEngine in project pentaho-platform by pentaho.
the class ActionSequenceAction method execute.
public void execute() throws Exception {
IOutputHandler outputHandler = null;
if (xactionResultsOutputStream instanceof RepositoryFileOutputStream) {
outputHandler = new RepositoryFileOutputHandler(((RepositoryFileOutputStream) xactionResultsOutputStream));
} else {
outputHandler = new SimpleOutputHandler(xactionResultsOutputStream, false);
}
IRuntimeContext rt = null;
try {
ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, null);
solutionEngine.setCreateFeedbackParameterCallback(null);
solutionEngine.setLoggingLevel(ILogger.DEBUG);
solutionEngine.setForcePrompt(false);
ArrayList messages = new ArrayList();
HashMap<String, Object> parameterProviders = new HashMap<String, Object>();
parameterProviders.put(IParameterProvider.SCOPE_REQUEST, new SimpleParameterProvider(xActionInputParams));
parameterProviders.put(IParameterProvider.SCOPE_SESSION, new PentahoSessionParameterProvider(PentahoSessionHolder.getSession()));
String xactionPath = null;
if (xactionDefInputStream instanceof RepositoryFileInputStream) {
xactionPath = ((RepositoryFileInputStream) xactionDefInputStream).getFile().getPath();
}
rt = solutionEngine.execute(xactionPath, this.getClass().getName(), false, true, null, true, parameterProviders, outputHandler, null, null, messages);
if (!outputHandler.contentDone()) {
if ((rt != null) && (rt.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS)) {
// set content which generated by sequence for pass it to caller
List<IContentItem> components = new ArrayList<IContentItem>(rt.getOutputContentItems());
setActionOutputContents(components);
boolean isFlushed = false;
boolean isEmpty;
if (xactionResultsOutputStream instanceof RepositoryFileOutputStream) {
RepositoryFileOutputStream repositoryFileOutputStream = (RepositoryFileOutputStream) xactionResultsOutputStream;
isFlushed = repositoryFileOutputStream.isFlushed();
isEmpty = repositoryFileOutputStream.size() > 0 ? false : true;
String extension = RepositoryFilenameUtils.getExtension(repositoryFileOutputStream.getFilePath());
String mimeTypeFromExtension = MimeHelper.getMimeTypeFromExtension("." + extension);
if (mimeTypeFromExtension == null) {
// unknown type, treat it not as an extension but part of the name
extension = "";
}
if (extension.isEmpty() && xactionResultsOutputStream.toString().isEmpty()) {
repositoryFileOutputStream.setFilePath(repositoryFileOutputStream.getFilePath() + ".html");
}
} else {
isEmpty = xactionResultsOutputStream.toString().isEmpty();
}
if (!isFlushed) {
if (isEmpty) {
StringBuffer buffer = new StringBuffer();
// $NON-NLS-1$
MessageFormatUtils.formatSuccessMessage("text/html", rt, buffer, false);
xactionResultsOutputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
}
xactionResultsOutputStream.close();
}
} else {
// we need an error message...
StringBuffer buffer = new StringBuffer();
// $NON-NLS-1$
MessageFormatUtils.formatFailureMessage("text/html", rt, buffer, messages);
xactionResultsOutputStream.write(buffer.toString().getBytes(LocaleHelper.getSystemEncoding()));
xactionResultsOutputStream.close();
}
}
} finally {
if (rt != null) {
rt.dispose();
}
}
}
use of org.pentaho.platform.api.engine.ISolutionEngine in project pentaho-platform by pentaho.
the class WidgetGridComponent method getActionData.
protected IPentahoResultSet getActionData() {
// create an instance of the solution engine to execute the specified
// action
ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, getSession());
solutionEngine.setLoggingLevel(ILogger.DEBUG);
solutionEngine.init(getSession());
HashMap parameterProviders = getParameterProviders();
OutputStream outputStream = null;
SimpleOutputHandler outputHandler = null;
outputHandler = new SimpleOutputHandler(outputStream, false);
ArrayList messages = new ArrayList();
String processId = this.getClass().getName();
String actionSeqPath = ActionInfo.buildSolutionPath(solution, actionPath, actionName);
context = solutionEngine.execute(actionSeqPath, processId, false, true, instanceId, false, parameterProviders, outputHandler, null, urlFactory, messages);
if (actionOutput != null) {
if (context.getOutputNames().contains(actionOutput)) {
IActionParameter output = context.getOutputParameter(actionOutput);
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;
}
use of org.pentaho.platform.api.engine.ISolutionEngine in project pentaho-platform by pentaho.
the class PentahoSystem method globalStartup.
public static void globalStartup(final IPentahoSession session) {
// getGlobalStartupActions doesn't pay any attention to session class
List<ISessionStartupAction> globalStartupActions = PentahoSystem.getGlobalStartupActions();
if (globalStartupActions == null) {
// nothing to do...
return;
}
boolean doGlobals = PentahoSystem.globalAttributes.size() == 0;
// see if this has been done already
if (!doGlobals) {
return;
}
if (globalStartupActions != null) {
for (ISessionStartupAction globalStartupAction : globalStartupActions) {
// now execute the action...
SimpleOutputHandler outputHandler = null;
String instanceId = null;
ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
solutionEngine.setLoggingLevel(PentahoSystem.loggingLevel);
solutionEngine.init(session);
// $NON-NLS-1$
String baseUrl = "";
HashMap parameterProviderMap = new HashMap();
IPentahoUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
ArrayList messages = new ArrayList();
IRuntimeContext context = null;
try {
context = solutionEngine.execute(globalStartupAction.getActionPath(), "Global startup actions", false, true, instanceId, false, parameterProviderMap, outputHandler, null, urlFactory, // $NON-NLS-1$
messages);
// if context is null, then we cannot check the status
if (null == context) {
return;
}
if (context.getStatus() == IRuntimeContext.RUNTIME_STATUS_SUCCESS) {
// now grab any outputs
Iterator outputNameIterator = context.getOutputNames().iterator();
while (outputNameIterator.hasNext()) {
String attributeName = (String) outputNameIterator.next();
IActionParameter output = context.getOutputParameter(attributeName);
Object data = output.getValue();
if (data != null) {
PentahoSystem.globalAttributes.remove(attributeName);
PentahoSystem.globalAttributes.put(attributeName, data);
}
}
}
} catch (Throwable th) {
Logger.warn(PentahoSystem.class.getName(), Messages.getInstance().getString("PentahoSystem.WARN_UNABLE_TO_EXECUTE_GLOBAL_ACTION", th.getLocalizedMessage()), // $NON-NLS-1$
th);
} finally {
if (context != null) {
context.dispose();
}
}
}
}
}
use of org.pentaho.platform.api.engine.ISolutionEngine 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");
}
use of org.pentaho.platform.api.engine.ISolutionEngine in project pentaho-platform by pentaho.
the class BaseRequestHandler method handleActionRequest.
public IRuntimeContext handleActionRequest(final int timeout, final int timeoutType) {
// Get the solution engine
ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
if (solutionEngine == null) {
// $NON-NLS-1$
Logger.error(this, Messages.getInstance().getErrorString("BaseRequestHandler.ERROR_0001_NO_SOLUTION_ENGINE"));
return null;
}
solutionEngine.setCreateFeedbackParameterCallback(createFeedbackParameterCallback);
solutionEngine.setLoggingLevel(ILogger.DEBUG);
solutionEngine.init(session);
solutionEngine.setForcePrompt(forcePrompt);
if (parameterXsl != null) {
solutionEngine.setParameterXsl(parameterXsl);
}
dispose();
runtime = solutionEngine.execute(actionPath, processId, false, instanceEnds, instanceId, true, parameterProviders, outputHandler, this, urlFactory, messages);
return runtime;
}
Aggregations