← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1657: Fixed Bug <354365>

 

------------------------------------------------------------
revno: 1657
committer: hieu <hieu.hispvietnam@xxxxxxxxx>
branch nick: trunk
timestamp: Wed 2010-03-17 13:31:25 +0700
message:
  Fixed Bug <354365>
modified:
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/SearchAction.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-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	2009-09-14 16:13:49 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-dataadmin/src/main/java/org/hisp/dhis/dataadmin/action/databrowser/SearchAction.java	2010-03-17 06:31:25 +0000
@@ -42,11 +42,14 @@
 import org.hisp.dhis.dataelement.DataElementGroup;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.i18n.I18nFormat;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.organisationunit.comparator.OrganisationUnitNameComparator;
 import org.hisp.dhis.ouwt.manager.OrganisationUnitSelectionManager;
+import org.hisp.dhis.period.CalendarPeriodType;
+import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
 import org.hisp.dhis.system.util.DateUtils;
@@ -75,10 +78,19 @@
 
     private static final String KEY_DATABROWSERTABLE = "dataBrowserTableResults";
 
+    private static final String HYPHEN = " - ";
+
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
 
+    private I18nFormat format;
+
+    public void setFormat( I18nFormat format )
+    {
+        this.format = format;
+    }
+
     private OrganisationUnitService organisationUnitService;
 
     public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
@@ -214,6 +226,13 @@
         this.fromDate = fromDate;
     }
 
+    private String fromToDate;
+
+    public String getFromToDate()
+    {
+        return fromToDate;
+    }
+
     private String periodTypeId;
 
     public String getPeriodTypeId()
@@ -484,6 +503,14 @@
         // Set DataBrowserTable variable for PDF export
         setExportPDFVariables();
 
+        // Get format standard for periods which appropriate with from date, to date and period type
+        fromToDate = getFromToDateFormat( periodType, fromDate, toDate );
+
+        if ( fromToDate == null )
+        {
+            fromToDate = "";
+        }
+
         return SUCCESS;
     }
 
@@ -547,10 +574,72 @@
     private void convertColumnNames( DataBrowserTable dataBrowserTable )
     {
         allColumnsConverted = dataBrowserTable.getColumns();
-        
+
         for ( MetaValue col : allColumnsConverted )
         {
             col.setName( DateUtils.convertDate( col.getName() ) );
         }
     }
+
+    /**
+     * 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 List of Periods
+     */
+
+    @SuppressWarnings( "unused" )
+    private List<Period> getPeriodsList( PeriodType periodType, 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 );
+
+            List<Period> periods = new ArrayList<Period>( periodService.getPeriodsBetweenDates( periodType, date1,
+                date2 ) );
+
+            if ( periods.isEmpty() )
+            {
+                CalendarPeriodType calendarPeriodType = (CalendarPeriodType) periodType;
+
+                periods.add( calendarPeriodType.createPeriod( date1 ) );
+                periods.add( calendarPeriodType.createPeriod( date2 ) );
+            }
+
+            return periods;
+        }
+        catch ( ParseException e )
+        {
+            return null; // The user hasn't specified any dates
+        }
+    }
+
+    @SuppressWarnings( "unchecked" )
+    private String getFromToDateFormat( PeriodType periodType, String fromDate, String toDate )
+    {
+        String stringFormatDate = "";
+        List<Period> periods = new ArrayList( this.getPeriodsList( periodType, fromDate, toDate ) );
+
+        for ( @SuppressWarnings( "unused" )
+        Period period : periods )
+        {
+            String sTemp = format.formatPeriod( period );
+            
+            if ( !stringFormatDate.contains( sTemp ) )
+            {
+                stringFormatDate += HYPHEN + sTemp;
+            }
+        }
+
+        return stringFormatDate;
+    }
 }