use of org.pentaho.platform.engine.core.solution.PentahoSessionParameterProvider in project pentaho-platform by pentaho.
the class PentahoSessionStartupAuthenticationSuccessListener method onApplicationEvent.
// ~ Methods
// =========================================================================================================
public void onApplicationEvent(final ApplicationEvent event) {
if (event instanceof InteractiveAuthenticationSuccessEvent) {
// $NON-NLS-1$
logger.debug("received InteractiveAuthenticationSuccessEvent");
// $NON-NLS-1$
logger.debug("calling PentahoSystem.sessionStartup");
try {
IPentahoSession pentahoSession = PentahoSessionHolder.getSession();
Assert.notNull(pentahoSession, "PentahoSessionHolder doesn't have a session");
IParameterProvider sessionParameters = new PentahoSessionParameterProvider(pentahoSession);
PentahoSystem.sessionStartup(pentahoSession, sessionParameters);
} catch (Exception e) {
logger.error(e.getLocalizedMessage(), e);
}
}
}
use of org.pentaho.platform.engine.core.solution.PentahoSessionParameterProvider 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.engine.core.solution.PentahoSessionParameterProvider in project pentaho-platform by pentaho.
the class SessionParameterProviderTest method test1.
public void test1() {
StandaloneSession session = new StandaloneSession("test name");
PentahoSessionParameterProvider params = new PentahoSessionParameterProvider(session);
session.setAttribute("param1", "value1");
assertEquals("Wrong param value", "test name", params.getParameter("name"));
assertEquals("Wrong param value", "value1", params.getParameter("param1"));
assertEquals("Wrong param value", "value1", params.getStringParameter("param1", null));
assertEquals("Wrong param value", null, params.getStringParameter("bogus", null));
}
use of org.pentaho.platform.engine.core.solution.PentahoSessionParameterProvider in project pentaho-platform by pentaho.
the class PentahoSystem method sessionStartup.
public static void sessionStartup(final IPentahoSession session, IParameterProvider sessionParameters) {
List<ISessionStartupAction> sessionStartupActions = PentahoSystem.getSessionStartupActionsForType(session.getClass().getName());
if (sessionStartupActions == null) {
// nothing to do...
return;
}
if (!session.isAuthenticated()) {
return;
}
Boolean startupActionsFired = (Boolean) session.getAttribute("StartupActionsFired");
if ((startupActionsFired == null) || (!startupActionsFired)) {
try {
if (debug) {
// $NON-NLS-1$
Logger.debug(PentahoSystem.class, "Process session startup actions");
}
if (sessionStartupActions != null) {
for (ISessionStartupAction sessionStartupAction : sessionStartupActions) {
// parse the actionStr out to identify an action
// 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();
if (sessionParameters == null) {
sessionParameters = new PentahoSessionParameterProvider(session);
}
parameterProviderMap.put(SCOPE_SESSION, sessionParameters);
IPentahoUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
ArrayList messages = new ArrayList();
IRuntimeContext context = null;
try {
context = solutionEngine.execute(sessionStartupAction.getActionPath(), "Session 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) {
session.removeAttribute(attributeName);
session.setAttribute(attributeName, data);
}
}
}
} catch (Throwable th) {
Logger.warn(PentahoSystem.class.getName(), Messages.getInstance().getString("PentahoSystem.WARN_UNABLE_TO_EXECUTE_SESSION_ACTION", th.getLocalizedMessage()), // $NON-NLS-1$
th);
} finally {
if (context != null) {
context.dispose();
}
}
}
}
} finally {
session.setAttribute("StartupActionsFired", true);
}
} else {
if (debug) {
Logger.debug(PentahoSystem.class, "Session startup actions already fired");
}
}
}
use of org.pentaho.platform.engine.core.solution.PentahoSessionParameterProvider 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);
}
}
}
Aggregations