Search in sources :

Example 26 with IPentahoObjectFactory

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

the class BootTest method testBoot.

@Test
public void testBoot() throws Exception {
    PentahoSystemBoot boot = new PentahoSystemBoot();
    boot.setFilePath("solution");
    IPentahoObjectFactory factory = boot.getFactory();
    assertNotNull("object factory is null", factory);
    assertTrue("object factory not definable", factory instanceof IPentahoDefinableObjectFactory);
    boot.define(ISolutionEngine.class.getSimpleName(), Object1.class.getName(), IPentahoDefinableObjectFactory.Scope.GLOBAL);
    boot.define("MyObject", Object1.class.getName(), IPentahoDefinableObjectFactory.Scope.GLOBAL);
    boot.define("MyObject", Object2.class.getName(), IPentahoDefinableObjectFactory.Scope.GLOBAL);
    assertFalse(boot.isInitialized());
    boolean ok = boot.start();
    assertNull(boot.getSettingsProvider());
    assertTrue(boot.isInitialized());
    assertTrue(ok);
    factory = boot.getFactory();
    Object2 object = factory.get(Object2.class, "MyObject", null);
    assertNotNull("object get failed", object);
    assertEquals("file path is wrong", "solution", boot.getFilePath());
    boot.stop();
    assertFalse(boot.isInitialized());
}
Also used : PentahoSystemBoot(org.pentaho.platform.engine.core.system.boot.PentahoSystemBoot) IPentahoDefinableObjectFactory(org.pentaho.platform.api.engine.IPentahoDefinableObjectFactory) ISolutionEngine(org.pentaho.platform.api.engine.ISolutionEngine) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) Test(org.junit.Test)

Example 27 with IPentahoObjectFactory

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

the class PluginManagerNotConfiguredIT method setUp.

public void setUp() {
    List<?> messages = TestManager.getMessagesList();
    if (messages == null) {
        messages = new ArrayList<String>();
    }
    if (initOk) {
        return;
    }
    PentahoSystem.setSystemSettingsService(new PathBasedSystemSettings());
    if (PentahoSystem.getApplicationContext() == null) {
        // $NON-NLS-1$
        StandaloneApplicationContext applicationContext = new StandaloneApplicationContext(getSolutionPath(), "");
        // $NON-NLS-1$ //$NON-NLS-2$
        String inContainer = System.getProperty("incontainer", "false");
        if (inContainer.equalsIgnoreCase("false")) {
            // $NON-NLS-1$
            // Setup simple-jndi for datasources
            // $NON-NLS-1$ //$NON-NLS-2$
            System.setProperty("java.naming.factory.initial", "org.osjava.sj.SimpleContextFactory");
            // $NON-NLS-1$ //$NON-NLS-2$
            System.setProperty("org.osjava.sj.root", getSolutionPath() + "/system/simple-jndi");
            // $NON-NLS-1$ //$NON-NLS-2$
            System.setProperty("org.osjava.sj.delimiter", "/");
        }
        ApplicationContext springApplicationContext = getSpringApplicationContext();
        IPentahoObjectFactory pentahoObjectFactory = new StandaloneSpringPentahoObjectFactory();
        pentahoObjectFactory.init(null, springApplicationContext);
        PentahoSystem.registerObjectFactory(pentahoObjectFactory);
        // force Spring to populate PentahoSystem
        // $NON-NLS-1$
        springApplicationContext.getBean("pentahoSystemProxy");
        initOk = PentahoSystem.init(applicationContext);
    } else {
        initOk = true;
    }
    initOk = true;
}
Also used : StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) PathBasedSystemSettings(org.pentaho.platform.engine.core.system.PathBasedSystemSettings) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Example 28 with IPentahoObjectFactory

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

the class SessionCachingMetadataDomainRepositoryIT method testCannotCreateCache.

public void testCannotCreateCache() throws Exception {
    SimpleObjectFactory factory = new SimpleObjectFactory();
    // $NON-NLS-1$
    factory.defineObject("ICacheManager", MockDisabledCacheManager.class.getName());
    // Swap in an object factory with a cache manager that doesn't allow creating new caches
    Set<IPentahoObjectFactory> facts = ((AggregateObjectFactory) PentahoSystem.getObjectFactory()).getFactories();
    PentahoSystem.clearObjectFactory();
    PentahoSystem.registerObjectFactory(factory);
    try {
        try {
            new SessionCachingMetadataDomainRepository(new MockSessionAwareMetadataDomainRepository());
            // $NON-NLS-1$
            fail("Should not be able to create a Session Caching Repository without an enabled cache");
        } catch (IllegalStateException ex) {
            // $NON-NLS-1$
            assertTrue(ex.getMessage().contains("cannot be initialized"));
        // expected
        }
    } finally {
        // Replace the original object factory so the rest of the tests work
        PentahoSystem.clearObjectFactory();
        for (IPentahoObjectFactory fact : facts) {
            PentahoSystem.registerObjectFactory(fact);
        }
    }
}
Also used : SimpleObjectFactory(org.pentaho.test.platform.engine.core.SimpleObjectFactory) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) SessionCachingMetadataDomainRepository(org.pentaho.platform.plugin.services.metadata.SessionCachingMetadataDomainRepository) AggregateObjectFactory(org.pentaho.platform.engine.core.system.objfac.AggregateObjectFactory)

