← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11923: Impl function for getting more hits for dashboard search for certain object types in service layer

 

------------------------------------------------------------
revno: 11923
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-09-04 17:50:41 +0200
message:
  Impl function for getting more hits for dashboard search for certain object types in service layer
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.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/dashboard/DashboardItem.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardItem.java	2013-09-04 15:50:41 +0000
@@ -65,7 +65,7 @@
     public static final String TYPE_REPORT_TABLES = "reportTables";
     public static final String TYPE_REPORTS = "reports";
     public static final String TYPE_RESOURCES = "resources";
-    public static final String TYPE_PATIENT_TABULAR_REPORT = "patientTabularReports";
+    public static final String TYPE_PATIENT_TABULAR_REPORTS = "patientTabularReports";
     
     private Chart chart;
     
@@ -135,7 +135,7 @@
         }
         else if ( !patientTabularReports.isEmpty() )
         {
-            return TYPE_PATIENT_TABULAR_REPORT;
+            return TYPE_PATIENT_TABULAR_REPORTS;
         }
         return null;
     }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java	2013-08-23 15:56:19 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java	2013-09-04 15:50:41 +0000
@@ -1,6 +1,7 @@
 package org.hisp.dhis.dashboard;
 
 import java.util.List;
+import java.util.Set;
 
 import org.hisp.dhis.user.User;
 
@@ -42,6 +43,8 @@
 
     DashboardSearchResult search( String query );
     
+    DashboardSearchResult search( String query, Set<String> maxTypes );
+    
     void addItemContent( String dashboardUid, String type, String contentUid );
     
     void mergeDashboard( Dashboard dashboard );

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java	2013-09-04 15:50:41 +0000
@@ -31,14 +31,16 @@
 import static org.hisp.dhis.common.IdentifiableObjectUtils.getUids;
 import static org.hisp.dhis.dashboard.DashboardItem.TYPE_CHART;
 import static org.hisp.dhis.dashboard.DashboardItem.TYPE_MAP;
+import static org.hisp.dhis.dashboard.DashboardItem.TYPE_PATIENT_TABULAR_REPORTS;
+import static org.hisp.dhis.dashboard.DashboardItem.TYPE_REPORTS;
 import static org.hisp.dhis.dashboard.DashboardItem.TYPE_REPORT_TABLE;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_REPORTS;
 import static org.hisp.dhis.dashboard.DashboardItem.TYPE_REPORT_TABLES;
 import static org.hisp.dhis.dashboard.DashboardItem.TYPE_RESOURCES;
 import static org.hisp.dhis.dashboard.DashboardItem.TYPE_USERS;
-import static org.hisp.dhis.dashboard.DashboardItem.TYPE_PATIENT_TABULAR_REPORT;
 
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import org.hisp.dhis.chart.Chart;
 import org.hisp.dhis.common.IdentifiableObjectManager;
@@ -65,7 +67,8 @@
 public class DefaultDashboardService
     implements DashboardService
 {
-    private static final int MAX_PER_OBJECT = 5;
+    private static final int HITS_PER_OBJECT = 5;
+    private static final int MAX_HITS_PER_OBJECT = 25;
     
     // -------------------------------------------------------------------------
     // Dependencies
@@ -88,15 +91,21 @@
     @Override
     public DashboardSearchResult search( String query )
     {
+        return search( query, new HashSet<String>() );
+    }
+    
+    @Override
+    public DashboardSearchResult search( String query, Set<String> maxTypes )
+    {
         DashboardSearchResult result = new DashboardSearchResult();
         
-        result.setUsers( objectManager.getBetweenByName( User.class, query, 0, MAX_PER_OBJECT ) );
-        result.setCharts( objectManager.getBetweenByName( Chart.class, query, 0, MAX_PER_OBJECT ) );
-        result.setMaps( objectManager.getBetweenByName( Map.class, query, 0, MAX_PER_OBJECT ) );
-        result.setReportTables( objectManager.getBetweenByName( ReportTable.class, query, 0, MAX_PER_OBJECT ) );
-        result.setReports( objectManager.getBetweenByName( Report.class, query, 0, MAX_PER_OBJECT ) );
-        result.setResources( objectManager.getBetweenByName( Document.class, query, 0, MAX_PER_OBJECT ) );
-        result.setPatientTabularReports( objectManager.getBetweenByName( PatientTabularReport.class, query, 0, MAX_PER_OBJECT ) );
+        result.setUsers( objectManager.getBetweenByName( User.class, query, 0, getMax( TYPE_USERS, maxTypes ) ) );
+        result.setCharts( objectManager.getBetweenByName( Chart.class, query, 0, getMax( TYPE_CHART, maxTypes ) ) );
+        result.setMaps( objectManager.getBetweenByName( Map.class, query, 0, getMax( TYPE_MAP, maxTypes ) ) );
+        result.setReportTables( objectManager.getBetweenByName( ReportTable.class, query, 0, getMax( TYPE_REPORT_TABLE, maxTypes ) ) );
+        result.setReports( objectManager.getBetweenByName( Report.class, query, 0, getMax( TYPE_REPORTS, maxTypes ) ) );
+        result.setResources( objectManager.getBetweenByName( Document.class, query, 0, getMax( TYPE_RESOURCES, maxTypes ) ) );
+        result.setPatientTabularReports( objectManager.getBetweenByName( PatientTabularReport.class, query, 0, getMax( TYPE_PATIENT_TABULAR_REPORTS, maxTypes ) ) );
         
         return result;
     }
@@ -146,7 +155,7 @@
             {
                 item.getResources().add( objectManager.get( Document.class, contentUid ) );
             }
-            else if ( TYPE_PATIENT_TABULAR_REPORT.equals( type ) )
+            else if ( TYPE_PATIENT_TABULAR_REPORTS.equals( type ) )
             {
                 item.getPatientTabularReports().add( objectManager.get( PatientTabularReport.class, contentUid ) );
             }
@@ -243,4 +252,12 @@
     {
         return dashboardStore.getByUser( user );
     }
+    // -------------------------------------------------------------------------
+    // Supportive methods
+    // -------------------------------------------------------------------------
+
+    private int getMax( String type, Set<String> maxTypes )
+    {
+        return maxTypes != null && maxTypes.contains( type ) ? MAX_HITS_PER_OBJECT : HITS_PER_OBJECT;
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java	2013-08-23 16:00:30 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java	2013-09-04 15:50:41 +0000
@@ -29,6 +29,7 @@
  */
 
 import java.io.InputStream;
+import java.util.Set;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
@@ -63,9 +64,10 @@
     private DashboardService dashboardService;
     
     @RequestMapping( value = "/q/{query}", method = RequestMethod.GET )
-    public String search( @PathVariable String query, Model model, HttpServletResponse response ) throws Exception
+    public String search( @PathVariable String query, @RequestParam(required=false) Set<String> max, 
+        Model model, HttpServletResponse response ) throws Exception
     {
-        DashboardSearchResult result = dashboardService.search( query );
+        DashboardSearchResult result = dashboardService.search( query, max );
         
         model.addAttribute( "model", result );