← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15083: made dateFormat handling for calendar a bit more flexible

 

------------------------------------------------------------
revno: 15083
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-04-29 13:13:26 +0545
message:
  made dateFormat handling for calendar a bit more flexible
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/AbstractCalendar.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/CalendarService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/DefaultCalendarService.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetGeneralSettingsAction.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/AbstractCalendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/AbstractCalendar.java	2014-04-29 05:05:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/AbstractCalendar.java	2014-04-29 07:28:26 +0000
@@ -90,16 +90,23 @@
 
     protected static final String DEFAULT_ISO8601_DATE_FORMAT = "yyyy-MM-dd";
 
+    protected String dateFormat = DEFAULT_ISO8601_DATE_FORMAT;
+
     @Override
-    public String defaultDateFormat()
-    {
-        return DEFAULT_ISO8601_DATE_FORMAT;
+    public String getDateFormat()
+    {
+        return dateFormat;
+    }
+
+    public void setDateFormat( String dateFormat )
+    {
+        this.dateFormat = dateFormat;
     }
 
     @Override
     public String formattedDate( DateUnit dateUnit )
     {
-        return defaultDateFormat()
+        return getDateFormat()
             .replace( "yyyy", String.format( "%04d", dateUnit.getYear() ) )
             .replace( "MM", String.format( "%02d", dateUnit.getMonth() ) )
             .replace( "dd", String.format( "%02d", dateUnit.getDay() ) );
@@ -110,7 +117,7 @@
     {
         dateUnit = toIso( dateUnit );
         DateTime dateTime = dateUnit.toDateTime();
-        DateTimeFormatter format = DateTimeFormat.forPattern( defaultDateFormat() );
+        DateTimeFormatter format = DateTimeFormat.forPattern( getDateFormat() );
 
         return format.print( dateTime );
     }
@@ -124,7 +131,7 @@
     @Override
     public DateUnit toIso( String date )
     {
-        DateTimeFormatter format = DateTimeFormat.forPattern( defaultDateFormat() );
+        DateTimeFormatter format = DateTimeFormat.forPattern( getDateFormat() );
         DateTime dateTime = format.parseDateTime( date );
 
         return toIso( DateUnit.fromDateTime( dateTime ) );

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java	2014-04-29 05:05:54 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/Calendar.java	2014-04-29 07:28:26 +0000
@@ -44,24 +44,30 @@
     String name();
 
     /**
-     * Default date format for this calendar
+     * Date format for this calendar
      * @return Default date format
      */
-    String defaultDateFormat();
-
-    /**
-     * Formats dateUnit using defaultDateFormat
+    String getDateFormat();
+
+    /**
+     * Set date format for this calendar
+     * @param dateFormat Date format to use for this calendar
+     */
+    void setDateFormat( String dateFormat );
+
+    /**
+     * Formats dateUnit using dateFormat
      * @param dateUnit DateUnit representing local year, month, day
      * @return Default date format
-     * @see #defaultDateFormat()
+     * @see #getDateFormat()
      */
     String formattedDate( DateUnit dateUnit );
 
     /**
-     * Formats dateUnit using defaultDateFormat and ISO 8601
+     * Formats dateUnit using dateFormat and ISO 8601
      * @param dateUnit DateUnit representing local year, month, day
      * @return Default date format
-     * @see #defaultDateFormat()
+     * @see #getDateFormat()
      */
     String formattedIsoDate( DateUnit dateUnit );
 
@@ -77,11 +83,11 @@
 
     /**
      * Convert local calendar to an ISO 8601 DateUnit.
-     * @param date  Date formatted using default date format
+     * @param date Date formatted using default date format
      * @return DateUnit representing local date in ISO 8601
      * @see <a href="http://en.wikipedia.org/wiki/ISO_8601";>http://en.wikipedia.org/wiki/ISO_8601</a>
      */
-    DateUnit toIso( String date);
+    DateUnit toIso( String date );
 
     /**
      * Convert local calendar to an ISO 8601 DateUnit.

=== 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	2014-04-26 06:29:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/CalendarService.java	2014-04-29 07:28:26 +0000
@@ -41,7 +41,7 @@
      * Gets all available calendars as a sorted list.
      * @return All available calendars
      */
-    List<Calendar> getAll();
+    List<Calendar> getAllCalendars();
 
     /**
      * Gets the currently selected system calendar.

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java	2014-04-27 09:26:20 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/calendar/impl/NepaliCalendar.java	2014-04-29 07:28:26 +0000
@@ -51,8 +51,6 @@
 
     private static final DateUnit startIso = new DateUnit( 1943, 4, 14, java.util.Calendar.WEDNESDAY );
 
-    private static final String DEFAULT_NEPALI_DATE_FORMAT = "dd-MM-yyyy";
-
     private static final Calendar self = new NepaliCalendar();
 
     public static Calendar getInstance()
@@ -67,12 +65,6 @@
     }
 
     @Override
-    public String defaultDateFormat()
-    {
-        return DEFAULT_NEPALI_DATE_FORMAT;
-    }
-
-    @Override
     public DateUnit toIso( DateUnit dateUnit )
     {
         DateTime dateTime = startIso.toDateTime();

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java	2014-04-25 12:25:39 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/setting/SystemSettingManager.java	2014-04-29 07:28:26 +0000
@@ -50,6 +50,7 @@
     final String KEY_APPLICATION_NOTIFICATION = "keyApplicationNotification";
     final String KEY_APPLICATION_FOOTER = "keyApplicationFooter";
     final String KEY_CALENDAR = "keyCalendar";
+    final String KEY_DATE_FORMAT = "keyDateFormat";
     final String KEY_FLAG = "keyFlag";
     final String KEY_FLAG_IMAGE = "keyFlagImage";
     final String KEY_START_MODULE = "startModule";
@@ -93,6 +94,7 @@
     final String DEFAULT_SCHEDULE_AGGREGATE_QUERY_BUILDER_TASK_STRATEGY = "lastMonth";
     final String DEFAULT_FLAG = "dhis2";
     final String DEFAULT_CALENDAR = "iso8601";
+    final String DEFAULT_DATE_FORMAT = "yyyy-MM-dd"; // ISO 8601
     final int DEFAULT_MAX_NUMBER_OF_ATTEMPTS = 20;
     final int DEFAULT_TIMEFRAME_MINUTES = 1;
     final double DEFAULT_FACTOR_OF_DEVIATION = 2.0;

=== 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	2014-04-26 08:46:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/calendar/DefaultCalendarService.java	2014-04-29 07:28:26 +0000
@@ -64,7 +64,7 @@
     }
 
     @Override
-    public List<Calendar> getAll()
+    public List<Calendar> getAllCalendars()
     {
         List<Calendar> sortedCalendars = Lists.newArrayList( calendarMap.values() );
         Collections.sort( sortedCalendars, CalendarComparator.INSTANCE );
@@ -74,13 +74,22 @@
     @Override
     public Calendar getSystemCalendar()
     {
-        String calendar = (String) settingManager.getSystemSetting( SystemSettingManager.KEY_CALENDAR, SystemSettingManager.DEFAULT_CALENDAR );
-
-        if ( calendarMap.containsKey( calendar ) )
-        {
-            return calendarMap.get( calendar );
-        }
-
-        return Iso8601Calendar.getInstance();
+        String calendarKey = (String) settingManager.getSystemSetting( SystemSettingManager.KEY_CALENDAR, SystemSettingManager.DEFAULT_CALENDAR );
+        String dateFormat = (String) settingManager.getSystemSetting( SystemSettingManager.KEY_DATE_FORMAT, SystemSettingManager.DEFAULT_DATE_FORMAT );
+
+        Calendar calendar;
+
+        if ( calendarMap.containsKey( calendarKey ) )
+        {
+            calendar = calendarMap.get( calendarKey );
+        }
+        else
+        {
+            calendar = Iso8601Calendar.getInstance();
+        }
+
+        calendar.setDateFormat( dateFormat );
+
+        return calendar;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetGeneralSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetGeneralSettingsAction.java	2014-04-25 13:14:41 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-settings/src/main/java/org/hisp/dhis/settings/action/system/GetGeneralSettingsAction.java	2014-04-29 07:28:26 +0000
@@ -28,12 +28,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.google.common.collect.Lists;
-import com.google.common.collect.Sets;
 import com.opensymphony.xwork2.Action;
-import org.hisp.dhis.calendar.AbstractCalendar;
 import org.hisp.dhis.calendar.Calendar;
-import org.hisp.dhis.calendar.CalendarComparator;
 import org.hisp.dhis.calendar.CalendarService;
 import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.configuration.Configuration;
@@ -54,7 +50,6 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.List;
-import java.util.Set;
 
 /**
  * @author Lars Helge Overland
@@ -172,7 +167,7 @@
 
     public List<Calendar> getCalendars()
     {
-        return calendarService.getAll();
+        return calendarService.getAllCalendars();
     }
 
     // -------------------------------------------------------------------------