Search in sources :

Example 1 with IPentahoUrlFactory

use of org.pentaho.platform.api.engine.IPentahoUrlFactory 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();
                }
            }
        }
    }
}
Also used : ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) HashMap(java.util.HashMap) 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 2 with IPentahoUrlFactory

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

the class JFreeReportIT method testJFreeReportWithChartActionComponent.

/*
   * public void testJFreeReportParameterPage3() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream
   * outputStream = getOutputStream("ReportingTest.testJFreeReportParameterPage3", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext
   * context = run( "test", "reporting", "jfreereport-reports-test-param3.xaction", null, false, parameterProvider,
   * outputHandler, session); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success finishTest(); }
   */
/*
   * public void testJFreeReport1() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream
   * outputStream = getOutputStream("ReportingTest.JFreeReporthtml", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext
   * context = run( "test", "reporting", "jfreereport-reports-test-1.xaction", null, false, parameterProvider,
   * outputHandler, session); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success finishTest(); }
   */
/*
   * public void testJFreeReport2() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "pdf"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream
   * outputStream = getOutputStream("ReportingTest.JFreeReport-2-PDF", ".pdf"); //$NON-NLS-1$ //$NON-NLS-2$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext
   * context = run( "test", "reporting", "jfreereport-reports-test-2.xaction", null, false, parameterProvider,
   * outputHandler, session); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success finishTest(); }
   * 
   * public void testJFreeReport3() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "xls"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream
   * outputStream = getOutputStream("ReportingTest.JFreeReportxls", ".xls"); //$NON-NLS-1$ //$NON-NLS-2$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext
   * context = run( "test", "reporting", "jfreereport-reports-test-1.xaction", null, false, parameterProvider,
   * outputHandler, session); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success finishTest(); }
   * 
   * public void testJFreeReport4() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$ OutputStream
   * outputStream = getOutputStream("ReportingTest.JFreeReporthtml", ".html"); //$NON-NLS-1$ //$NON-NLS-2$
   * SimpleOutputHandler outputHandler = new SimpleOutputHandler(outputStream, true); StandaloneSession session = new
   * StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION")); //$NON-NLS-1$ IRuntimeContext
   * context = run( "test", "reporting", "jfreereport-reports-test-1.xaction", null, false, parameterProvider,
   * outputHandler, session); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ // TODO need some validation of success finishTest(); }
   * 
   * public void testJFreeReport5() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "pdf"); //$NON-NLS-1$ //$NON-NLS-2$
   * parameterProvider.setParameter("solution", getSolutionPath()); //$NON-NLS-1$ //$NON-NLS-2$ IRuntimeContext context
   * = run( "test", "reporting", "jfreereport-reports-file.xaction", parameterProvider, "dummy", "txt"); //$NON-NLS-1$
   * //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ finishTest(); }
   */
/*
   * public void testJFreeReport6() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "csv"); //$NON-NLS-1$ //$NON-NLS-2$
   * IRuntimeContext context = run( "test", "reporting", "jfreereport-reports-file.xaction", parameterProvider, "dummy",
   * "txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ finishTest(); }
   * 
   * public void testJFreeReport7() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "xls"); //$NON-NLS-1$ //$NON-NLS-2$
   * IRuntimeContext context = run( "test", "reporting", "jfreereport-reports-file.xaction", parameterProvider, "dummy",
   * "txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ finishTest(); }
   * 
   * public void testJFreeReport8() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "rtf"); //$NON-NLS-1$ //$NON-NLS-2$
   * IRuntimeContext context = run( "test", "reporting", "jfreereport-reports-file.xaction", parameterProvider, "dummy",
   * "txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ finishTest(); }
   */
/*
   * public void testJFreeReport9() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "zip"); //$NON-NLS-1$ //$NON-NLS-2$
   * IRuntimeContext context = run( "test", "reporting", "jfreereport-reports-file.xaction", parameterProvider, "dummy",
   * "txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ finishTest(); }
   * 
   * public void testJFreeReport10() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("type", "xml"); //$NON-NLS-1$ //$NON-NLS-2$
   * IRuntimeContext context = run( "test", "reporting", "jfreereport-reports-file.xaction", parameterProvider, "dummy",
   * "txt"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$ assertEquals(
   * Messages.getInstance().getString("BaseTest.USER_RUNNING_ACTION_SEQUENCE"), IRuntimeContext.RUNTIME_STATUS_SUCCESS,
   * context.getStatus()); //$NON-NLS-1$ finishTest(); }
   */
