← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1774: Fixed bug <354365> try to do once more time

 

------------------------------------------------------------
revno: 1774
committer: hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Tue 2010-04-13 13:00:13 +0700
message:
  Fixed bug <354365> try to do once more time
modified:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/SearchAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataBrowserResult.vm


--
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-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java	2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/DateUtils.java	2010-04-13 06:00:13 +0000
@@ -33,6 +33,11 @@
 import java.util.Date;
 
 import org.apache.commons.validator.DateValidator;
+import org.hisp.dhis.i18n.I18nFormat;
+import org.hisp.dhis.period.CalendarPeriodType;
+import org.hisp.dhis.period.MonthlyPeriodType;
+import org.hisp.dhis.period.PeriodService;
+import org.hisp.dhis.period.PeriodType;
 import org.joda.time.DateTime;
 import org.joda.time.Days;
 
@@ -61,7 +66,7 @@
 
         return date != null ? format.format( date ) : null;
     }
-    
+
     /**
      * Formats a Date to the IXF date format which is YYYY-MM-DD'T'HH:MM:SS.
      * 
@@ -155,8 +160,8 @@
      * @param baseDate the date used as base for the test.
      * @param startDate the start date.
      * @param endDate the end date.
-     * @return <code>true</code> if the base date is between the start date and
-     *         end date, <code>false</code> otherwise.
+     * @return <code>true</code> if the base date is between the start date
+     *         and end date, <code>false</code> otherwise.
      */
     public static boolean between( Date baseDate, Date startDate, Date endDate )
     {
@@ -181,8 +186,8 @@
      * @param baseDate the date used as base for the test.
      * @param startDate the start date.
      * @param endDate the end date.
-     * @return <code>true</code> if the base date is between the start date and
-     *         end date, <code>false</code> otherwise.
+     * @return <code>true</code> if the base date is between the start date
+     *         and end date, <code>false</code> otherwise.
      */
     public static boolean strictlyBetween( Date baseDate, Date startDate, Date endDate )
     {
@@ -351,6 +356,38 @@
     }
 
     /**
+     * This method converts a string from the date format "yyyy-MM-dd" to "MMMM
+     * yyyy". Default is Monthly period type.
+     * 
+     * @param date is the string to be converted.
+     * @param periodService service of period
+     * @param format is i18n format object
+     * @return converted string if the date is valid, else the original string
+     *         is returned
+     */
+    public static String convertDate( PeriodService periodService, String dateString, I18nFormat format )
+    {
+        if ( !dateIsValid( dateString ) )
+        {
+            return dateString;
+        }
+
+        SimpleDateFormat dateFormat = new SimpleDateFormat( DEFAULT_DATE_FORMAT );
+
+        try
+        {
+            Date date = dateFormat.parse( dateString );
+            CalendarPeriodType calendarPeriodType = (CalendarPeriodType) getMonthlyPeriodType( periodService );
+
+            return format.formatPeriod( calendarPeriodType.createPeriod( date ) );
+        }
+        catch ( ParseException pe )
+        {
+            throw new RuntimeException( "Date string could not be parsed: " + dateString );
+        }
+    }
+
+    /**
      * This method adds days to a date
      * 
      * @param date the date.
@@ -365,4 +402,51 @@
 
         return cal.getTime();
     }
+
+    /**
+     * This is a helper method for checking if the fromDate is later than the
+     * toDate. This is necessary in case a user sends the dates with HTTP GET.
+     * 
+     * @param fromDate
+     * @param toDate
+     * @return boolean
+     */
+    private boolean checkDates( String fromDate, String toDate )
+    {
+        String formatString = DateUtils.DEFAULT_DATE_FORMAT;
+        SimpleDateFormat sdf = new SimpleDateFormat( formatString );
+
+        Date date1 = new Date();
+        Date date2 = new Date();
+
+        try
+        {
+            date1 = sdf.parse( fromDate );
+            date2 = sdf.parse( toDate );
+        }
+        catch ( ParseException e )
+        {
+            return false; // The user hasn't specified any dates
+        }
+
+        if ( !date1.before( date2 ) )
+        {
+            return true; // Return true if date2 is earlier than date1
+        }
+        else
+        {
+            return false;
+        }
+    }
+
+    /**
+     * This method returns monthly period type is default
+     * 
+     * @param periodService service of period persistent object
+     */
+    public static final PeriodType getMonthlyPeriodType( PeriodService periodService )
+    {
+        return periodService.getPeriodTypeByName( MonthlyPeriodType.NAME );
+    }
+
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/SearchAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/SearchAction.java	2010-04-03 09:35:43 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/SearchAction.java	2010-04-13 06:00:13 +0000
@@ -52,6 +52,7 @@
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.period.comparator.AscendingPeriodComparator;
 import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.util.SessionUtils;
 
@@ -62,6 +63,8 @@
 /**
  * @author espenjac, joakibj, briane, eivinhb
  * @version $Id$
+ * @modifier Dang Duy Hieu
+ * @since 2010-04-06
  */
 public class SearchAction
     implements Action
@@ -78,7 +81,9 @@
 
     private static final String KEY_DATABROWSERTABLE = "dataBrowserTableResults";
 
-    private static final String HYPHEN = " - ";
+    private static final String SPACE = " ";
+
+    private static final String DASH = " - ";
 
     // -------------------------------------------------------------------------
     // Dependencies
@@ -410,7 +415,7 @@
         // date
         if ( fromDate.length() == 0 && toDate.length() == 0 )
         {
-            if ( checkDates( fromDate, toDate ) )
+            if ( DateUtils.checkDates( fromDate, toDate ) )
             {
                 return ERROR;
             }
@@ -462,7 +467,6 @@
             }
             else
             {
-
                 dataBrowserTable = dataBrowserService.getDataElementGroupsInPeriod( fromDate, toDate, periodType );
             }
         }
