UserSettingService implements IAnyUserSettingService, IUserSettingService { public List<IUserSetting> getGlobalUserSettings() { String tentantHomePath = ClientRepositoryPaths.getEtcFolderPath(); Serializable tenantHomeId = repository.getFile( tentantHomePath ).getId(); Map<String, Serializable> tenantMetadata = repository.getFileMetadata( tenantHomeId ); List<IUserSetting> userSettings = new ArrayList<IUserSetting>( tenantMetadata.size() ); for ( Map.Entry<String, Serializable> entry : tenantMetadata.entrySet() ) { String key = entry.getKey(); if ( key.startsWith( SETTING_PREFIX ) ) { userSettings.add( createSetting( key.substring( SETTING_PREFIX.length() ), entry.getValue() ) ); } } return userSettings; } UserSettingService( IUnifiedRepository repository ); void init( IPentahoSession session ); void deleteUserSettings(); List<IUserSetting> getUserSettings(); IUserSetting getUserSetting( String settingName, String defaultValue ); void setUserSetting( String settingName, String settingValue ); @Override void deleteUserSettings( String username ); @Override List<IUserSetting> getUserSettings( String username ); @Override IUserSetting getUserSetting( String username, String settingName, String defaultValue ); @Override void setUserSetting( String username, String settingName, String settingValue ); IUserSetting getGlobalUserSetting( String settingName, String defaultValue ); List<IUserSetting> getGlobalUserSettings(); void setGlobalUserSetting( String settingName, String settingValue ); static final String SETTING_PREFIX; }
@Test public void testGetGlobalUserSettings() throws Exception { final List<IUserSetting> globalUserSettings = userSettingService.getGlobalUserSettings(); assertNotNull( globalUserSettings ); assertEquals( 2, globalUserSettings.size() ); label : for ( IUserSetting setting : globalUserSettings ) { for ( String key : globalSettings.keySet() ) { if ( key.startsWith( UserSettingService.SETTING_PREFIX ) && key.substring( UserSettingService.SETTING_PREFIX.length() ).equals( setting.getSettingName() ) ) { assertEquals( globalSettings.get( key ), setting.getSettingValue() ); continue label; } } fail( "wrong setting" ); } }