Search in sources :

Example 1 with SimpleRuntimeElement

use of org.pentaho.platform.engine.services.runtime.SimpleRuntimeElement in project pentaho-platform by pentaho.

the class SolutionEngine method execute.

protected IRuntimeContext execute(final String actionPath, final String processId, final boolean async, final boolean instanceEnds, String instanceId, final boolean isPersisted, final Map parameterProviderMap, final IOutputHandler outputHandler, final IActionCompleteListener pListener, final IPentahoUrlFactory urlFactory, final List messages, final String actionSequenceXML) {
    this.persisted = isPersisted;
    setlistener(pListener);
    setSession(session);
    setMessages(messages);
    auditStart(actionPath, instanceId);
    if (!checkParameters(actionPath, processId)) {
        return null;
    }
    session.setProcessId(processId);
    session.setActionName(actionPath);
    // create the runtime context object for this operation
    if (debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("SolutionEngine.DEBUG_GETTING_RUNTIME_CONTEXT"));
    }
    boolean newInstance = instanceId == null;
    IRuntimeRepository runtimeRepository = null;
    if (PentahoSystem.getObjectFactory().objectDefined(IRuntimeRepository.class.getSimpleName())) {
        runtimeRepository = PentahoSystem.get(IRuntimeRepository.class, session);
    }
    IRuntimeElement runtimeData;
    if (runtimeRepository == null) {
        String id = UUIDUtil.getUUIDAsString();
        runtimeData = new SimpleRuntimeElement(id, session.getId(), IParameterProvider.SCOPE_SESSION);
    } else {
        runtimeRepository.setLoggingLevel(loggingLevel);
        if (newInstance) {
            // we need to create runtime data for this execution
            try {
                runtimeData = runtimeRepository.newRuntimeElement(session.getId(), IParameterProvider.SCOPE_SESSION, !persisted);
            } catch (Throwable t) {
                // $NON-NLS-1$
                error(Messages.getInstance().getErrorString("SolutionEngine.ERROR_0008_INVALID_INSTANCE", instanceId), t);
                status = IRuntimeContext.RUNTIME_STATUS_SETUP_FAIL;
                return null;
            }
        } else {
            try {
                runtimeData = runtimeRepository.loadElementById(instanceId, null);
            } catch (Throwable t) {
                // $NON-NLS-1$
                error(Messages.getInstance().getErrorString("SolutionEngine.ERROR_0008_INVALID_INSTANCE", instanceId), t);
                status = IRuntimeContext.RUNTIME_STATUS_SETUP_FAIL;
                return null;
            }
        }
    }
    if (runtimeData == null) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("SolutionEngine.ERROR_0008_INVALID_INSTANCE", instanceId));
        status = IRuntimeContext.RUNTIME_STATUS_SETUP_FAIL;
        return null;
    }
    createRuntime(runtimeData, actionPath, outputHandler, processId, urlFactory);
    runtime.setLoggingLevel(loggingLevel);
    instanceId = runtime.getInstanceId();
    genLogIdFromInfo(instanceId, SolutionEngine.LOG_NAME, actionPath);
    if (newInstance) {
        // audit the creation of this against the session
        AuditHelper.audit(session.getId(), session.getName(), actionPath, getObjectName(), processId, MessageTypes.INSTANCE_START, instanceId, "", 0, // $NON-NLS-1$
        this);
    }
    /*
     * IRuntimeElement runtimeData; if (instanceId == null) { // we need to create runtime data for this execution try {
     * runtimeRepository.setLoggingLevel(loggingLevel); runtimeData =
     * runtimeRepository.newRuntimeElement(session.getId(), IParameterProvider.SCOPE_SESSION, !persisted);
     * createRuntime(runtimeData, solutionName, outputHandler, processId, urlFactory);
     * runtime.setLoggingLevel(loggingLevel); instanceId = runtime.getInstanceId(); genLogIdFromInfo(instanceId,
     * SolutionEngine.LOG_NAME, sequenceName); // audit the creation of this against the session
     * AuditHelper.audit(session.getId(), session.getName(), sequenceName, getObjectName(), processId,
     * MessageTypes.INSTANCE_START, instanceId, "", 0, this); //$NON-NLS-1$ } catch (Throwable t) {
     * error(Messages.getInstance().getErrorString("SolutionEngine.ERROR_0008_INVALID_INSTANCE", instanceId), t);
     * //$NON-NLS-1$ status = IRuntimeContext.RUNTIME_STATUS_SETUP_FAIL; return null; } } else { try {
     * runtimeRepository.setLoggingLevel(loggingLevel); runtimeData = runtimeRepository.loadElementById(instanceId,
     * null); createRuntime(runtimeData, solutionName, outputHandler, processId, urlFactory);
     * runtime.setLoggingLevel(loggingLevel); instanceId = runtime.getInstanceId(); genLogIdFromInfo(instanceId,
     * SolutionEngine.LOG_NAME, sequenceName); } catch (Throwable t) {
     * error(Messages.getInstance().getErrorString("SolutionEngine.ERROR_0008_INVALID_INSTANCE", instanceId), t);
     * //$NON-NLS-1$ status = IRuntimeContext.RUNTIME_STATUS_SETUP_FAIL; return null; } }
     */
    return executeInternal(actionPath, processId, async, instanceEnds, parameterProviderMap, actionSequenceXML);
}
Also used : IRuntimeRepository(org.pentaho.platform.api.repository.IRuntimeRepository) IRuntimeElement(org.pentaho.platform.api.repository.IRuntimeElement) SimpleRuntimeElement(org.pentaho.platform.engine.services.runtime.SimpleRuntimeElement)

