private void setObjectFactory(final ServletContext context) { final String SYSTEM_FOLDER = "/system"; // $NON-NLS-1$ String pentahoObjectFactoryClassName = getServerParameter("pentahoObjectFactory"); // $NON-NLS-1$ String pentahoObjectFactoryConfigFile = getServerParameter("pentahoObjectFactoryCfgFile"); // $NON-NLS-1$ // if web.xml doesnt specify a config file, use the default path. if (StringUtils.isEmpty(pentahoObjectFactoryConfigFile)) { pentahoObjectFactoryConfigFile = solutionPath + SYSTEM_FOLDER + "/" + DEFAULT_SPRING_CONFIG_FILE_NAME; // $NON-NLS-1$ } else if (-1 == pentahoObjectFactoryConfigFile.indexOf("/")) { // $NON-NLS-1$ pentahoObjectFactoryConfigFile = solutionPath + SYSTEM_FOLDER + "/" + pentahoObjectFactoryConfigFile; // $NON-NLS-1$ } // else objectFactoryCreatorCfgFile contains the full path. IPentahoObjectFactory pentahoObjectFactory; try { Class<?> classObject = Class.forName(pentahoObjectFactoryClassName); pentahoObjectFactory = (IPentahoObjectFactory) classObject.newInstance(); } catch (Exception e) { String msg = Messages.getInstance() .getErrorString( "SolutionContextListener.ERROR_0002_BAD_OBJECT_FACTORY", pentahoObjectFactoryClassName); //$NON-NLS-1$ // Cannot proceed without an object factory, so we'll put some context around what // we were trying to do throw a runtime exception throw new RuntimeException(msg, e); } pentahoObjectFactory.init(pentahoObjectFactoryConfigFile, context); PentahoSystem.registerPrimaryObjectFactory(pentahoObjectFactory); }
/** * @return the {@link IBackingRepositoryLifecycleManager} that this instance will use. If none has * been specified, it will default to getting the information from {@link PentahoSystem.get()} */ public ITenantManager getTenantManager() { // Check ... if we haven't been injected with a lifecycle manager, get one from PentahoSystem try { IPentahoObjectFactory objectFactory = PentahoSystem.getObjectFactory(); IPentahoSession pentahoSession = PentahoSessionHolder.getSession(); return (null != tenantManager ? tenantManager : objectFactory.get(ITenantManager.class, "tenantMgrProxy", pentahoSession)); } catch (ObjectFactoryException e) { return null; } }
@Before public void setUp() throws ConnectionServiceException, ObjectFactoryException, DBDatasourceServiceException { doReturn(nativeConnection).when(sqlConnection).getNativeConnection(); doReturn(SimpleDataAccessPermissionHandler.class.getName()) .when(loader) .getPluginSetting(this.anyClass(), anyString(), anyString()); when(pentahoObjectFactory.objectDefined(anyString())).thenReturn(true); when(pentahoObjectFactory.get(this.anyClass(), anyString(), any(IPentahoSession.class))) .thenAnswer( new Answer<Object>() { @Override public Object answer(InvocationOnMock invocation) throws Throwable { if (invocation.getArguments()[0].equals(IPluginResourceLoader.class)) { return loader; } if (invocation.getArguments()[0].equals(IPentahoConnection.class)) { return sqlConnection; } if (invocation.getArguments()[0].equals(IDBDatasourceService.class)) { return datasourceService; } if (invocation.getArguments()[0].equals(PooledDatasourceHelper.class)) { return pdh; } return null; } }); PentahoSystem.registerObjectFactory(pentahoObjectFactory); doReturn(databaseType).when(mockDBConnection).getDatabaseType(); doReturn(CONN_NAME).when(mockDBConnection).getName(); doNothing().when(mockDBConnection).setPassword(anyString()); connectionServiceImpl = spy(new ConnectionServiceImpl()); connectionServiceImpl.datasourceMgmtSvc = mock(IDatasourceMgmtService.class); connectionServiceImpl.dialectService = mock(DatabaseDialectService.class); connectionServiceImpl.datasourceService = datasourceService; }
public static synchronized void initializePentahoSystem(String solutionPath) throws Exception { // this setting is useful only for running the integration tests from within IntelliJ // this same property is set for integration tests via the pom when running with mvn String folderPaths = "target/spoon/plugins"; File f = new File(folderPaths); System.setProperty("KETTLE_PLUGIN_BASE_FOLDERS", f.getAbsolutePath()); StandaloneApplicationContext appContext = new StandaloneApplicationContext(solutionPath, ""); PentahoSystem.setSystemSettingsService(new PathBasedSystemSettings()); if (solutionPath == null) { throw new MetaverseException( Messages.getString("ERROR.MetaverseInit.BadConfigPath", solutionPath)); } try { ClassLoader cl = Thread.currentThread().getContextClassLoader(); Thread.currentThread().setContextClassLoader(MetaverseUtil.class.getClassLoader()); IPentahoObjectFactory pentahoObjectFactory = new StandaloneSpringPentahoObjectFactory(); pentahoObjectFactory.init(solutionPath, PentahoSystem.getApplicationContext()); PentahoSystem.registerObjectFactory(pentahoObjectFactory); // Restore context classloader Thread.currentThread().setContextClassLoader(cl); } catch (Exception e) { throw new MetaverseException(Messages.getString("ERROR.MetaverseInit.CouldNotInit"), e); } PentahoSystem.init(appContext); PentahoSessionHolder.setSession(new StandaloneSession()); registerKettlePlugins(); try { KettleEnvironment.init(); } catch (KettleException e) { e.printStackTrace(); } }