Search in sources :

Example 21 with IPentahoObjectFactory

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

the class PentahoSystemTest method initXMLFactories.

private void initXMLFactories(boolean factoriesInPentahoXML) throws Exception {
    // mock pentaho.xml
    final ISystemSettings settingsService = mock(ISystemSettings.class);
    if (factoriesInPentahoXML) {
        final Node testNode = mock(Node.class);
        final Node testNodeName = mock(Node.class);
        when(testNodeName.getText()).thenReturn(testSystemPropertyName);
        when(testNode.selectSingleNode(eq("@name"))).thenReturn(testNodeName);
        final Node testNodeImplementation = mock(Node.class);
        when(testNodeImplementation.getText()).thenReturn(testXMLValue);
        when(testNode.selectSingleNode(eq("@implementation"))).thenReturn(testNodeImplementation);
        when(settingsService.getSystemSettings(eq("xml-factories/factory-impl"))).thenReturn(new LinkedList() {

            {
                add(testNode);
            }
        });
    } else {
        when(settingsService.getSystemSettings(eq("xml-factories/factory-impl"))).thenReturn(new LinkedList());
    }
    when(settingsService.getSystemSetting(anyString(), anyString())).thenReturn("");
    PentahoSystem.setSystemSettingsService(settingsService);
    // mock java-system-properties.properties
    final IPentahoObjectFactory objectFactory = mock(IPentahoObjectFactory.class);
    final ISystemConfig systemConfig = mock(ISystemConfig.class);
    final IConfiguration configuration = mock(IConfiguration.class);
    when(configuration.getProperties()).thenReturn(new Properties() {

        {
            setProperty(testSystemPropertyName, testPropertyValue);
        }
    });
    when(systemConfig.getConfiguration(eq(PentahoSystem.JAVA_SYSTEM_PROPERTIES))).thenReturn(configuration);
    when(objectFactory.objectDefined(eq(ISystemConfig.class))).thenReturn(true);
    final IPentahoObjectReference pentahoObjectReference = mock(IPentahoObjectReference.class);
    when(pentahoObjectReference.getObject()).thenReturn(systemConfig);
    when(objectFactory.getObjectReferences(eq(ISystemConfig.class), any(IPentahoSession.class), any(Map.class))).thenReturn(new LinkedList() {

        {
            add(pentahoObjectReference);
        }
    });
    PentahoSystem.registerObjectFactory(objectFactory);
    PentahoSystem.init();
}
Also used : IPentahoObjectReference(org.pentaho.platform.api.engine.IPentahoObjectReference) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) IPentahoSession(org.pentaho.platform.api.engine.IPentahoSession) Node(org.dom4j.Node) ISystemConfig(org.pentaho.platform.api.engine.ISystemConfig) ISystemSettings(org.pentaho.platform.api.engine.ISystemSettings) IConfiguration(org.pentaho.platform.api.engine.IConfiguration) Properties(java.util.Properties) Map(java.util.Map) LinkedList(java.util.LinkedList)

Example 22 with IPentahoObjectFactory

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

the class PentahoBoot method enablePooledDatasources.

/**
 * Enables the pooled datasources
 */
public void enablePooledDatasources() {
    IPentahoObjectFactory objectFactory = getFactory();
    if (objectFactory instanceof IPentahoDefinableObjectFactory) {
        define(IDBDatasourceService.class, PooledOrJndiDatasourceService.class, Scope.LOCAL);
        define(IPooledDatasourceService.class, PooledDatasourceService.class, Scope.LOCAL);
        define(IJndiDatasourceService.class, JndiDatasourceService.class, Scope.LOCAL);
    }
    addLifecycleListener(new PooledDatasourceSystemListener());
}
Also used : IPentahoDefinableObjectFactory(org.pentaho.platform.api.engine.IPentahoDefinableObjectFactory) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) PooledDatasourceSystemListener(org.pentaho.platform.engine.services.connection.datasource.dbcp.PooledDatasourceSystemListener)

Example 23 with IPentahoObjectFactory

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