Example 2 with SimpleRuntimeElement

use of org.pentaho.platform.engine.services.runtime.SimpleRuntimeElement in project pentaho-platform by pentaho.

the class SimpleRuntimeRepository method newRuntimeElement.

/**
 * Creates a new RuntimeElement
 *
 * @param parId
 *          Parent ID of this instance
 * @param parType
 *          Parent type of the instance
 * @return the created runtime element
 */
public IRuntimeElement newRuntimeElement(final String parId, final String parType, final boolean transientOnly) {
    if (SimpleRuntimeRepository.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("RTREPO.DEBUG_NEW_ELEMENT_PARENT", parId, parType));
    }
    String instanceId = UUIDUtil.getUUIDAsString();
    if (SimpleRuntimeRepository.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("RTREPO.DEBUG_CREATE_INSTANCE", instanceId));
    }
    SimpleRuntimeElement re = new SimpleRuntimeElement(instanceId, parId, parType);
    return re;
}
Also used : SimpleRuntimeElement(org.pentaho.platform.engine.services.runtime.SimpleRuntimeElement)

Example 3 with SimpleRuntimeElement

use of org.pentaho.platform.engine.services.runtime.SimpleRuntimeElement in project pentaho-platform by pentaho.

the class MultipleComponentIT method testSimpleRuntime.