public void testJFreeReportWithChartActionComponent() {
    startTest();
    IPentahoRequestContext requestContext = PentahoRequestContextHolder.getRequestContext();
    IPentahoUrlFactory urlFactory = new SimpleUrlFactory(requestContext.getContextPath());
    ArrayList messages = new ArrayList();
    SimpleParameterProvider parameterProvider = new SimpleParameterProvider();
    // $NON-NLS-1$ //$NON-NLS-2$
    parameterProvider.setParameter("solution", "test");
    // $NON-NLS-1$ //$NON-NLS-2$
    parameterProvider.setParameter("path", "reporting");
    // $NON-NLS-1$ //$NON-NLS-2$
    parameterProvider.setParameter("action", "JFree_XQuery_Chart_report.xaction");
    ActionComponent component = new ActionComponent("samples/reporting/JFree_XQuery_Chart_report.xaction", null, IOutputHandler.OUTPUT_TYPE_DEFAULT, urlFactory, // $NON-NLS-1$
    messages);
    component.setParameterProvider(IParameterProvider.SCOPE_REQUEST, parameterProvider);
    StandaloneSession session = // $NON-NLS-1$
    new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
    component.validate(session, null);
    // $NON-NLS-1$ //$NON-NLS-2$
    OutputStream outputStream = getOutputStream("ReportingTest.testJFreeReportWithChartActionComponent", ".html");
    // $NON-NLS-1$
    String content = component.getContent("text/html");
    try {
        outputStream.write(content.getBytes());
    } catch (Exception e) {
    // ignore
    }
    finishTest();
}
Also used : IPentahoRequestContext(org.pentaho.platform.api.engine.IPentahoRequestContext) IPentahoUrlFactory(org.pentaho.platform.api.engine.IPentahoUrlFactory) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) ActionComponent(org.pentaho.platform.uifoundation.component.ActionComponent) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) SimpleParameterProvider(org.pentaho.platform.engine.core.solution.SimpleParameterProvider)

Example 3 with IPentahoUrlFactory

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

the class MetadataIT method __testLookup.

public void __testLookup() {
    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_LOOKUP);
    // $NON-NLS-1$
    component.setDomainName("test");
    // $NON-NLS-1$
    component.setModelId("Orders");
    // $NON-NLS-1$
    component.setColumnId("BC_CUSTOMERS_CUSTOMERNAME");
    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 4 with IPentahoUrlFactory

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

the class MetadataIT method testViewList.

public void testViewList() {
    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_LIST_MODELS);
    Document doc = component.getXmlContent();
    System.out.println(doc.asXML());
    try {
        // $NON-NLS-1$//$NON-NLS-2$
        OutputStream outputStream = getOutputStream("MetadataTest.testViewList", ".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 5 with IPentahoUrlFactory

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

the class ServiceLayerTest method testEmptyActionSequence.

@Test
public void testEmptyActionSequence() throws IOException {
    List<Object> messages = new ArrayList<Object>();
    String instanceId = null;
    IPentahoSession session = new StandaloneSession("system");
    ISolutionEngine solutionEngine = PentahoSystem.get(ISolutionEngine.class, session);
    solutionEngine.setLoggingLevel(ILogger.ERROR);
    solutionEngine.init(session);
    Map<Object, Object> parameterProviderMap = new HashMap<Object, Object>();
    IPentahoUrlFactory urlFactory = new SimpleUrlFactory("");
    Reader reader = null;
    try {
        File file = new File(SOLUTION_PATH + "/services_layer/test1.xaction");
        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);
        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$
        instanceId, false, parameterProviderMap, null, null, urlFactory, messages);
        assertNotNull("RuntimeContext is null", runtimeContext);
        assertEquals("Action sequence execution failed", runtimeContext.getStatus(), IRuntimeContext.RUNTIME_STATUS_SUCCESS);
    } catch (Exception e) {
        // we should not get here
        e.printStackTrace();
        assertTrue(e.getMessage(), false);
    } finally {
        if (reader != null) {
            reader.close();
        }
    }
}
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) PlatformInitializationException(org.pentaho.platform.engine.core.system.boot.PlatformInitializationException) IOException(java.io.IOException) FileReader(java.io.FileReader) SimpleUrlFactory(org.pentaho.platform.util.web.SimpleUrlFactory) File(java.io.File) IRuntimeContext(org.pentaho.platform.api.engine.IRuntimeContext) Test(org.junit.Test)

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