← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7119: Made report service paging consistent. Copied mydatamart action functionality to web api.

 

------------------------------------------------------------
revno: 7119
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-05-31 15:16:24 +0200
message:
  Made report service paging consistent. Copied mydatamart action functionality to web api.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java
  dhis-2/dhis-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java
  dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/GetAllReportsAction.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/report/ReportService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java	2012-04-23 10:21:07 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/report/ReportService.java	2012-05-31 13:16:24 +0000
@@ -75,6 +75,12 @@
      * @return the total number of reports.
      */
     int getReportCount();
+    
+    /**
+     * Returns the number of reports which names are like the given name.
+     * Returns the number of reports which names are like the given name.
+     */
+    int getReportCountByName( String name );
 
     /**
      * Retrieves the given number of maximum reports starting at the given start

=== modified file 'dhis-2/dhis-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java'
--- dhis-2/dhis-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java	2012-05-30 11:13:07 +0000
+++ dhis-2/dhis-dxf2/src/test/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetServiceTest.java	2012-05-31 13:16:24 +0000
@@ -54,7 +54,6 @@
 import org.hisp.dhis.period.MonthlyPeriodType;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
-import org.junit.Ignore;
 import org.junit.Test;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.ClassPathResource;

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java	2012-04-25 20:34:19 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/report/impl/DefaultReportService.java	2012-05-31 13:16:24 +0000
@@ -191,6 +191,12 @@
     }
 
     @Override
+    public int getReportCountByName( String name )
+    {
+        return reportStore.getCountByName( name );
+    }
+    
+    @Override
     public Collection<Report> getReportsBetween( int first, int max )
     {
         return reportStore.getBetween( first, max );

=== modified file 'dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/GetAllReportsAction.java'
--- dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/GetAllReportsAction.java	2012-01-25 17:11:43 +0000
+++ dhis-2/dhis-web/dhis-web-reporting/src/main/java/org/hisp/dhis/reporting/reportviewer/action/GetAllReportsAction.java	2012-05-31 13:16:24 +0000
@@ -30,17 +30,14 @@
 import static org.apache.commons.lang.StringUtils.isNotBlank;
 
 import java.util.ArrayList;
-import java.util.Collections;
 import java.util.List;
 
-import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.paging.ActionPagingSupport;
 import org.hisp.dhis.report.Report;
 import org.hisp.dhis.report.ReportService;
 
 /**
  * @author Lars Helge Overland
- * @version $Id$
  */
 public class GetAllReportsAction
     extends ActionPagingSupport<Report>
@@ -86,40 +83,19 @@
     public String execute() 
         throws Exception
     {
-        reports = new ArrayList<Report>( reportService.getAllReports() );
-        
-        Collections.sort( reports, IdentifiableObjectNameComparator.INSTANCE );
-        
         if ( isNotBlank( key ) )
         {
-            reports = searchByName( reports, key );
-            
-            this.paging = createPaging( reports.size() );
-            
-            reports = getBlockElement( reports, paging.getStartPos(), paging.getPageSize() );           
+            this.paging = createPaging( reportService.getReportCountByName( key ) );
+            
+            reports = new ArrayList<Report>( reportService.getReportsBetweenByName( key, paging.getStartPos(), paging.getPageSize() ) );
         }
         else 
         {
-            this.paging = createPaging( reports.size() );
+            this.paging = createPaging( reportService.getReportCount() );
                 
-            reports = getBlockElement( reports, paging.getStartPos(), paging.getPageSize() );
+            reports = new ArrayList<Report>( reportService.getReportsBetween( paging.getStartPos(), paging.getPageSize() ) );
         }
         
         return SUCCESS;
     }
-    
-    private List<Report> searchByName( List<Report> reports, String key )
-    {
-        List<Report> result = new ArrayList<Report>();
-
-        for ( Report each : reports )
-        {
-            if ( each.getName().toLowerCase().contains( key.toLowerCase() ) )
-            {
-                result.add( each );
-            }
-        }
-        
-        return result;
-    }
 }