/*
   * public void testReportCharts() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); parameterProvider.setParameter("chart_type", "multipie"); //$NON-NLS-1$ //$NON-NLS-2$
   * parameterProvider.setParameter("output-type", "html"); //$NON-NLS-1$ //$NON-NLS-2$ long curTime =
   * System.currentTimeMillis(); String testName = RC_TEST_NAME + "multipie_" + curTime; //$NON-NLS-1$ IRuntimeContext
   * context = run( "test", "reporting/JFreeReportChartTypes", "JFreeReport_Chart_ChartTypes.xaction",
   * parameterProvider, testName, RC_TEST_EXTN); //$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$ InputStream is = this.getInputStreamFromOutput(testName, RC_TEST_EXTN);
   * assertNotNull(is); try { is.close(); } catch (Exception ignored) { }
   * 
   * parameterProvider.setParameter("chart_type", "line"); //$NON-NLS-1$ //$NON-NLS-2$ testName = RC_TEST_NAME + "line_"
   * + curTime; //$NON-NLS-1$ context = run( "test", "reporting/JFreeReportChartTypes",
   * "JFreeReport_Chart_ChartTypes.xaction", parameterProvider, testName, RC_TEST_EXTN); //$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$ is =
   * this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is); try { is.close(); } catch (Exception
   * ignored) { }
   * 
   * parameterProvider.setParameter("chart_type", "area"); //$NON-NLS-1$ //$NON-NLS-2$ testName = RC_TEST_NAME + "area_"
   * + curTime; //$NON-NLS-1$ context = run( "test", "reporting/JFreeReportChartTypes",
   * "JFreeReport_Chart_ChartTypes.xaction", parameterProvider, testName, RC_TEST_EXTN); //$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$ is =
   * this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is); try { is.close(); } catch (Exception
   * ignored) { }
   * 
   * parameterProvider.setParameter("chart_type", "stackedarea"); //$NON-NLS-1$ //$NON-NLS-2$ testName = RC_TEST_NAME +
   * "stackedarea_" + curTime; //$NON-NLS-1$ context = run( "test", "reporting/JFreeReportChartTypes",
   * "JFreeReport_Chart_ChartTypes.xaction", parameterProvider, testName, RC_TEST_EXTN); //$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$ is =
   * this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is); try { is.close(); } catch (Exception
   * ignored) { }
   * 
   * parameterProvider.setParameter("chart_type", "bar"); //$NON-NLS-1$ //$NON-NLS-2$ testName = RC_TEST_NAME + "bar_" +
   * curTime; //$NON-NLS-1$ context = run( "test", "reporting/JFreeReportChartTypes",
   * "JFreeReport_Chart_ChartTypes.xaction", parameterProvider, testName, RC_TEST_EXTN); //$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$ is =
   * this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is); try { is.close(); } catch (Exception
   * ignored) { }
   * 
   * parameterProvider.setParameter("chart_type", "stackedbar"); //$NON-NLS-1$ //$NON-NLS-2$ testName = RC_TEST_NAME +
   * "stackedbar_" + curTime; //$NON-NLS-1$ context = run( "test", "reporting/JFreeReportChartTypes",
   * "JFreeReport_Chart_ChartTypes.xaction", parameterProvider, testName, RC_TEST_EXTN); //$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$ is =
   * this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is); try { is.close(); } catch (Exception
   * ignored) { }
   * 
   * parameterProvider.setParameter("chart_type", "stackedbarpercentages"); //$NON-NLS-1$ //$NON-NLS-2$ testName =
   * RC_TEST_NAME + "stackedbarpercentages_" + curTime; //$NON-NLS-1$ context = run( "test",
   * "reporting/JFreeReportChartTypes", "JFreeReport_Chart_ChartTypes.xaction", parameterProvider, testName,
   * RC_TEST_EXTN); //$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$ is = this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is);
   * try { is.close(); } catch (Exception ignored) { }
   * 
   * parameterProvider.setParameter("chart_type", "pie"); //$NON-NLS-1$ //$NON-NLS-2$ testName = RC_TEST_NAME + "pie_" +
   * curTime; //$NON-NLS-1$ context = run( "test", "reporting/JFreeReportChartTypes",
   * "JFreeReport_Chart_ChartTypes.xaction", parameterProvider, testName, RC_TEST_EXTN); //$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$ is =
   * this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is); try { is.close(); } catch (Exception
   * ignored) { }
   * 
   * finishTest(); }
   */
