dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #43143
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21916: Renamed systemSetting *currentStyle* to *keyStyle* to follow convetions and to be equal to the us...
Merge authors:
Stian Sandvold (stian-sandvold)
------------------------------------------------------------
revno: 21916 [merge]
committer: Stian Sandvold <stian.sandvold@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2016-02-09 16:35:42 +0100
message:
Renamed systemSetting *currentStyle* to *keyStyle* to follow convetions and to be equal to the userSettingKey; Removed all default values for UserSettingKeys; SystemSetting now works as a fallback for userSettings, if no userSetting can be found(null); if no usersetting is found, the set systemsetting is used, or the system setting default;
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SettingKey.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingKey.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserSettingServiceTest.java
--
lp:dhis2
https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk
Your team DHIS 2 developers is subscribed to branch lp:dhis2.
To unsubscribe from this branch go to https://code.launchpad.net/~dhis2-devs-core/dhis2/trunk/+edit-subscription
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SettingKey.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SettingKey.java 2016-01-07 19:01:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SettingKey.java 2016-02-09 15:26:32 +0000
@@ -28,22 +28,32 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.apache.commons.lang3.LocaleUtils;
+import org.hisp.dhis.common.ListMap;
+import org.hisp.dhis.configuration.Configuration;
+import org.hisp.dhis.sms.config.SmsConfiguration;
+
import java.io.Serializable;
import java.util.Date;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
-import org.apache.commons.lang3.LocaleUtils;
-import org.hisp.dhis.common.ListMap;
-import org.hisp.dhis.configuration.Configuration;
-import org.hisp.dhis.sms.config.SmsConfiguration;
-
/**
* @author Lars Helge Overland
*/
public enum SettingKey
{
+ MESSAGE_EMAIL_NOTIFICATION( "keyMessageEmailNotification", Boolean.FALSE, Boolean.class ),
+ MESSAGE_SMS_NOTIFICATION( "keyMessageSmsNotification", Boolean.FALSE, Boolean.class ),
+ UI_LOCALE( "keyUiLocale", Locale.class ),
+ DB_LOCALE( "keyDbLocale", Locale.class ),
+ ANALYSIS_DISPLAY_PROPERTY( "keyAnalysisDisplayProperty", "name", String.class ),
+ CURRENT_DOMAIN_TYPE( "keyCurrentDomainType" ),
+ AUTO_SAVE_CASE_ENTRY_FORM( "keyAutoSaveCaseEntryForm", Boolean.FALSE, Boolean.class ),
+ AUTO_SAVE_TRACKED_ENTITY_REGISTRATION_ENTRY_FORM( "keyAutoSavetTrackedEntityForm", Boolean.FALSE, Boolean.class ),
+ AUTO_SAVE_DATA_ENTRY_FORM( "keyAutoSaveDataEntryForm", Boolean.FALSE, Boolean.class ),
+ TRACKER_DASHBOARD_LAYOUT( "keyTrackerDashboardLayout" ),
APPLICATION_TITLE( "applicationTitle", "DHIS 2", String.class ),
APPLICATION_INTRO( "keyApplicationIntro" ),
APPLICATION_NOTIFICATION( "keyApplicationNotification" ),
@@ -111,7 +121,7 @@
DATE_FORMAT( "keyDateFormat", "yyyy-MM-dd", String.class ),
APP_STORE_URL( "appStoreUrl", "https://www.dhis2.org/appstore", String.class ),
APP_STORE_INDEX_URL( "appStoreIndexUrl", "https://s3-eu-west-1.amazonaws.com/dhis2-appstore/appstore.json", String.class ),
- STYLE( "currentStyle", "light_blue/light_blue.css", String.class ),
+ STYLE( "keyStyle", "light_blue/light_blue.css", String.class ),
REMOTE_INSTANCE_URL( "keyRemoteInstanceUrl", "", String.class ),
REMOTE_INSTANCE_USERNAME( "keyRemoteInstanceUsername", "", String.class ),
REMOTE_INSTANCE_PASSWORD( "keyRemoteInstancePassword", "", String.class, true );
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingKey.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingKey.java 2016-01-12 13:06:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserSettingKey.java 2016-02-09 15:26:32 +0000
@@ -28,33 +28,31 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import org.apache.commons.lang3.LocaleUtils;
+
import java.io.Serializable;
import java.util.Locale;
import java.util.Optional;
-import org.apache.commons.lang3.LocaleUtils;
-
/**
* @author Lars Helge Overland
*/
public enum UserSettingKey
{
STYLE( "keyStyle" ),
- MESSAGE_EMAIL_NOTIFICATION( "keyMessageEmailNotification", Boolean.FALSE, Boolean.class ),
- MESSAGE_SMS_NOTIFICATION( "keyMessageSmsNotification", Boolean.FALSE, Boolean.class ),
+ MESSAGE_EMAIL_NOTIFICATION( "keyMessageEmailNotification", Boolean.class ),
+ MESSAGE_SMS_NOTIFICATION( "keyMessageSmsNotification", Boolean.class ),
UI_LOCALE( "keyUiLocale", Locale.class ),
DB_LOCALE( "keyDbLocale", Locale.class ),
- ANALYSIS_DISPLAY_PROPERTY( "keyAnalysisDisplayProperty", "name", String.class ),
+ ANALYSIS_DISPLAY_PROPERTY( "keyAnalysisDisplayProperty", String.class ),
CURRENT_DOMAIN_TYPE( "keyCurrentDomainType" ),
- AUTO_SAVE_CASE_ENTRY_FORM( "keyAutoSaveCaseEntryForm", Boolean.FALSE, Boolean.class ),
- AUTO_SAVE_TRACKED_ENTITY_REGISTRATION_ENTRY_FORM( "keyAutoSavetTrackedEntityForm", Boolean.FALSE, Boolean.class ),
- AUTO_SAVE_DATA_ENTRY_FORM( "keyAutoSaveDataEntryForm", Boolean.FALSE, Boolean.class ),
+ AUTO_SAVE_CASE_ENTRY_FORM( "keyAutoSaveCaseEntryForm", Boolean.class ),
+ AUTO_SAVE_TRACKED_ENTITY_REGISTRATION_ENTRY_FORM( "keyAutoSavetTrackedEntityForm", Boolean.class ),
+ AUTO_SAVE_DATA_ENTRY_FORM( "keyAutoSaveDataEntryForm", Boolean.class ),
TRACKER_DASHBOARD_LAYOUT( "keyTrackerDashboardLayout" );
private final String name;
- private final Serializable defaultValue;
-
private final Class<?> clazz;
// -------------------------------------------------------------------------
@@ -64,21 +62,12 @@
private UserSettingKey( String name )
{
this.name = name;
- this.defaultValue = null;
this.clazz = String.class;
}
private UserSettingKey( String name, Class<?> clazz )
{
this.name = name;
- this.defaultValue = null;
- this.clazz = clazz;
- }
-
- private UserSettingKey( String name, Serializable defaultValue, Class<?> clazz )
- {
- this.name = name;
- this.defaultValue = defaultValue;
this.clazz = clazz;
}
@@ -129,11 +118,6 @@
return value;
}
-
- public boolean hasDefaultValue()
- {
- return defaultValue != null;
- }
// -------------------------------------------------------------------------
// Getters
@@ -144,11 +128,6 @@
return name;
}
- public Serializable getDefaultValue()
- {
- return defaultValue;
- }
-
public Class<?> getClazz()
{
return clazz;
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java 2016-01-05 19:38:32 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserSettingService.java 2016-02-09 15:26:32 +0000
@@ -28,18 +28,23 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import com.google.common.cache.Cache;
+import com.google.common.cache.CacheBuilder;
+import com.google.common.collect.Sets;
+import org.hisp.dhis.common.DimensionalObject;
+import org.hisp.dhis.setting.SettingKey;
+import org.hisp.dhis.setting.SystemSettingManager;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.transaction.annotation.Transactional;
+
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
-
-import org.hisp.dhis.common.DimensionalObject;
-import org.springframework.transaction.annotation.Transactional;
-
-import com.google.common.cache.Cache;
-import com.google.common.cache.CacheBuilder;
+import java.util.stream.Collectors;
/**
* @author Torgeir Lorange Ostby
@@ -56,16 +61,27 @@
.initialCapacity( 200 )
.maximumSize( 10000 )
.build();
-
+
+ private static final Map<String, SettingKey> NAME_SETTING_KEY_MAP = Sets.newHashSet(
+ SettingKey.values() ).stream().collect( Collectors.toMap( SettingKey::getName, s -> s ) );
+
private String getCacheKey( String settingName, String username )
{
return settingName + DimensionalObject.ITEM_SEP + username;
}
-
+
// -------------------------------------------------------------------------
// Dependencies
// -------------------------------------------------------------------------
+ @Autowired
+ private SystemSettingManager systemSettingManager;
+
+ public void setSystemSettingManager( SystemSettingManager systemSettingManager )
+ {
+ this.systemSettingManager = systemSettingManager;
+ }
+
private CurrentUserService currentUserService;
public void setCurrentUserService( CurrentUserService currentUserService )
@@ -95,9 +111,9 @@
public void saveUserSetting( UserSettingKey key, Serializable value, String username )
{
UserCredentials credentials = userService.getUserCredentialsByUsername( username );
-
+
if ( credentials != null )
- {
+ {
saveUserSetting( key, value, credentials.getUserInfo() );
}
}
@@ -106,10 +122,10 @@
public void saveUserSetting( UserSettingKey key, Serializable value )
{
User currentUser = currentUserService.getCurrentUser();
-
+
saveUserSetting( key, value, currentUser );
}
-
+
@Override
public void saveUserSetting( UserSettingKey key, Serializable value, User user )
{
@@ -119,7 +135,7 @@
}
SETTING_CACHE.invalidate( getCacheKey( key.getName(), user.getUsername() ) );
-
+
UserSetting userSetting = userSettingStore.getUserSetting( user, key.getName() );
if ( userSetting == null )
@@ -140,10 +156,10 @@
public void deleteUserSetting( UserSetting userSetting )
{
SETTING_CACHE.invalidate( getCacheKey( userSetting.getName(), userSetting.getUser().getUsername() ) );
-
+
userSettingStore.deleteUserSetting( userSetting );
}
-
+
@Override
public void deleteUserSetting( UserSettingKey key )
{
@@ -152,19 +168,19 @@
if ( currentUser != null )
{
UserSetting setting = userSettingStore.getUserSetting( currentUser, key.getName() );
-
+
if ( setting != null )
{
deleteUserSetting( setting );
}
}
}
-
+
@Override
public void deleteUserSetting( UserSettingKey key, User user )
{
UserSetting setting = userSettingStore.getUserSetting( user, key.getName() );
-
+
if ( setting != null )
{
deleteUserSetting( setting );
@@ -189,14 +205,24 @@
{
return Optional.empty();
}
-
- String username = user.isPresent() ? user.get().getUsername() : currentUserService.getCurrentUsername();
try
{
+ String username = user.isPresent() ? user.get().getUsername() : currentUserService.getCurrentUsername();
String cacheKey = getCacheKey( key.getName(), username );
-
- return SETTING_CACHE.get( cacheKey, () -> getUserSettingOptional( key, username ) );
+ Optional<Serializable> result = SETTING_CACHE
+ .get( cacheKey, () -> getUserSettingOptional( key, username ) );
+
+ if ( !result.isPresent() && NAME_SETTING_KEY_MAP.containsKey( key.getName() ) )
+ {
+ return Optional
+ .ofNullable( systemSettingManager.getSystemSetting( NAME_SETTING_KEY_MAP.get( key.getName() ) ) );
+ }
+ else
+ {
+ return result;
+ }
+
}
catch ( ExecutionException ignored )
{
@@ -210,14 +236,16 @@
if ( userCredentials == null )
{
- return Optional.ofNullable( key.getDefaultValue() );
+ return Optional.empty();
}
-
+
UserSetting setting = userSettingStore.getUserSetting( userCredentials.getUserInfo(), key.getName() );
-
- return setting != null && setting.hasValue() ? Optional.of( setting.getValue() ) : Optional.ofNullable( key.getDefaultValue() );
+
+ return setting != null && setting.hasValue() ?
+ Optional.of( setting.getValue() ) :
+ Optional.empty();
}
-
+
@Override
public List<UserSetting> getAllUserSettings()
{
@@ -225,7 +253,7 @@
return getUserSettings( currentUser );
}
-
+
@Override
public List<UserSetting> getUserSettings( User user )
{
@@ -234,7 +262,15 @@
return new ArrayList<>();
}
- return userSettingStore.getAllUserSettings( user );
+ List<UserSetting> list = userSettingStore.getAllUserSettings( user );
+
+ return list.stream().map( userSetting -> {
+ if ( userSetting.getValue() == null )
+ return new UserSetting( userSetting.getUser(), userSetting.getName(),
+ systemSettingManager.getSystemSetting( NAME_SETTING_KEY_MAP.get( userSetting.getName() ) ) );
+ else
+ return userSetting;
+ } ).collect( Collectors.toList() );
}
@Override
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserSettingServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserSettingServiceTest.java 2016-01-04 02:27:49 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/user/UserSettingServiceTest.java 2016-02-09 15:26:32 +0000
@@ -29,6 +29,7 @@
*/
import org.hisp.dhis.DhisSpringTest;
+import org.hisp.dhis.setting.SettingKey;
import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
@@ -64,8 +65,8 @@
@Test
public void testSaveGetDeleteUserSetting()
{
- assertEquals( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY.getDefaultValue(), userSettingService.getUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, userA ) );
- assertEquals( UserSettingKey.STYLE.getDefaultValue(), userSettingService.getUserSetting( UserSettingKey.STYLE, userA ) );
+ assertEquals( SettingKey.ANALYSIS_DISPLAY_PROPERTY.getDefaultValue(), userSettingService.getUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, userA ) );
+ assertEquals( SettingKey.STYLE.getDefaultValue(), userSettingService.getUserSetting( UserSettingKey.STYLE, userA ) );
userSettingService.saveUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, "shortName", "usernameA" );
userSettingService.saveUserSetting( UserSettingKey.STYLE, "blue", "usernameA" );
@@ -75,13 +76,13 @@
userSettingService.deleteUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, userA );
- assertEquals( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY.getDefaultValue(), userSettingService.getUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, userA ) );
+ assertEquals( SettingKey.ANALYSIS_DISPLAY_PROPERTY.getDefaultValue(), userSettingService.getUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, userA ) );
assertEquals( "blue", userSettingService.getUserSetting( UserSettingKey.STYLE, userA ) );
userSettingService.deleteUserSetting( UserSettingKey.STYLE, userA );
- assertEquals( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY.getDefaultValue(), userSettingService.getUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, userA ) );
- assertEquals( UserSettingKey.STYLE.getDefaultValue(), userSettingService.getUserSetting( UserSettingKey.STYLE, userA ) );
+ assertEquals( SettingKey.ANALYSIS_DISPLAY_PROPERTY.getDefaultValue(), userSettingService.getUserSetting( UserSettingKey.ANALYSIS_DISPLAY_PROPERTY, userA ) );
+ assertEquals( SettingKey.STYLE.getDefaultValue(), userSettingService.getUserSetting( UserSettingKey.STYLE, userA ) );
}
@Test