Search in sources :

Example 11 with IPentahoUrlFactory

use of org.pentaho.platform.api.engine.IPentahoUrlFactory in project pentaho-platform by pentaho.

the class MetadataIT method __testLoadView.

public void __testLoadView() {
    startTest();
    // $NON-NLS-1$
    IPentahoUrlFactory urlFactory = new SimpleUrlFactory("");
    PMDUIComponent component = new PMDUIComponent(urlFactory, new ArrayList());
    StandaloneSession session = // $NON-NLS-1$
    new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
    component.validate(session, null);
    component.setAction(PMDUIComponent.ACTION_LOAD_MODEL);
    // $NON-NLS-1$
    component.setDomainName("test");
    // $NON-NLS-1$
    component.setModelId("Orders");
    Document doc = component.getXmlContent();
    System.out.println(doc.asXML());
    try {
        // $NON-NLS-1$//$NON-NLS-2$
        OutputStream outputStream = getOutputStream("MetadataTest.testLoadView", ".xml");
        outputStream.write(doc.asXML().getBytes());
    } catch (IOException e) {
    // ignore
    }
    finishTest();
}
Also used : IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) PMDUIComponent(org.pentaho.platform.uifoundation.component.xml.PMDUIComponent) IOException(java.io.IOException) Document(org.dom4j.Document)

Example 12 with IPentahoUrlFactory

use of org.pentaho.platform.api.engine.IPentahoUrlFactory in project pentaho-platform by pentaho.

the class BaseTestCase method run.

public IRuntimeContext run(String actionSequencePath, String actionSequence, IParameterProvider parameterProvider, IOutputHandler outputHandler) {
    List messages = new ArrayList();
    String instanceId = null;
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
    solutionEngine.setLoggingLevel(ILogger.ERROR);
    solutionEngine.init(session);
    HashMap parameterProviderMap = new HashMap();
    IPentahoUrlFactory urlFactory = new SimpleUrlFactory("");
    IRuntimeContext runtimeContext = null;
    Reader reader = null;
    try {
        File file = new File(actionSequencePath + actionSequence);
        StringBuilder str = new StringBuilder();
        reader = new FileReader(file);
        char[] buffer = new char[4096];
        int n = reader.read(buffer);
        while (n != -1) {
            str.append(buffer, 0, n);
            n = reader.read(buffer);
        }
        String xactionStr = str.toString();
        solutionEngine.setSession(session);
        runtimeContext = // $NON-NLS-1$
        solutionEngine.execute(// $NON-NLS-1$
        xactionStr, // $NON-NLS-1$
        actionSequence, // $NON-NLS-1$
        "action sequence test", // $NON-NLS-1$
        false, // $NON-NLS-1$
        true, // $NON-NLS-1$
        instanceId, // $NON-NLS-1$
        false, parameterProviderMap, null, null, urlFactory, messages);
    } catch (Exception e) {
        // we should not get here
        e.printStackTrace();
        assertTrue(e.getMessage(), false);
    } finally {
        if (reader != null) {
            try {
                reader.close();
            } catch (Exception ex) {
                ex.printStackTrace();
                assertTrue(ex.getMessage(), false);
            }
        }
    }
    return runtimeContext;
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Reader(java.io.Reader) FileReader(java.io.FileReader) FileNotFoundException(java.io.FileNotFoundException) ArrayList(java.util.ArrayList) List(java.util.List) FileReader(java.io.FileReader) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) File(java.io.File)

Example 13 with IPentahoUrlFactory

use of org.pentaho.platform.api.engine.IPentahoUrlFactory 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 14 with IPentahoUrlFactory

use of org.pentaho.platform.api.engine.IPentahoUrlFactory in project pentaho-platform by pentaho.

the class DefaultChartBeansGenerator method runActionSequence.

/**
 * Executes an action sequence from an <code>ActionSequenceDocument</code>.
 *
 * @param pentahoSession
 *          current <code>IPentahoSession</code>
 * @param parameterProviders
 *          map of parameter providers; there should a single entry with "request" as the key
 * @param outputHandler
 *          output handler
 * @param doc
 *          action sequence document
 * @throws RuntimeException
 *           if anything goes wrong
 */