/*
   * public void testDynamicSQLAndSecureFilter() { startTest(); SimpleParameterProvider parameterProvider = new
   * SimpleParameterProvider(); // Add no parameters yet for first run String testName = DS_TEST_NAME +
   * "parameterResponse_" + System.currentTimeMillis(); //$NON-NLS-1$ IRuntimeContext context = run( "test",
   * "reporting", "DynamicSQLSample.xaction", parameterProvider, testName, DS_TEST_EXTN); //$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$ // Should have created a Feedback html
   * page in the output. InputStream is = this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is);
   * String feedbackHTML = FileHelper.getStringFromInputStream(is); assertNotNull(feedbackHTML); // Make sure it's
   * feedback HTML we have...
   * assertTrue(feedbackHTML.indexOf("Use this form to supply the parameters required for this content") > 0);
   * //$NON-NLS-1$ assertTrue(feedbackHTML.indexOf("Select: Department or Position") > 0); //$NON-NLS-1$ // OK - now,
   * supply all the parameters and re-run. parameterProvider.setParameter("deptorposn", "department"); //$NON-NLS-1$
   * //$NON-NLS-2$ parameterProvider.setParameter("type", "html"); //$NON-NLS-1$ //$NON-NLS-2$
   * parameterProvider.setParameter("region", "Central"); //$NON-NLS-1$ //$NON-NLS-2$ testName = DS_TEST_NAME + "report_"
   * + System.currentTimeMillis(); //$NON-NLS-1$ context = run("test", "reporting", "DynamicSQLSample.xaction",
   * parameterProvider, testName, DS_TEST_EXTN); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
   * assertEquals(context.getStatus(), IRuntimeContext.RUNTIME_STATUS_SUCCESS); // Should have created a report html
   * page in the output. is = this.getInputStreamFromOutput(testName, RC_TEST_EXTN); assertNotNull(is); String
   * reportHTML = FileHelper.getStringFromInputStream(is); assertNotNull(reportHTML); // Insure it has information
   * assertTrue(reportHTML.indexOf("Professional Services") > 0); //$NON-NLS-1$
   * assertTrue(reportHTML.indexOf("20,068,039") > 0); //$NON-NLS-1$ finishTest(); }
   */
