Search in sources :

Example 1 with PentahoSessionParameterProvider

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);
        }
    }
}
Also used : InteractiveAuthenticationSuccessEvent(org.springframework.security.authentication.event.InteractiveAuthenticationSuccessEvent) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) PentahoSessionParameterProvider(org.pentaho.platform.engine.core.solution.PentahoSessionParameterProvider) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 2 with PentahoSessionParameterProvider

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();
        }
    }
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) RepositoryFileOutputHandler(org.pentaho.platform.repository2.unified.fileio.RepositoryFileOutputHandler) HashMap(java.util.HashMap) PentahoSessionParameterProvider(org.pentaho.platform.engine.core.solution.PentahoSessionParameterProvider) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) RepositoryFileInputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileInputStream) RepositoryFileOutputStream(org.pentaho.platform.repository2.unified.fileio.RepositoryFileOutputStream) IOutputHandler(org.pentaho.platform.api.engine.IOutputHandler) IContentItem(org.pentaho.platform.api.repository.IContentItem) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 3 with PentahoSessionParameterProvider

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));
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) PentahoSessionParameterProvider(org.pentaho.platform.engine.core.solution.PentahoSessionParameterProvider)

Example 4 with PentahoSessionParameterProvider

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");
        }
    }
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) HashMap(java.util.HashMap) PentahoSessionParameterProvider(org.pentaho.platform.engine.core.solution.PentahoSessionParameterProvider) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) ISessionStartupAction(org.pentaho.platform.api.engine.ISessionStartupAction) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 5 with PentahoSessionParameterProvider

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);
        }
    }
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) PentahoSessionParameterProvider(org.pentaho.platform.engine.core.solution.PentahoSessionParameterProvider) HashMap(java.util.HashMap) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) ByteArrayOutputStream(java.io.ByteArrayOutputStream) UserSession(org.pentaho.platform.engine.core.system.UserSession) IActionParameter(org.pentaho.platform.api.engine.IActionParameter) SubActionAction(org.pentaho.actionsequence.dom.actions.SubActionAction)

Aggregations

PentahoSessionParameterProvider (org.pentaho.platform.engine.core.solution.PentahoSessionParameterProvider)5 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)3 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)2 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 Iterator (java.util.Iterator)1 ListIterator (java.util.ListIterator)1 SubActionAction (org.pentaho.actionsequence.dom.actions.SubActionAction)1 IOutputHandler (org.pentaho.platform.api.engine.IOutputHandler)1 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)1 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)1 ISessionStartupAction (org.pentaho.platform.api.engine.ISessionStartupAction)1 IContentItem (org.pentaho.platform.api.repository.IContentItem)1 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)1 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)1 UserSession (org.pentaho.platform.engine.core.system.UserSession)1