the class AggregateObjectFactory method getObjectReference.

@Override
public <T> IPentahoObjectReference<T> getObjectReference(Class<T> interfaceClass, IPentahoSession curSession, Map<String, String> properties) throws ObjectFactoryException {
    Set<IPentahoObjectReference<T>> references = new HashSet<IPentahoObjectReference<T>>();
    readLock.lock();
    try {
        for (IPentahoObjectFactory fact : factories) {
            if (fact.objectDefined(interfaceClass)) {
                List<IPentahoObjectReference<T>> found = fact.getObjectReferences(interfaceClass, curSession, properties);
                if (found != null) {
                    references.addAll(found);
                }
            }
        }
    } finally {
        readLock.unlock();
    }
    IPentahoObjectReference<T> highestRef = null;
    int highestRefPriority = -1;
    for (IPentahoObjectReference<T> ref : references) {
        int pri = computePriority(ref);
        if (pri > highestRefPriority) {
            highestRef = ref;
            highestRefPriority = pri;
        }
    }
    return highestRef;
}
Also used : IPentahoObjectReference(org.pentaho.platform.api.engine.IPentahoObjectReference) IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) HashSet(java.util.HashSet)

Example 24 with IPentahoObjectFactory

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

the class AggregateObjectFactory method get.

@Override
public <T> T get(Class<T> clazz, IPentahoSession session, Map<String, String> properties) throws ObjectFactoryException {
    IPentahoObjectReference<T> highestRef = this.getObjectReference(clazz, session, properties);
    if (highestRef != null) {
        return highestRef.getObject();
    }
    readLock.lock();
    try {
        for (IPentahoObjectFactory fact : factories) {
            if (fact.objectDefined(clazz.getSimpleName())) {
                T object = fact.get(clazz, clazz.getSimpleName(), session);
                return object;
            }
        }
    } finally {
        readLock.unlock();
    }
    String msg = Messages.getInstance().getString("AbstractSpringPentahoObjectFactory.WARN_FAILED_TO_RETRIEVE_OBJECT", clazz.getSimpleName());
    throw new ObjectFactoryException(msg);
}
Also used : IPentahoObjectFactory(org.pentaho.platform.api.engine.IPentahoObjectFactory) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException)

Example 25 with IPentahoObjectFactory

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

the class BootTest method testBootActions.

@Test
public void testBootActions() throws Exception {
    PentahoSystemBoot boot = new PentahoSystemBoot();
    boot.setFilePath("src/test/resources/solution");
    boot.define(ISolutionEngine.class.getSimpleName(), Object1.class.getName(), IPentahoDefinableObjectFactory.Scope.GLOBAL);
    TestStartupAction startupAction1 = new TestStartupAction();
    TestStartupAction startupAction2 = new TestStartupAction();
    boot.addStartupAction(startupAction1);
    List<ISessionStartupAction> startupActions1 = boot.getStartupActions();
    assertEquals(1, startupActions1.size());
    assertEquals(startupAction1, startupActions1.get(0));
    List<ISessionStartupAction> startupActions2 = new ArrayList<ISessionStartupAction>();
    startupActions2.add(startupAction2);
    boot.setStartupActions(startupActions2);
    List<ISessionStartupAction> startupActions3 = boot.getStartupActions();
    assertEquals(1, startupActions3.size());
    assertEquals(startupAction2, startupActions3.get(0));
    assertEquals(startupActions2, startupActions3);
    IPentahoObjectFactory factory = boot.getFactory();
    assertNotNull("object factory is null", factory);
    assertTrue("object factory not definable", factory instanceof IPentahoDefinableObjectFactory);
    assertFalse(boot.isInitialized());
    boolean ok = boot.start();
    assertNull(boot.getSettingsProvider());
    assertTrue(boot.isInitialized());
    assertTrue(ok);
    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) ArrayList(java.util.ArrayList) ISessionStartupAction(org.pentaho.platform.api.engine.ISessionStartupAction) Test(org.junit.Test)

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