Example 29 with IPentahoObjectFactory

use of org.pentaho.platform.api.engine.IPentahoObjectFactory in project data-access by pentaho.

the class DebugModelerService method getSession.

private IPentahoSession getSession() {
    IPentahoSession session = null;
    IPentahoObjectFactory pentahoObjectFactory = PentahoSystem.getObjectFactory();
    if (pentahoObjectFactory != null) {
        try {
            // $NON-NLS-1$
            session = pentahoObjectFactory.get(IPentahoSession.class, "systemStartupSession", null);
        } catch (ObjectFactoryException e) {
            e.printStackTrace();
        }
    }
    return session;
}
Also used : IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession)

Example 30 with IPentahoObjectFactory

use of org.pentaho.platform.api.engine.IPentahoObjectFactory in project data-access by pentaho.

the class PentahoSystemHelper method init.

public static void init() {
    if (PentahoSystem.getInitializedOK()) {
        return;
    }
    try {
        PentahoSystem.setSystemSettingsService(new PathBasedSystemSettings());
        if (PentahoSystem.getApplicationContext() == null) {
            StandaloneApplicationContext applicationContext = // $NON-NLS-1$
            new StandaloneApplicationContext(getSolutionPath(), "");
            // set the base url assuming there is a running server on port 8080
            if (PentahoRequestContextHolder.getRequestContext() != null) {
                applicationContext.setFullyQualifiedServerURL(PentahoRequestContextHolder.getRequestContext().getContextPath());
            }
            // $NON-NLS-1$ //$NON-NLS-2$
            String inContainer = System.getProperty("incontainer", "false");
            if (inContainer.equalsIgnoreCase("false")) {
                // $NON-NLS-1$
                // Setup simple-jndi for datasources
                System.setProperty("java.naming.factory.initial", // $NON-NLS-1$ //$NON-NLS-2$
                "org.osjava.sj.SimpleContextFactory");
                System.setProperty("org.osjava.sj.root", // $NON-NLS-1$ //$NON-NLS-2$
                getSolutionPath() + "/system/simple-jndi");
                // $NON-NLS-1$ //$NON-NLS-2$
                System.setProperty("org.osjava.sj.delimiter", "/");
            }
            ApplicationContext springApplicationContext = getSpringApplicationContext();
            IPentahoObjectFactory pentahoObjectFactory = new StandaloneSpringPentahoObjectFactory();
            pentahoObjectFactory.init(null, springApplicationContext);
            PentahoSystem.registerObjectFactory(pentahoObjectFactory);
            // force Spring to inject PentahoSystem, there has got to be a better way than this,
            // perhaps an alternate way of initting spring's app context
            // $NON-NLS-1$
            springApplicationContext.getBean("pentahoSystemProxy");
            PentahoSystem.init(applicationContext);
        }
    } catch (Exception e) {
        logger.error(e);
    }
}
Also used : StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) ApplicationContext(org.springframework.context.ApplicationContext) GenericApplicationContext(org.springframework.context.support.GenericApplicationContext) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) StandaloneApplicationContext(org.pentaho.platform.engine.core.system.StandaloneApplicationContext) PathBasedSystemSettings(org.pentaho.platform.engine.core.system.PathBasedSystemSettings) StandaloneSpringPentahoObjectFactory(org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)

Aggregations

IPentahoObjectFactory (org.pentaho.platform.api.engine.IPentahoObjectFactory)30 StandaloneSpringPentahoObjectFactory (org.pentaho.platform.engine.core.system.objfac.StandaloneSpringPentahoObjectFactory)9 Test (org.junit.Test)7 StandaloneApplicationContext (org.pentaho.platform.engine.core.system.StandaloneApplicationContext)7 IPentahoDefinableObjectFactory (org.pentaho.platform.api.engine.IPentahoDefinableObjectFactory)6 IPentahoObjectReference (org.pentaho.platform.api.engine.IPentahoObjectReference)6 PathBasedSystemSettings (org.pentaho.platform.engine.core.system.PathBasedSystemSettings)6 ArrayList (java.util.ArrayList)5 IPentahoSession (org.pentaho.platform.api.engine.IPentahoSession)5 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)5 PentahoSystemBoot (org.pentaho.platform.engine.core.system.boot.PentahoSystemBoot)5 GenericApplicationContext (org.springframework.context.support.GenericApplicationContext)5 HashSet (java.util.HashSet)3 ISystemConfig (org.pentaho.platform.api.engine.ISystemConfig)3 ApplicationContext (org.springframework.context.ApplicationContext)3 File (java.io.File)2 Map (java.util.Map)2 Properties (java.util.Properties)2 IConfiguration (org.pentaho.platform.api.engine.IConfiguration)2 ISolutionEngine (org.pentaho.platform.api.engine.ISolutionEngine)2