public void testSimpleRuntime() {
    // The simple runtime is used by the standalone distribution.
    // This provides some simple tests to exercise the code...
    startTest();
    StandaloneSession session = // $NON-NLS-1$
    new StandaloneSession(Messages.getInstance().getString("BaseTest.DEBUG_JUNIT_SESSION"));
    IRuntimeRepository srr = new SimpleRuntimeRepository();
    srr.setSession(session);
    // $NON-NLS-1$
    IRuntimeElement ele1 = srr.loadElementById("instanceid", null);
    // $NON-NLS-1$ //$NON-NLS-2$
    IRuntimeElement ele2 = srr.newRuntimeElement("parent", "parentType", true);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    IRuntimeElement ele3 = srr.newRuntimeElement("parentid", "parentType", "solutionId", true);
    // $NON-NLS-1$
    SimpleRuntimeElement sre = (SimpleRuntimeElement) srr.loadElementById("instanceid", null);
    List list = sre.getMessages();
    if (list != null) {
        for (int i = 0; i < list.size(); i++) {
            // $NON-NLS-1$
            System.out.println("Message " + (i + 1) + list.get(i));
        }
        // $NON-NLS-1$
        sre.setParentId("parentid1");
        // $NON-NLS-1$
        sre.setParentType("parentidType1");
        // $NON-NLS-1$
        sre.setSolutionId("solutionId1");
        sre.setReadOnly(true);
        boolean isReadOnly = sre.getReadOnly();
        String parentId = sre.getParentId();
        String parentIdType = sre.getParentType();
        String solutionId = sre.getSolutionId();
        assertEquals(isReadOnly, true);
        // $NON-NLS-1$
        assertEquals(parentId, "parentid1");
        // $NON-NLS-1$
        assertEquals(parentIdType, "parentidType1");
        // $NON-NLS-1$
        assertEquals(solutionId, "solutionId1");
    }
    int revision = sre.getRevision();
    // $NON-NLS-1$
    System.out.println("Revision Value is" + revision);
    // $NON-NLS-1$ //$NON-NLS-2$
    sre.setStringProperty("parentId", "value");
    // $NON-NLS-1$
    BigDecimal tstBD = new BigDecimal("2.4");
    // $NON-NLS-1$
    ele2.setBigDecimalProperty("junkBD", tstBD);
    // $NON-NLS-1$
    BigDecimal bd = ele2.getBigDecimalProperty("junkBD");
    assertEquals(bd, tstBD);
    Date tstDT = new Date();
    // $NON-NLS-1$
    ele3.setDateProperty("junkDT", tstDT);
    // $NON-NLS-1$
    Date dt = ele3.getDateProperty("junkDT");
    assertEquals(tstDT, dt);
    List l = new ArrayList();
    // $NON-NLS-1$
    l.add("one");
    // $NON-NLS-1$
    l.add("two");
    // $NON-NLS-1$
    ele1.setListProperty("SOMELIST", l);
    // $NON-NLS-1$
    assertEquals(ele1.getListProperty("SOMELIST"), l);
    Long aLong = new Long(5);
    // $NON-NLS-1$
    ele2.setLongProperty("SOMELONG", aLong);
    // $NON-NLS-1$
    assertEquals(ele2.getLongProperty("SOMELONG", null), aLong);
    // $NON-NLS-1$
    assertEquals(ele2.getLongProperty("SOMELONG", 5), 5);
    Map mapProperty = new HashMap();
    // $NON-NLS-1$ //$NON-NLS-2$
    mapProperty.put("mapKey", "mapValue");
    // $NON-NLS-1$
    ele3.setMapProperty("SOMEMAP", mapProperty);
    // $NON-NLS-1$
    assertEquals(ele3.getMapProperty("SOMEMAP"), mapProperty);
    // $NON-NLS-1$ //$NON-NLS-2$
    ele1.setStringProperty("SOMESTRING", "SomeStringValue");
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals(ele1.getStringProperty("SOMESTRING"), "SomeStringValue");
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals(ele2.getStringProperty("DOESNTEXIST", "SomeDefault"), "SomeDefault");
    // $NON-NLS-1$
    assertNull(ele1.getStringProperty("DOESNTEXIST"));
    // $NON-NLS-1$
    assertNull(ele1.getBigDecimalProperty("DOESNTEXIST"));
    // $NON-NLS-1$
    assertNull(ele2.getDateProperty("DOESNTEXIST"));
    // $NON-NLS-1$
    assertNull(ele3.getListProperty("DOESNTEXIST"));
    // $NON-NLS-1$
    assertEquals(ele2.getLongProperty("DOESNTEXIST", 2), 2);
    // $NON-NLS-1$
    assertEquals(ele2.getLongProperty("DOESNTEXIST", new Long(2)), new Long(2));
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    assertEquals(ele1.getBigDecimalProperty("DOESNTEXIST", new BigDecimal("0.23")), new BigDecimal("0.23"));
    Date tmpDate = new Date();
    // $NON-NLS-1$
    assertEquals(ele1.getDateProperty("DOESNTEXIST", tmpDate), tmpDate);
    Set parmNames = ele1.getParameterNames();
    assertNotNull(parmNames);
    assertFalse(srr.usesHibernate());
    // $NON-NLS-1$ //$NON-NLS-2$
    assertEquals(ele2.getParameterType("SOMELONG"), "java.lang.Long");
    // $NON-NLS-1$
    assertEquals(ele2.getParentType(), "parentType");
    // $NON-NLS-1$
    assertEquals(ele3.getParentId(), "parentid");
    // $NON-NLS-1$
    assertEquals(ele1.getInstanceId(), "instanceid");
    finishTest();
}
Also used : Set(java.util.Set) MemoryResultSet(org.pentaho.commons.connection.memory.MemoryResultSet) IPentahoResultSet(org.pentaho.commons.connection.IPentahoResultSet) StandaloneSession(org.pentaho.platform.engine.core.system.StandaloneSession) IRuntimeElement(org.pentaho.platform.api.repository.IRuntimeElement) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SimpleRuntimeRepository(org.pentaho.platform.repository.SimpleRuntimeRepository) SimpleRuntimeElement(org.pentaho.platform.engine.services.runtime.SimpleRuntimeElement) BigDecimal(java.math.BigDecimal) Date(java.util.Date) IRuntimeRepository(org.pentaho.platform.api.repository.IRuntimeRepository) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

SimpleRuntimeElement (org.pentaho.platform.engine.services.runtime.SimpleRuntimeElement)3 IRuntimeElement (org.pentaho.platform.api.repository.IRuntimeElement)2 IRuntimeRepository (org.pentaho.platform.api.repository.IRuntimeRepository)2 BigDecimal (java.math.BigDecimal)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)1 MemoryResultSet (org.pentaho.commons.connection.memory.MemoryResultSet)1 StandaloneSession (org.pentaho.platform.engine.core.system.StandaloneSession)1 SimpleRuntimeRepository (org.pentaho.platform.repository.SimpleRuntimeRepository)1