MondrianCatalogHelper implements IAclAwareMondrianCatalogService { protected void loadCatalogsIntoCache( final DataSourcesConfig.DataSources dataSources, final IPentahoSession pentahoSession ) { ICacheManager cacheMgr = PentahoSystem.getCacheManager( pentahoSession ); if ( !cacheMgr.cacheEnabled( MONDRIAN_CATALOG_CACHE_REGION ) ) { cacheMgr.addCacheRegion( MONDRIAN_CATALOG_CACHE_REGION ); } Map<String, MondrianCatalog> catalogs = (Map<String, MondrianCatalog>) cacheMgr.getFromRegionCache( MONDRIAN_CATALOG_CACHE_REGION, getLocale() .toString() ); if ( catalogs == null ) { catalogs = new HashMap<String, MondrianCatalog>(); } else { return; } for ( DataSourcesConfig.DataSource dataSource : dataSources.dataSources ) { List<String> catalogNames = new ArrayList<String>(); for ( DataSourcesConfig.Catalog catalog : dataSource.catalogs.catalogs ) { catalogNames.add( catalog.name ); } for ( DataSourcesConfig.Catalog catalog : dataSource.catalogs.catalogs ) { if ( catalog.definition.startsWith( "mondrian:" ) || catalog.definition .startsWith( "solution:" ) ) { MondrianSchema schema = null; try { schema = makeSchema( getCatalogAsString( pentahoSession, catalog ) ); } catch ( Exception e ) { MondrianCatalogHelper.logger.error( Messages.getInstance().getErrorString( "MondrianCatalogHelper.ERROR_0013_FAILED_TO_LOAD_SCHEMA", catalog.definition ), e ); if ( e instanceof MondrianException ) { throw (MondrianException) e; } } MondrianCatalog mondrianCatalog = null; if ( schema == null ) { mondrianCatalog = new MondrianCatalog( catalog.name, catalog.dataSourceInfo, catalog.definition, schema ); } else { mondrianCatalog = new MondrianCatalog( useSchemaNameAsCatalogName ? schema.getName() : catalog.name, catalog.dataSourceInfo, catalog.definition, schema ); } catalogs.put( mondrianCatalog.getName(), mondrianCatalog ); catalogs.put( mondrianCatalog.getDefinition(), mondrianCatalog ); } else { MondrianCatalogHelper.logger.warn( Messages.getInstance().getString( "MondrianCatalogHelper.WARN_SKIPPING_DATASOURCE_DEF", catalog.definition ) ); } } } cacheMgr.putInRegionCache( MONDRIAN_CATALOG_CACHE_REGION, getLocale().toString(), catalogs ); } @VisibleForTesting @Deprecated  MondrianCatalogHelper( IAclNodeHelper aclHelper );  MondrianCatalogHelper();  MondrianCatalogHelper( boolean useLegacyDbName ); @Deprecated static MondrianCatalogHelper getInstance(); @Override synchronized void reInit( final IPentahoSession pentahoSession ); String generateInMemoryDatasourcesXml( IUnifiedRepository unifiedRepository ); synchronized String getDataSourcesConfig(); synchronized void setDataSourcesConfig( final String dataSourcesConfig ); @Override List<MondrianCatalog> listCatalogs( final IPentahoSession pentahoSession, final boolean jndiOnly ); @Override synchronized void addCatalog( final MondrianCatalog catalog, final boolean overwrite,
                                       final IPentahoSession pentahoSession ); @Override void addCatalog( InputStream inputStream, MondrianCatalog catalog, boolean overwriteInRepossitory,
                          IPentahoSession session ); @Override synchronized void addCatalog( InputStream schemaInputStream, final MondrianCatalog catalog,
                                       final boolean overwrite, RepositoryFileAcl acl,
                                       final IPentahoSession pentahoSession ); synchronized void setAclHelper( IAclNodeHelper helper ); @Override void setAclFor( String catalogName, RepositoryFileAcl acl ); @Override RepositoryFileAcl getAclFor( String catalogName ); void importSchema( File mondrianFile, String databaseConnection, String parameters ); @Override MondrianCatalog getCatalog( final String context, final IPentahoSession pentahoSession ); MondrianCatalogComplementInfo getCatalogComplementInfoMap( String name ); @Override MondrianSchema loadMondrianSchema( final String solutionLocation, final IPentahoSession pentahoSession ); boolean isUseSchemaNameAsCatalogName(); void setUseSchemaNameAsCatalogName( final boolean useSchemaNameAsCatalogName ); static int addToCatalog( String baseUrl, boolean enableXmla, String schemaSolutionPath,
                                  IPentahoSession session, String jndiName, boolean overwrite ); @Override void removeCatalog( final String catalogName, final IPentahoSession pentahoSession ); static final String MONDRIAN_DATASOURCE_FOLDER; static String MONDRIAN_CATALOG_CACHE_REGION; }
@Test public void testLoadCatalogsIntoCache() { DataSourcesConfig.DataSources dsList = new DataSourcesConfig.DataSources(); dsList.dataSources = new DataSource[1]; DataSource ds = new DataSource(); dsList.dataSources[0] = ds; ds.catalogs = new Catalogs(); ds.catalogs.catalogs = new Catalog[1]; Catalog ct = new Catalog(); ct.definition = DEFINITION; ds.catalogs.catalogs[0] = ct; MockUp<ICacheManager> cmMock = new MockUp<ICacheManager>() { Object cacheValue; @Mock public boolean cacheEnabled( String s ) { return true; } @Mock public Object getFromRegionCache( String s, Object obj ) { return cacheValue; } @Mock public void putInRegionCache( String s, Object obj, Object obj1 ) { cacheValue = obj1; } }; final ICacheManager cm = cmMock.getMockInstance(); new NonStrictExpectations( PentahoSystem.class ) { { PentahoSystem.getCacheManager( null ); result = cm; } }; mch.loadCatalogsIntoCache( dsList, null ); Object cacheValue = cm.getFromRegionCache( null, null ); Assert.assertTrue( Map.class.isInstance( cacheValue ) ); Map<?, ?> map = (Map<?, ?>) cacheValue; for ( Object item : map.values() ) { Assert.assertTrue( MondrianCatalog.class.isInstance( item ) ); MondrianCatalog catalog = (MondrianCatalog) item; Assert.assertEquals( DEFINITION, catalog.getDefinition() ); } }