UserSettingService implements IAnyUserSettingService, IUserSettingService { public List<IUserSetting> getUserSettings() { List<IUserSetting> userSettings = new ArrayList<IUserSetting>(); String tentantHomePath = ClientRepositoryPaths.getEtcFolderPath(); Serializable tenantHomeId = repository.getFile( tentantHomePath ).getId(); Map<String, Serializable> tenantMetadata = repository.getFileMetadata( tenantHomeId ); for ( Map.Entry<String, Serializable> entry : tenantMetadata.entrySet() ) { String key = entry.getKey(); if ( key.startsWith( SETTING_PREFIX ) ) { UserSetting setting = createSetting( key.substring( SETTING_PREFIX.length() ), entry.getValue() ); userSettings.add( setting ); } } String homePath = ClientRepositoryPaths.getUserHomeFolderPath( PentahoSessionHolder.getSession().getName() ); Serializable userHomeId = repository.getFile( homePath ).getId(); Map<String, Serializable> userMetadata = repository.getFileMetadata( userHomeId ); for ( Map.Entry<String, Serializable> entry : userMetadata.entrySet() ) { String key = entry.getKey(); if ( key.startsWith( SETTING_PREFIX ) ) { UserSetting setting = createSetting( key.substring( SETTING_PREFIX.length() ), entry.getValue() ); if ( userSettings.contains( setting ) ) { userSettings.remove( setting ); } userSettings.add( setting ); } } 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 testGetUserSettingsByName() throws Exception { try { ( (UserSettingServiceForTesting) userSettingService ).setCanAdministerOverrideValue( true ); final List<IUserSetting> settings = userSettingService.getUserSettings( "test" ); assertNotNull( settings ); assertEquals( 2, settings.size() ); for ( IUserSetting setting : settings ) { if ( COMMON_SETTING_NAME.equals( setting.getSettingName() ) ) { assertEquals( COMMON_USER_SETTING_VALUE, setting.getSettingValue() ); } else if ( USER_SETTING_NAME_3.equals( setting.getSettingName() ) ) { assertEquals( USER_SETTING_VALUE_3, setting.getSettingValue() ); } else if ( GLOBAL_SETTING_NAME_3.equals( setting.getSettingName() ) ) { assertEquals( GLOBAL_SETTING_VALUE_3, setting.getSettingValue() ); } } } finally { ( (UserSettingServiceForTesting) userSettingService ).setCanAdministerOverrideValue( null ); } }
@Test public void testGetUserSettings() throws Exception { final List<IUserSetting> settings = userSettingService.getUserSettings(); assertNotNull( settings ); assertEquals( 3, settings.size() ); for ( IUserSetting setting : settings ) { if ( COMMON_SETTING_NAME.equals( setting.getSettingName() ) ) { assertEquals( COMMON_USER_SETTING_VALUE, setting.getSettingValue() ); } else if ( USER_SETTING_NAME_3.equals( setting.getSettingName() ) ) { assertEquals( USER_SETTING_VALUE_3, setting.getSettingValue() ); } else if ( GLOBAL_SETTING_NAME_3.equals( setting.getSettingName() ) ) { assertEquals( GLOBAL_SETTING_VALUE_3, setting.getSettingValue() ); } } }