UserSettingService implements IAnyUserSettingService, IUserSettingService { public void setUserSetting( String settingName, String settingValue ) { String name = PentahoSessionHolder.getSession().getName(); String homePath = ClientRepositoryPaths.getUserHomeFolderPath( name ); synchronized ( lock ) { final Serializable id = repository.getFile( homePath ).getId(); final Map<String, Serializable> fileMetadata = repository.getFileMetadata( id ); fileMetadata.put( SETTING_PREFIX + settingName, settingValue ); try { SecurityHelper.getInstance().runAsSystem( new Callable<Void>() { @Override public Void call() throws Exception { repository.setFileMetadata( id, fileMetadata ); return null; } } ); } catch ( Exception e ) { if ( log.isDebugEnabled() ) { log.debug( "Error storing user setting for user: " + name + ", setting: " + settingName + ", value: " + settingValue, e ); } log.error( "Error storing user setting", e ); } } } 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 testSetUserSettingByName() throws Exception { final String settingName = "settingName"; final String settingValue = "settingValue"; IAuthorizationPolicy policy = mock( IAuthorizationPolicy.class ); when( policy.isAllowed( anyString() ) ).thenReturn( true ); PentahoSystem.registerObject( policy ); assertEquals( 4, userSettings.size() ); userSettingService.setUserSetting( "test", settingName, settingValue ); assertEquals( 5, userSettings.size() ); final Serializable value = userSettings.get( UserSettingService.SETTING_PREFIX + settingName ); assertEquals( settingValue, value ); verify( repository ).setFileMetadata( eq( USER_FOLDER_ID ), anyMap() ); }
@Test public void testSetUserSetting() throws Exception { final String settingName = "settingName"; final String settingValue = "settingValue"; assertEquals( 4, userSettings.size() ); userSettingService.setUserSetting( settingName, settingValue ); assertEquals( 5, userSettings.size() ); final Serializable value = userSettings.get( UserSettingService.SETTING_PREFIX + settingName ); assertEquals( settingValue, value ); verify( repository ).setFileMetadata( eq( USER_FOLDER_ID ), anyMap() ); }