@@ -503,7 +507,8 @@
         // Set DataBrowserTable variable for PDF export
         setExportPDFVariables();
 
-        // Get format standard for periods which appropriate with from date, to date and period type
+        // Get format standard for periods which appropriate with from date, to
+        // date and period type
         fromToDate = getFromToDateFormat( periodType, fromDate, toDate );
 
         if ( fromToDate == null )
@@ -519,42 +524,6 @@
     // -------------------------------------------------------------------------
 
     /**
-     * This is a helper method for checking if the fromDate is later than the
-     * toDate. This is necessary in case a user sends the dates with HTTP GET.
-     * 
-     * @param fromDate
-     * @param toDate
-     * @return boolean
-     */
-    private boolean checkDates( String fromDate, String toDate )
-    {
-        String formatString = "yyyy-MM-dd";
-        SimpleDateFormat sdf = new SimpleDateFormat( formatString );
-
-        Date date1 = new Date();
-        Date date2 = new Date();
-
-        try
-        {
-            date1 = sdf.parse( fromDate );
-            date2 = sdf.parse( toDate );
-        }
-        catch ( ParseException e )
-        {
-            return false; // The user hasn't specified any dates
-        }
-
-        if ( !date1.before( date2 ) )
-        {
-            return true; // Return true if date2 is earlier than date1
-        }
-        else
-        {
-            return false;
-        }
-    }
-
-    /**
      * This is a helper method for setting session variables for PDF export
      */
     private void setExportPDFVariables()
@@ -577,7 +546,7 @@
 
         for ( MetaValue col : allColumnsConverted )
         {
-            col.setName( DateUtils.convertDate( col.getName() ) );
+            col.setName( DateUtils.convertDate( periodService, col.getName(), format ) );
         }
     }
 
@@ -591,7 +560,7 @@
      */
     private List<Period> getPeriodsList( PeriodType periodType, String fromDate, String toDate )
     {
-        String formatString = "yyyy-MM-dd";
+        String formatString = DateUtils.DEFAULT_DATE_FORMAT;
         SimpleDateFormat sdf = new SimpleDateFormat( formatString );
 
         Date date1 = new Date();
@@ -613,6 +582,8 @@
                 periods.add( calendarPeriodType.createPeriod( date2 ) );
             }
 
+            Collections.sort( periods, new AscendingPeriodComparator() );
+
             return periods;
         }
         catch ( ParseException e )
@@ -630,10 +601,14 @@
         for ( Period period : periods )
         {
             String sTemp = format.formatPeriod( period );
-            
-            if ( !stringFormatDate.contains( sTemp ) )
-            {
-                stringFormatDate += HYPHEN + sTemp;
+
+            if ( stringFormatDate.isEmpty() )
+            {
+                stringFormatDate = SPACE + sTemp;
+            }
+            else if ( !stringFormatDate.contains( sTemp ) )
+            {
+                stringFormatDate += DASH + sTemp;
             }
         }
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataBrowserResult.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataBrowserResult.vm	2010-03-17 06:07:42 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/webapp/dhis-web-maintenance-dataadmin/dataBrowserResult.vm	2010-04-13 06:00:13 +0000
@@ -119,6 +119,7 @@
 	    <strong>$i18n.getString( "period_type" ):</strong> $periodTypeId
 	#elseif ( $fromToDate != "" )
 	    <strong>$i18n.getString( "from_date" ):</strong> $fromToDate
+		<br/>
 		<strong>$i18n.getString( "period_type" ):</strong> $periodTypeId
 	#else
 	    <strong>$i18n.getString( "from_date" ):</strong> $fromDate
@@ -135,7 +136,7 @@
 	<thead>
 		<tr>
 		#foreach ( $col in $allColumnsConverted )
-			<th title="$col.metaValue">$col.name</th>
+			<th title="$col.metaValue">$i18n.getString( $col.name )</th>
 		#end
 		</tr>
 	</thead>