UserSettingService implements IAnyUserSettingService, IUserSettingService { public IUserSetting getGlobalUserSetting( String settingName, String defaultValue ) { String tentantHomePath = ClientRepositoryPaths.getEtcFolderPath(); Serializable tenantHomeId = repository.getFile( tentantHomePath ).getId(); Map<String, Serializable> tenantMetadata = repository.getFileMetadata( tenantHomeId ); String key = SETTING_PREFIX + settingName; Serializable value = tenantMetadata.get( key ); if ( value != null ) { return createSetting( settingName, value.toString() ); } return createSetting( settingName, defaultValue ); } 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 testGetGlobalUserSettingUnset() throws Exception { final String settingName = "settings"; final String defaultValue = "defaultValue"; final IUserSetting globalUserSetting = userSettingService.getGlobalUserSetting( settingName, defaultValue ); assertEquals( settingName, globalUserSetting.getSettingName() ); assertEquals( defaultValue, globalUserSetting.getSettingValue() ); }
@Test public void testGetGlobalUserSetting() throws Exception { final String settingName = GLOBAL_SETTING_NAME_3; final String defaultValue = "defaultValue"; final IUserSetting globalUserSetting = userSettingService.getGlobalUserSetting( settingName, defaultValue ); assertEquals( settingName, globalUserSetting.getSettingName() ); assertEquals( GLOBAL_SETTING_VALUE_3, globalUserSetting.getSettingValue() ); }