Search in sources :

Example 6 with IRuntimeElement

use of org.pentaho.platform.api.repository.IRuntimeElement in project pentaho-platform by pentaho.

the class RuntimeRepository method loadElementById.

/**
 * Loads an existing RuntimeElement
 *
 * @param instId
 *          The instance Id
 * @return the RuntimeElement
 * @throws RepositoryException
 */
public IRuntimeElement loadElementById(final String instId, final Collection allowableReadAttributeNames) throws RepositoryException {
    if (RuntimeRepository.debug) {
        // $NON-NLS-1$
        debug(Messages.getInstance().getString("RTREPO.DEBUG_LOAD_ELEMENT_BY_ID", instId));
    }
    Session session = HibernateUtil.getSession();
    try {
        RuntimeElement runtimeElement = (RuntimeElement) session.load(RuntimeElement.class, instId);
        runtimeElement.setAllowableAttributeNames(allowableReadAttributeNames);
        return runtimeElement;
    } catch (HibernateException ex) {
        // $NON-NLS-1$
        error(Messages.getInstance().getErrorString("RTREPO.ERROR_0001_LOAD_ELEMENT", instId), ex);
        throw new RepositoryException(Messages.getInstance().getErrorString("RTREPO.ERROR_0001_LOAD_ELEMENT", instId), // $NON-NLS-1$
        ex);
    }
}
Also used : IRuntimeElement(org.pentaho.platform.api.repository.IRuntimeElement) HibernateException(org.hibernate.HibernateException) RepositoryException(org.pentaho.platform.api.repository.RepositoryException) Session(org.hibernate.Session) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 7 with IRuntimeElement

use of org.pentaho.platform.api.repository.IRuntimeElement 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)

Example 8 with IRuntimeElement

use of org.pentaho.platform.api.repository.IRuntimeElement in project pentaho-platform by pentaho.

the class RuntimeContextTest method testCreateNewInstanceWithParams.

/**
 * Tests that params are passed and saved correctly to the underlying runtime element.
 *
 * @throws Exception
 */
@Test
public void testCreateNewInstanceWithParams() throws Exception {
    final IRuntimeElement elem = new SimpleRuntimeElement(UUIDUtil.getUUIDAsString(), "parentId", "parentType", "sol1");
    when(mockedRuntimeRepository.newRuntimeElement(anyString(), anyString(), anyBoolean())).thenAnswer(new Answer<IRuntimeElement>() {

        @Override
        public IRuntimeElement answer(final InvocationOnMock invocation) throws Throwable {
            Object[] args = invocation.getArguments();
            final String parentId = (String) args[0];
            final String parentType = (String) args[1];
            return elem;
        }
    });
    final boolean persisted = true;
    final boolean forceImmediateWrite = true;
    final List<Integer> list = new ArrayList<>();
    final Map<String, Object> params = new HashMap<>();
    final Date now = new Date();
    final BigDecimal three = new BigDecimal(3.0d);
    params.put("One", "One");
    params.put("Two", new Long(2));
    params.put("Three", three);
    params.put("Date", now);
    list.add(1);
    list.add(2);
    list.add(3);
    params.put("List", list);
    runtimeCtx.createNewInstance(persisted, params, forceImmediateWrite);
    Assert.assertTrue(elem.getStringProperty("One").equals("One"));
    Assert.assertTrue(elem.getLongProperty("Two", 0) == 2);
    Assert.assertTrue(elem.getBigDecimalProperty("Three").equals(three));
    Assert.assertTrue(elem.getDateProperty("Date").equals(now));
    Assert.assertNotNullOrEmpty(elem.getListProperty("List"));
}
Also used : IRuntimeElement(org.pentaho.platform.api.repository.IRuntimeElement) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Matchers.anyString(org.mockito.Matchers.anyString) Date(java.util.Date) BigDecimal(java.math.BigDecimal) InvocationOnMock(org.mockito.invocation.InvocationOnMock) Test(org.junit.Test)

Aggregations

IRuntimeElement (org.pentaho.platform.api.repository.IRuntimeElement)8 BigDecimal (java.math.BigDecimal)3 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 IRuntimeRepository (org.pentaho.platform.api.repository.IRuntimeRepository)3 HashMap (java.util.HashMap)2 List (java.util.List)2 HibernateException (org.hibernate.HibernateException)2 Session (org.hibernate.Session)2 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)2 RepositoryException (org.pentaho.platform.api.repository.RepositoryException)2 SimpleRuntimeElement (org.pentaho.platform.engine.services.runtime.SimpleRuntimeElement)2 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 Test (org.junit.Test)1 Matchers.anyString (org.mockito.Matchers.anyString)1 InvocationOnMock (org.mockito.invocation.InvocationOnMock)1 IPentahoResultSet (org.pentaho.commons.connection.IPentahoResultSet)1 MemoryResultSet (org.pentaho.commons.connection.memory.MemoryResultSet)1