← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 20854: CalendarService. Removed key cache. Caused stale data now that system setting manager has a cache.

 

------------------------------------------------------------
revno: 20854
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-10-23 00:26:41 +0200
message:
  CalendarService. Removed key cache. Caused stale data now that system setting manager has a cache.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/CalendarService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/DefaultCalendarService.java
  dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.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/calendar/CalendarService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/CalendarService.java	2015-10-06 22:23:53 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/CalendarService.java	2015-10-22 22:26:41 +0000
@@ -61,28 +61,4 @@
      * @see DateFormat
      */
     DateFormat getSystemDateFormat();
-    
-    /**
-     * Gets the system calendar key.
-     * @return the system calendar key
-     */
-    String getSystemCalendarKey();
-    
-    /**
-     * Sets the system calendar key.
-     * @param calendarKey the system calendar key
-     */
-    void setSystemCalendarKey( String calendarKey );
-    
-    /**
-     * Gets the system date format key.
-     * @return the system date format key
-     */
-    String getSystemDateFormatKey();
-    
-    /**
-     * Sets the system date format key.
-     * @param dateFormatKey the system date format key
-     */
-    void setSystemDateFormatKey( String dateFormatKey );
 }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/DefaultCalendarService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/DefaultCalendarService.java	2015-10-06 22:23:53 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/DefaultCalendarService.java	2015-10-22 22:26:41 +0000
@@ -28,10 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.apache.commons.lang3.StringUtils.isEmpty;
-
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -68,11 +65,6 @@
         new DateFormat( "dd-MM-yyyy", "dd-MM-yyyy", "dd-MM-yyyy", "dd-mm-yyyy" )
     );
 
-    /**
-     * Memory cache for calendar and date format keys.
-     */
-    private final Map<String, String> keyCache = new HashMap<>();
-
     // -------------------------------------------------------------------------
     // CalendarService implementation
     // -------------------------------------------------------------------------
@@ -107,8 +99,8 @@
     @Override
     public Calendar getSystemCalendar()
     {
-        String calendarKey = getSystemCalendarKey();
-        String dateFormat = getSystemDateFormatKey();
+        String calendarKey = (String) settingManager.getSystemSetting( Setting.CALENDAR );
+        String dateFormat = (String) settingManager.getSystemSetting( Setting.DATE_FORMAT );
 
         Calendar calendar = null;
 
@@ -129,7 +121,7 @@
     @Override
     public DateFormat getSystemDateFormat()
     {
-        String dateFormatKey = getSystemDateFormatKey();
+        String dateFormatKey = (String) settingManager.getSystemSetting( Setting.DATE_FORMAT );
 
         for ( DateFormat dateFormat : dateFormats )
         {
@@ -141,40 +133,4 @@
 
         return dateFormats.get( 0 );
     }
-
-    // -------------------------------------------------------------------------
-    // Calendar key
-    // -------------------------------------------------------------------------
-
-    @Override
-    public String getSystemCalendarKey()
-    {
-        String key = keyCache.get( Setting.CALENDAR.getName() );        
-        key = !isEmpty( key ) ? key : (String) settingManager.getSystemSetting( Setting.CALENDAR );        
-        keyCache.put( Setting.CALENDAR.getName(), key );        
-        return key;
-    }
-    
-    @Override
-    public void setSystemCalendarKey( String calendarKey )
-    {
-        keyCache.put( Setting.CALENDAR.getName(), calendarKey );
-        settingManager.saveSystemSetting( Setting.CALENDAR.getName(), calendarKey );
-    }
-    
-    @Override
-    public String getSystemDateFormatKey()
-    {
-        String key = keyCache.get( Setting.DATE_FORMAT.getName() );
-        key = !isEmpty( key ) ? key : (String) settingManager.getSystemSetting( Setting.DATE_FORMAT );
-        keyCache.put( Setting.DATE_FORMAT.getName(), key );
-        return key;
-    }
-
-    @Override
-    public void setSystemDateFormatKey( String dateFormatKey )
-    {
-        keyCache.put( Setting.DATE_FORMAT.getName(), dateFormatKey );
-        settingManager.saveSystemSetting( Setting.DATE_FORMAT.getName(), dateFormatKey );
-    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java	2015-10-15 16:58:04 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/interceptor/SystemSettingInterceptor.java	2015-10-22 22:26:41 +0000
@@ -57,7 +57,8 @@
         Setting.APPLICATION_NOTIFICATION, Setting.APPLICATION_FOOTER, Setting.APPLICATION_RIGHT_FOOTER,
         Setting.FLAG, Setting.START_MODULE, Setting.MULTI_ORGANISATION_UNIT_FORMS, Setting.ACCOUNT_RECOVERY,
         Setting.APP_BASE_URL, Setting.INSTANCE_BASE_URL, Setting.GOOGLE_ANALYTICS_UA, Setting.OPENID_PROVIDER,
-        Setting.OPENID_PROVIDER_LABEL, Setting.HELP_PAGE_LINK, Setting.REQUIRE_ADD_TO_VIEW, Setting.ALLOW_OBJECT_ASSIGNMENT );
+        Setting.OPENID_PROVIDER_LABEL, Setting.HELP_PAGE_LINK, Setting.REQUIRE_ADD_TO_VIEW, Setting.ALLOW_OBJECT_ASSIGNMENT,
+        Setting.CALENDAR, Setting.DATE_FORMAT );
     
     // -------------------------------------------------------------------------
     // Dependencies
@@ -99,9 +100,7 @@
         throws Exception
     {
         Map<String, Object> map = new HashMap<>();
-
-        map.put( Setting.CALENDAR.getName(), calendarService.getSystemCalendarKey() );
-        map.put( Setting.DATE_FORMAT.getName(), calendarService.getSystemDateFormatKey() );        
+        
         map.put( DATE_FORMAT, calendarService.getSystemDateFormat() );
         map.put( Setting.CONFIGURATION.getName(), configurationService.getConfiguration() );
         map.put( Setting.FLAG_IMAGE.getName(), systemSettingManager.getFlagImage() );