protected void runActionSequence(final IPentahoSession pentahoSession, final Map<String, IParameterProvider> parameterProviders, final IOutputHandler outputHandler, final ActionSequenceDocument doc) throws RuntimeException {
    // Get the solution engine
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, pentahoSession);
    if (solutionEngine == null) {
        // $NON-NLS-1$
        throw new RuntimeException("solutionEngine is null");
    }
    solutionEngine.setLoggingLevel(ILogger.DEBUG);
    solutionEngine.init(pentahoSession);
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    String contextPath = requestContext.getContextPath();
    // $NON-NLS-1$
    IPentahoUrlFactory urlFactory = new SimpleUrlFactory(contextPath);
    IRuntimeContext runtime;
    IParameterProvider requestParmProvider = parameterProviders.get("request");
    if (requestParmProvider.hasParameter("obj_id")) {
        final String obj_id = (String) requestParmProvider.getParameter("obj_id");
        final String msg_name = (String) requestParmProvider.getParameter("message_name");
        final String job_id = (String) requestParmProvider.getParameter("job_id");
        runtime = // $NON-NLS-1$ //$NON-NLS-2$
        solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
        doc.toString(), // $NON-NLS-1$ //$NON-NLS-2$
        obj_id, // $NON-NLS-1$ //$NON-NLS-2$
        job_id, // $NON-NLS-1$ //$NON-NLS-2$
        false, // $NON-NLS-1$ //$NON-NLS-2$
        true, msg_name, true, parameterProviders, outputHandler, null, urlFactory, // $NON-NLS-1$
        new ArrayList());
    } else {
        runtime = // $NON-NLS-1$ //$NON-NLS-2$
        solutionEngine.execute(// $NON-NLS-1$ //$NON-NLS-2$
        doc.toString(), // $NON-NLS-1$ //$NON-NLS-2$
        "chartbeans_mql", // $NON-NLS-1$ //$NON-NLS-2$
        "myprocessid", // $NON-NLS-1$ //$NON-NLS-2$
        false, // $NON-NLS-1$ //$NON-NLS-2$
        true, "myinstanceid", true, parameterProviders, outputHandler, null, urlFactory, // $NON-NLS-1$
        new ArrayList());
    }
    if ((runtime != null) && (runtime.getStatus() != IRuntimeContext.RUNTIME_STATUS_SUCCESS)) {
        StringBuilder buf = new StringBuilder();
        boolean firstIteration = true;
        for (Object /* String */
        message : runtime.getMessages()) {
            if (message instanceof Exception) {
                Exception ex = (Exception) message;
                if (ex.getCause() instanceof RuntimeException) {
                    throw (RuntimeException) ex.getCause();
                }
            }
            if (!firstIteration) {
                // $NON-NLS-1$
                buf.append(" \\\\ ");
            }
            buf.append(message);
        }
        String errorStr;
        if (buf.indexOf("action_sequence_failed") > -1 && buf.indexOf("MQLRelationalDataComponent") > -1) {
            errorStr = Messages.getInstance().getString("DefaultChartBeansGenerator.ERROR_0001_SECURITY_ERROR");
        } else {
            errorStr = Messages.getInstance().getString("DefaultChartBeansGenerator.ERROR_0002_UNKNOWN_ERROR");
        }
        throw new RuntimeException(errorStr);
    }
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) ArrayList(java.util.ArrayList) IOException(java.io.IOException) IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext)

Example 15 with IPentahoUrlFactory

use of org.pentaho.platform.api.engine.IPentahoUrlFactory in project pentaho-platform by pentaho.

the class GlobalOutputIT method testEmptyActionSequence.

public void testEmptyActionSequence() {
    startTest();
    List messages = new ArrayList();
    String instanceId = null;
    IPentahoSession session = new StandaloneSession("system");
    PentahoSessionHolder.setSession(session);
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class);
    solutionEngine.setLoggingLevel(ILogger.ERROR);
    solutionEngine.init(session);
    String baseUrl = PentahoSystem.getApplicationContext().getBaseUrl();
    HashMap parameterProviderMap = new HashMap();
    IPentahoUrlFactory urlFactory = new SimpleUrlFactory(baseUrl);
    try {
        File file = new File(getSolutionPath() + "/samples/platform/SetGlobalOutputTest.xaction");
        StringBuilder str = new StringBuilder();
        Reader reader = new FileReader(file);
        char[] buffer = new char[4096];
        int n = reader.read(buffer);
        while (n != -1) {
            str.append(buffer, 0, n);
            n = reader.read(buffer);
        }
        String xactionStr = str.toString();
        solutionEngine.setSession(session);
        IRuntimeContext runtimeContext = solutionEngine.execute(xactionStr, "SetGlobalOutputTest.xaction", "empty action sequence test", false, true, instanceId, false, parameterProviderMap, null, null, urlFactory, // $NON-NLS-1$ //$NON-NLS-2$
        messages);
        assertNotNull("RuntimeContext is null", runtimeContext);
        assertEquals("Action sequence execution failed", runtimeContext.getStatus(), IRuntimeContext.RUNTIME_STATUS_SUCCESS);
        IParameterProvider provider = PentahoSystem.getGlobalParameters();
        // $NON-NLS-1$
        String parameter = provider.getStringParameter("GLOBAL_TEST", null);
        assertNotNull(parameter);
        // $NON-NLS-1$
        assertEquals("This is a test", parameter);
    } catch (Exception e) {
        // we should not get here
        e.printStackTrace();
        assertTrue(e.getMessage(), false);
    }
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) HashMap(java.util.HashMap) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) ArrayList(java.util.ArrayList) Reader(java.io.Reader) FileReader(java.io.FileReader) IParameterProvider(org.pentaho.platform.api.engine.IParameterProvider) ArrayList(java.util.ArrayList) List(java.util.List) FileReader(java.io.FileReader) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) File(java.io.File) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext)

Aggregations

IPentahoUrlFactory (org.pentaho.platform.api.engine.IPentahoUrlFactory)17 SimpleUrlFactory (org.pentaho.platform.util.web.SimpleUrlFactory)17 ArrayList (java.util.ArrayList)15 HashMap (java.util.HashMap)9 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)8 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)8 OutputStream (java.io.OutputStream)6 IParameterProvider (org.pentaho.platform.api.engine.IParameterProvider)6 IRuntimeContext (org.pentaho.platform.api.engine.IRuntimeContext)6 IOException (java.io.IOException)5 IPentahoRequestContext (org.pentaho.platform.api.engine.IPentahoRequestContext)5 SimpleParameterProvider (org.pentaho.platform.engine.core.solution.SimpleParameterProvider)5 Document (org.dom4j.Document)4 SimpleOutputHandler (org.pentaho.platform.engine.core.output.SimpleOutputHandler)4 PMDUIComponent (org.pentaho.platform.uifoundation.component.xml.PMDUIComponent)4 File (java.io.File)3 FileReader (java.io.FileReader)3 Reader (java.io.Reader)3 List (java.util.List)3 ActionComponent (org.pentaho.platform.uifoundation.component.ActionComponent)3