Search in sources :

Example 36 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.

the class AuditHelperTest method testAuditFailures.

public void testAuditFailures() {
    startTest();
    // $NON-NLS-1$ //$NON-NLS-2$
    OutputStream outputStream = getOutputStream("testAudit", ".html");
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true);
    outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_PARAMETERS);
    StandaloneSession session = // $NON-NLS-1$
    new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    AuditHelper.audit(null, session, "Type", "This is a message", "Values", 34, this);
    assertTrue(true);
    finishTest();
}
Also used : StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) OutputStream(java.io.OutputStream) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler)

Example 37 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.

the class PojoComponentTest method testStreamingPojo.

public void testStreamingPojo() {
    String instanceId = null;
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(out, false);
    outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
    startTest();
    IPentahoSession session = new StandaloneSession("system");
    ISolutionEngine solutionEngine = ServiceTestHelper.getSolutionEngine();
    if (outputHandler != null) {
        outputHandler.setSession(session);
    }
    try {
        String xactionStr = ServiceTestHelper.getXAction(SOLUTION_PATH, "test/pojo/pojo2.xaction");
        PojoComponentTest.setActionSequenceResourceCalled = false;
        IRuntimeContext runtimeContext = // $NON-NLS-1$ //$NON-NLS-2$
        solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
        xactionStr, // $NON-NLS-1$ //$NON-NLS-2$
        "test1.xaction", // $NON-NLS-1$ //$NON-NLS-2$
        "empty action sequence test", // $NON-NLS-1$ //$NON-NLS-2$
        false, // $NON-NLS-1$ //$NON-NLS-2$
        true, // $NON-NLS-1$ //$NON-NLS-2$
        null, // $NON-NLS-1$ //$NON-NLS-2$
        false, new HashMap(), outputHandler, null, new SimpleUrlFactory(""), new ArrayList());
        IActionParameter param = runtimeContext.getOutputParameter("outputstream");
        assertNotNull("RuntimeContext is null", runtimeContext);
        assertEquals("Action sequence execution failed", runtimeContext.getStatus(), IRuntimeContext.RUNTIME_STATUS_SUCCESS);
        assertTrue("setResource was not called", PojoComponentTest.setResourceInputStreamCalled);
        assertTrue("setResource was not called", PojoComponentTest.setActionSequenceResourceCalled);
    } catch (Exception e) {
        // we should not get here
        e.printStackTrace();
        assertTrue(e.getMessage(), false);
    }
    String output = new String(out.toByteArray());
    assertEquals("outputstream", "abcdeabcde", output);
    finishTest();
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HashMap(java.util.HashMap) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) ByteArrayOutputStream(java.io.ByteArrayOutputStream) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) IActionParameter(org.pentaho.platform.api.engine.IActionParameter)

Example 38 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler 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 39 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.

the class DefaultChartBeansGenerator method createAndRunActionSequence.

protected void createAndRunActionSequence(final IPentahoSession pentahoSession, final Map<String, Object> params, final Map<String, Object> defaultParameterMap, String contentLinkingTemplate, final OutputStream out) {
    SimpleParameterProvider parameterProvider = new SimpleParameterProvider(params);
    // add the default parameter values
    for (Map.Entry<String, Object> entry : defaultParameterMap.entrySet()) {
        parameterProvider.setParameter(entry.getKey(), entry.getValue());
    }
    Map<String, IParameterProvider> parameterProviders = new HashMap<String, IParameterProvider>();
    parameterProviders.put(IParameterProvider.SCOPE_REQUEST, parameterProvider);
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(out, true);
    outputHandler.setOutputPreference(IOutputHandler.OUTPUT_TYPE_DEFAULT);
    ActionSequenceDocument doc = createActionSequenceDocument(defaultParameterMap.keySet(), contentLinkingTemplate);
    runActionSequence(pentahoSession, parameterProviders, outputHandler, doc);
    try {
        out.flush();
        out.close();
    } catch (IOException e) {
        e.printStackTrace();
    }
}
Also used : IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) HashMap(java.util.HashMap) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) IOException(java.io.IOException) HashMap(java.util.HashMap) Map(java.util.Map) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider) IActionSequenceDocument(org.pentaho.actionsequence.dom.IActionSequenceDocument) ActionSequenceDocument(org.pentaho.actionsequence.dom.ActionSequenceDocument)

Example 40 with SimpleOutputHandler

use of org.pentaho.platform.engine.core.output.SimpleOutputHandler in project pentaho-platform by pentaho.

the class DashboardWidgetIT method testWidget1.

public void testWidget1() {
    startTest();
    // $NON-NLS-1$
    SimpleUrlFactory urlFactory = new SimpleUrlFactory("/testurl?");
    ArrayList messages = new ArrayList();
    DashboardWidgetComponent widget = new DashboardWidgetComponent(DashboardWidgetComponent.TYPE_DIAL, getSolutionPath() + "/samples/charts/dashboardwidget1.dial.xml", 300, 300, urlFactory, // $NON-NLS-1$
    messages);
    widget.setLoggingLevel(getLoggingLevel());
    widget.setValue(72.5);
    // $NON-NLS-1$
    widget.setTitle("test widget 1");
    // $NON-NLS-1$
    widget.setUnits("$");
    // $NON-NLS-1$//$NON-NLS-2$
    OutputStream outputStream = getOutputStream("DashboardWidgetTest.testWidget1", ".html");
    // $NON-NLS-1$
    String contentType = "text/html";
    SimpleParameterProvider requestParameters = new SimpleParameterProvider();
    SimpleParameterProvider sessionParameters = new SimpleParameterProvider();
    HashMap parameterProviders = new HashMap();
    parameterProviders.put(HttpRequestParameterProvider.SCOPE_REQUEST, requestParameters);
    parameterProviders.put(HttpSessionParameterProvider.SCOPE_SESSION, sessionParameters);
    // $NON-NLS-1$
    StandaloneSession session = new StandaloneSession("BaseTest.DEBUG_JUNIT_SESSION");
    SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, false);
    BaseRequestHandler requestHandler = new BaseRequestHandler(session, null, outputHandler, null, urlFactory);
    try {
        widget.validate(session, requestHandler);
        widget.handleRequest(outputStream, requestHandler, contentType, parameterProviders);
    } catch (IOException e) {
        e.printStackTrace();
    }
    finishTest();
}
Also used : HashMap(java.util.HashMap) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) SimpleOutputHandler(org.pentaho.platform.engine.core.output.SimpleOutputHandler) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) IOException(java.io.IOException) BaseRequestHandler(org.pentaho.platform.engine.services.BaseRequestHandler) DashboardWidgetComponent(org.pentaho.platform.uifoundation.chart.DashboardWidgetComponent) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Aggregations

SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)43 OutputStream (java.io.OutputStream)25 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)24 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)22 ArrayList (java.util.ArrayList)20 HashMap (java.util.HashMap)20 ByteArrayOutputStream (java.io.ByteArrayOutputStream)17 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)17 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)15 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)12 IOException (java.io.IOException)8 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)8 IActionParameter (org.pentaho.platform.api.engine.IActionParameter)6 IContentItem (org.pentaho.platform.api.repository.IContentItem)6 BaseRequestHandler (org.pentaho.platform.engine.services.BaseRequestHandler)6 IOutputHandler (org.pentaho.platform.api.engine.IOutputHandler)5 Iterator (java.util.Iterator)4 List (java.util.List)4 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)4 IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)4