← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11470: Improved dashboard search. Exposed it through web api. Allowing for more hits in search result page.

 

------------------------------------------------------------
revno: 11470
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-07-22 17:17:19 +0200
message:
  Improved dashboard search. Exposed it through web api. Allowing for more hits in search result page.
removed:
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/SearchAction.java
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/hits.vm
added:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardSearchResult.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java
  dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.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/DocumentController.java
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js
  dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/style/dashboard.css


--
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/chart/ChartService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java	2013-05-29 13:18:45 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/chart/ChartService.java	2013-07-22 15:17:19 +0000
@@ -29,6 +29,7 @@
 
 import java.util.Collection;
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
 
 import org.hisp.dhis.dataelement.DataElement;
@@ -101,9 +102,9 @@
 
     Collection<Chart> getCharts( final Collection<Integer> identifiers );
 
-    Collection<Chart> getChartsBetween( int first, int max );
+    List<Chart> getChartsBetween( int first, int max );
 
-    Collection<Chart> getChartsBetweenByName( String name, int first, int max );
+    List<Chart> getChartsBetweenByName( String name, int first, int max );
 
     int getChartCount();
 

=== added file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardSearchResult.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardSearchResult.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardSearchResult.java	2013-07-22 15:17:19 +0000
@@ -0,0 +1,211 @@
+package org.hisp.dhis.dashboard;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.hisp.dhis.chart.Chart;
+import org.hisp.dhis.common.BaseIdentifiableObject;
+import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.document.Document;
+import org.hisp.dhis.mapping.Map;
+import org.hisp.dhis.report.Report;
+import org.hisp.dhis.reporttable.ReportTable;
+import org.hisp.dhis.user.User;
+
+import com.fasterxml.jackson.annotation.JsonProperty;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlElementWrapper;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+
+@JacksonXmlRootElement( localName = "dashboardSearchResult", namespace = DxfNamespaces.DXF_2_0)
+public class DashboardSearchResult
+{
+    private List<User> users = new ArrayList<User>();
+    
+    private List<Chart> charts = new ArrayList<Chart>();
+    
+    private List<Map> maps = new ArrayList<Map>();
+
+    private List<ReportTable> reportTables = new ArrayList<ReportTable>();
+    
+    private List<Report> reports = new ArrayList<Report>();
+
+    private List<Document> resources = new ArrayList<Document>();
+
+    // -------------------------------------------------------------------------
+    // Constructor
+    // -------------------------------------------------------------------------
+
+    public DashboardSearchResult()
+    {
+    }
+
+    // -------------------------------------------------------------------------
+    // Logic
+    // -------------------------------------------------------------------------
+
+    @JsonProperty
+    public int getSearchCount()
+    {
+        int results = 0;
+        results += users.size();
+        results += charts.size();
+        results += maps.size();
+        results += reportTables.size();
+        results += reports.size();
+        results += resources.size();
+        return results;
+    }
+
+    @JsonProperty
+    public int getUserCount()
+    {
+        return users.size();
+    }
+    
+    @JsonProperty
+    public int getChartCount()
+    {
+        return charts.size();
+    }
+
+    @JsonProperty
+    public int getMapCount()
+    {
+        return maps.size();
+    }
+
+    @JsonProperty
+    public int getReportTableCount()
+    {
+        return reportTables.size();
+    }
+
+    @JsonProperty
+    public int getReportCount()
+    {
+        return reports.size();
+    }
+
+    @JsonProperty
+    public int getResourceCount()
+    {
+        return resources.size();
+    }    
+
+    // -------------------------------------------------------------------------
+    // Getters and setters
+    // -------------------------------------------------------------------------
+
+    @JsonProperty( value = "users" )
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+    @JacksonXmlElementWrapper( localName = "users", namespace = DxfNamespaces.DXF_2_0)
+    @JacksonXmlProperty( localName = "user", namespace = DxfNamespaces.DXF_2_0)
+    public List<User> getUsers()
+    {
+        return users;
+    }
+
+    public void setUsers( List<User> users )
+    {
+        this.users = users;
+    }
+
+    @JsonProperty( value = "charts" )
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+    @JacksonXmlElementWrapper( localName = "charts", namespace = DxfNamespaces.DXF_2_0)
+    @JacksonXmlProperty( localName = "chart", namespace = DxfNamespaces.DXF_2_0)
+    public List<Chart> getCharts()
+    {
+        return charts;
+    }
+
+    public void setCharts( List<Chart> charts )
+    {
+        this.charts = charts;
+    }
+
+    @JsonProperty( value = "maps" )
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+    @JacksonXmlElementWrapper( localName = "maps", namespace = DxfNamespaces.DXF_2_0)
+    @JacksonXmlProperty( localName = "map", namespace = DxfNamespaces.DXF_2_0)
+    public List<Map> getMaps()
+    {
+        return maps;
+    }
+
+    public void setMaps( List<Map> maps )
+    {
+        this.maps = maps;
+    }
+
+    @JsonProperty( value = "reportTables" )
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+    @JacksonXmlElementWrapper( localName = "reportTables", namespace = DxfNamespaces.DXF_2_0)
+    @JacksonXmlProperty( localName = "reportTable", namespace = DxfNamespaces.DXF_2_0)
+    public List<ReportTable> getReportTables()
+    {
+        return reportTables;
+    }
+
+    public void setReportTables( List<ReportTable> reportTables )
+    {
+        this.reportTables = reportTables;
+    }
+
+    @JsonProperty( value = "reports" )
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+    @JacksonXmlElementWrapper( localName = "reports", namespace = DxfNamespaces.DXF_2_0)
+    @JacksonXmlProperty( localName = "report", namespace = DxfNamespaces.DXF_2_0)
+    public List<Report> getReports()
+    {
+        return reports;
+    }
+
+    public void setReports( List<Report> reports )
+    {
+        this.reports = reports;
+    }
+
+    @JsonProperty( value = "resources" )
+    @JsonSerialize( contentAs = BaseIdentifiableObject.class )
+    @JacksonXmlElementWrapper( localName = "resources", namespace = DxfNamespaces.DXF_2_0)
+    @JacksonXmlProperty( localName = "resource", namespace = DxfNamespaces.DXF_2_0)
+    public List<Document> getResources()
+    {
+        return resources;
+    }
+
+    public void setResources( List<Document> resources )
+    {
+        this.resources = resources;
+    }
+}

=== 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	2012-11-06 07:01:56 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dashboard/DashboardService.java	2013-07-22 15:17:19 +0000
@@ -28,9 +28,7 @@
  */
 
 import java.util.Collection;
-import java.util.List;
 
-import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.document.Document;
 import org.hisp.dhis.mapping.Map;
 import org.hisp.dhis.report.Report;
@@ -44,7 +42,7 @@
 {
     final String ID = DashboardService.class.getName();
 
-    List<IdentifiableObject> search( String query );
+    DashboardSearchResult search( String query );
     
     void saveDashboardContent( DashboardContent dashboardContent );
 

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java	2013-01-24 04:15:05 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserService.java	2013-07-22 15:17:19 +0000
@@ -6,6 +6,7 @@
 import java.io.Serializable;
 import java.util.Collection;
 import java.util.Date;
+import java.util.List;
 import java.util.Map;
 
 /*
@@ -93,9 +94,9 @@
      */
     Collection<User> getAllUsers();
 
-    Collection<User> getAllUsersBetween( int first, int max );
+    List<User> getAllUsersBetween( int first, int max );
     
-    Collection<User> getAllUsersBetweenByName( String name, int first, int max );
+    List<User> getAllUsersBetweenByName( String name, int first, int max );
 
     Collection<User> getUsersByLastUpdated(Date lastUpdated);
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java	2013-01-24 04:15:05 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/user/DefaultUserService.java	2013-07-22 15:17:19 +0000
@@ -32,6 +32,7 @@
 import java.util.Collection;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 
 import org.apache.commons.logging.Log;
@@ -185,13 +186,13 @@
     }
 
     @Override
-    public Collection<User> getAllUsersBetween( int first, int max )
+    public List<User> getAllUsersBetween( int first, int max )
     {
         return userStore.getAllOrderedName( first, max );
     }
     
     @Override
-    public Collection<User> getAllUsersBetweenByName( String name, int first, int max )
+    public List<User> getAllUsersBetweenByName( String name, int first, int max )
     {
         return userStore.getAllLikeNameOrderedName( name, first, max );
     }

=== modified file 'dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java'
--- dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2013-07-04 15:41:57 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/chart/impl/DefaultChartService.java	2013-07-22 15:17:19 +0000
@@ -822,12 +822,12 @@
         return chartStore.getCountLikeName( name );
     }
 
-    public Collection<Chart> getChartsBetween( int first, int max )
+    public List<Chart> getChartsBetween( int first, int max )
     {
         return chartStore.getAllOrderedName( first, max );
     }
 
-    public Collection<Chart> getChartsBetweenByName( String name, int first, int max )
+    public List<Chart> getChartsBetweenByName( String name, int first, int max )
     {
         return chartStore.getAllLikeNameOrderedName( name, first, max );
     }

=== 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-03-14 04:50:21 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java	2013-07-22 15:17:19 +0000
@@ -27,14 +27,12 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import java.util.ArrayList;
 import java.util.Collection;
-import java.util.List;
 
 import org.hisp.dhis.chart.ChartService;
-import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.dashboard.DashboardContent;
 import org.hisp.dhis.dashboard.DashboardContentStore;
+import org.hisp.dhis.dashboard.DashboardSearchResult;
 import org.hisp.dhis.dashboard.DashboardService;
 import org.hisp.dhis.document.Document;
 import org.hisp.dhis.document.DocumentService;
@@ -58,7 +56,6 @@
     implements DashboardService
 {
     private static final int MAX_PER_OBJECT = 5;
-    private static final int MAX_OBJECTS = 15;
     
     // -------------------------------------------------------------------------
     // Dependencies
@@ -117,38 +114,18 @@
     // DashboardService implementation
     // -------------------------------------------------------------------------
 
-    public List<IdentifiableObject> search( String query )
+    public DashboardSearchResult search( String query )
     {
-        List<IdentifiableObject> objects = new ArrayList<IdentifiableObject>();
-        
-        int remaining = 0;
-        
-        objects.addAll( userService.getAllUsersBetweenByName( query, 0, MAX_PER_OBJECT ) );
-        objects.addAll( chartService.getChartsBetweenByName( query, 0, MAX_PER_OBJECT ) );
-        objects.addAll( mappingService.getMapsBetweenLikeName( query, 0, MAX_PER_OBJECT ) );
-
-        remaining = MAX_OBJECTS - objects.size();
-        
-        if ( remaining > 0 )
-        {
-            objects.addAll( reportService.getReportsBetweenByName( query, 0, MAX_PER_OBJECT ) );
-        }
-        
-        remaining = MAX_OBJECTS - objects.size();
-        
-        if ( remaining > 0 )
-        {
-            objects.addAll( reportTableService.getReportTablesBetweenByName( query, 0, Math.min( remaining, MAX_PER_OBJECT ) ) );
-        }
-
-        remaining = MAX_OBJECTS - objects.size();
-        
-        if ( remaining > 0 )
-        {
-            objects.addAll( documentService.getDocumentsBetweenByName( query, 0, Math.min( remaining, MAX_PER_OBJECT ) ) );
-        }
-        
-        return objects;
+        DashboardSearchResult result = new DashboardSearchResult();
+        
+        result.setUsers( userService.getAllUsersBetweenByName( query, 0, MAX_PER_OBJECT ) );
+        result.setCharts( chartService.getChartsBetweenByName( query, 0, MAX_PER_OBJECT ) );
+        result.setMaps( mappingService.getMapsBetweenLikeName( query, 0, MAX_PER_OBJECT ) );
+        result.setReportTables( reportTableService.getReportTablesBetweenByName( query, 0, MAX_PER_OBJECT ) );
+        result.setReports( reportService.getReportsBetweenByName( query, 0, MAX_PER_OBJECT ) );
+        result.setResources( documentService.getDocumentsBetweenByName( query, 0, MAX_PER_OBJECT ) );
+        
+        return result;
     }
     
     public void saveDashboardContent( DashboardContent dashboardContent )

=== added 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	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DashboardController.java	2013-07-22 15:17:19 +0000
@@ -0,0 +1,41 @@
+package org.hisp.dhis.api.controller;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.hisp.dhis.api.utils.ContextUtils;
+import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
+import org.hisp.dhis.dashboard.DashboardSearchResult;
+import org.hisp.dhis.dashboard.DashboardService;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Controller;
+import org.springframework.ui.Model;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+
+@Controller
+@RequestMapping( value = DashboardController.RESOURCE_PATH )
+public class DashboardController
+{
+    public static final String RESOURCE_PATH = "/dashboards";
+        
+    @Autowired
+    private DashboardService dashboardService;
+    
+    @Autowired
+    private ContextUtils contextUtils;
+    
+    @RequestMapping( value = "/search/{query}", method = RequestMethod.GET, produces = { "application/json" } )
+    public String search( @PathVariable String query, 
+        Model model,
+        HttpServletResponse response ) throws Exception
+    {
+        contextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_JSON, CacheStrategy.NO_CACHE );
+        
+        DashboardSearchResult result = dashboardService.search( query );
+        
+        model.addAttribute( "model", result );
+        
+        return "dashboardSearchResult";
+    }
+}

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java	2013-04-23 12:02:26 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DocumentController.java	2013-07-22 15:17:19 +0000
@@ -72,7 +72,13 @@
     public void getDocumentContent( @PathVariable( "uid" ) String uid, HttpServletResponse response ) throws Exception
     {
         Document document = documentService.getDocument( uid );
-
+        
+        if ( document == null )
+        {
+            ContextUtils.notFoundResponse( response, "Resource not found for identifier: " + uid );
+            return;
+        }
+        
         if ( document.isExternal() )
         {
             response.sendRedirect( response.encodeRedirectURL( document.getUrl() ) );

=== removed file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/SearchAction.java'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/SearchAction.java	2012-10-05 16:00:19 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/java/org/hisp/dhis/dashboard/action/SearchAction.java	1970-01-01 00:00:00 +0000
@@ -1,95 +0,0 @@
-package org.hisp.dhis.dashboard.action;
-
-/*
- * Copyright (c) 2004-2012, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- *   list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- *   this list of conditions and the following disclaimer in the documentation
- *   and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- *   be used to endorse or promote products derived from this software without
- *   specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
-import static org.hisp.dhis.api.utils.ContextUtils.CONTENT_TYPE_HTML;
-
-import java.util.List;
-
-import org.apache.struts2.ServletActionContext;
-import org.hisp.dhis.api.utils.ContextUtils;
-import org.hisp.dhis.api.utils.ContextUtils.CacheStrategy;
-import org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.dashboard.DashboardService;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import com.opensymphony.xwork2.Action;
-
-/**
- * @author Lars Helge Overland
- */
-public class SearchAction
-    implements Action
-{
-    // -------------------------------------------------------------------------
-    // Dependencies
-    // -------------------------------------------------------------------------
-
-    @Autowired
-    private DashboardService dashboardService;
-
-    @Autowired
-    private ContextUtils contextUtils;
-
-    // -------------------------------------------------------------------------
-    // Input
-    // -------------------------------------------------------------------------
-
-    private String q;
-    
-    public void setQ( String q )
-    {
-        this.q = q;
-    }
-
-    // -------------------------------------------------------------------------
-    // Output
-    // -------------------------------------------------------------------------
-
-    private List<IdentifiableObject> objects;
-    
-    public List<IdentifiableObject> getObjects()
-    {
-        return objects;
-    }
-
-    // -------------------------------------------------------------------------
-    // Action implementation
-    // -------------------------------------------------------------------------
-
-    public String execute()
-    {
-        objects = dashboardService.search( q );
-        
-        // TODO search and cache per user
-        
-        contextUtils.configureResponse( ServletActionContext.getResponse(), CONTENT_TYPE_HTML, CacheStrategy.CACHE_1_HOUR );
-        
-        return SUCCESS;
-    }
-}

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml	2013-03-14 10:53:15 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/META-INF/dhis/beans.xml	2013-07-22 15:17:19 +0000
@@ -55,9 +55,6 @@
     <property name="mappingService" ref="org.hisp.dhis.mapping.MappingService" />
   </bean>
   
-  <bean id="org.hisp.dhis.dashboard.action.SearchAction" class="org.hisp.dhis.dashboard.action.SearchAction"
-    scope="prototype"/>
-  
   <!-- Message -->
 
   <bean id="org.hisp.dhis.dashboard.message.action.GetMessagesAction" class="org.hisp.dhis.dashboard.message.action.GetMessagesAction"

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml	2013-07-19 08:23:53 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/resources/struts.xml	2013-07-22 15:17:19 +0000
@@ -57,12 +57,6 @@
       <result name="success" type="redirect">index.action</result>
     </action>
 
-    <action name="search" class="org.hisp.dhis.dashboard.action.SearchAction">
-      <result name="success" type="velocity">/dhis-web-dashboard-integration/hits.vm
-      </result>
-      <param name="onExceptionReturn">plainTextError</param>
-    </action>
-
     <!-- Message -->
 
     <action name="message"

=== removed file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/hits.vm'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/hits.vm	2012-11-06 12:30:31 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/hits.vm	1970-01-01 00:00:00 +0000
@@ -1,23 +0,0 @@
-<ul>
-#if( $objects.size() > 0 )
-#foreach( $o in $objects )
-#if( $o )
-#if( "User" == $o.getClass().getSimpleName() )
-<li><a href="profile.action?id=${o.uid}"><img src="../images/user_small.png">&nbsp; $encoder.htmlEncode( $o.name )</a></li>
-#elseif( "Chart" == $o.getClass().getSimpleName() )
-<li><a href="../dhis-web-visualizer/app/index.html?id=${o.uid}"><img src="../images/chart_small.png">&nbsp; $encoder.htmlEncode( $o.name )</a></li>
-#elseif( "Map" == $o.getClass().getSimpleName() )
-<li><a href="../dhis-web-mapping/app/index.html?id=${o.uid}"><img src="../images/map_small.png">&nbsp; $encoder.htmlEncode( $o.name )</a></li>
-#elseif( "Report" == $o.getClass().getSimpleName() )
-<li><a href="../dhis-web-reporting/getReportParams.action?uid=${o.uid}&mode=report"><img src="../images/table_small.png">&nbsp; $encoder.htmlEncode( $o.name )</a></li>
-#elseif( "ReportTable" == $o.getClass().getSimpleName() )
-<li><a href="../dhis-web-reporting/getReportParams.action?uid=${o.uid}&mode=table"><img src="../images/table_small.png">&nbsp; $encoder.htmlEncode( $o.name )</a></li>
-#elseif( "Document" == $o.getClass().getSimpleName() )
-<li><a href="../api/documents/${o.uid}/data"><img src="../images/document_small.png">&nbsp; $encoder.htmlEncode( $o.name )</a></li>
-#end
-#end
-#end
-#else
-<li style="padding-left:12px">$i18n.getString( "no_hits" )</li>
-#end
-</ul>
\ No newline at end of file

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js	2013-07-03 15:17:31 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/javascript/dashboard.js	2013-07-22 15:17:19 +0000
@@ -131,11 +131,87 @@
 		return false;
 	}
 	
-	var hits = $.get( "search.action", { q:query }, function( data ) {
-		$( "#hitDiv" ).show().html( data );
+	var hits = $.get( "../api/dashboards/search/" + query, function( data ) {
+		$( "#hitDiv" ).show().html( getSearchResultList( data ) );		
 	} );		
 }
 
+function getSearchResultList( data )
+{
+	var html = "<ul>";
+	
+	if ( data.searchCount > 0 )
+	{
+		if ( data.userCount > 0 )
+		{
+			html += "<li class='hitHeader'>Users</li>";			
+			for ( var i in data.users )
+			{
+				var o = data.users[i];
+				html += "<li><a href='profile.action?id=" + o.id + "'><img src='../images/user_small.png'>" + o.name + "</a></li>";
+			}
+		}
+		
+		if ( data.chartCount > 0 )
+		{
+			html += "<li class='hitHeader'>Charts</li>";
+			for ( var i in data.charts )
+			{
+				var o = data.charts[i];
+				html += "<li><a href='../dhis-web-visualizer/app/index.html?id=" + o.id + "'><img src='../images/chart_small.png'>" + o.name + "</a></li>";
+			}
+		}
+		
+		if ( data.mapCount > 0 )
+		{
+			html += "<li class='hitHeader'>Maps</li>";
+			for ( var i in data.maps )
+			{
+				var o = data.maps[i];
+				html += "<li><a href='../dhis-web-mapping/app/index.html?id=" + o.id + "'><img src='../images/map_small.png'>" + o.name + "</a></li>";
+			}
+		}
+		
+		if ( data.reportTableCount > 0 )
+		{
+			html += "<li class='hitHeader'>Pivot tables</li>";
+			for ( var i in data.reportTables )
+			{
+				var o = data.reportTables[i];
+				html += "<li><a href='../dhis-web-pivot/app/index.html?id=" + o.id + "'><img src='../images/table_small.png'>" + o.name + "</a></li>";
+			}
+		}
+		
+		if ( data.reportCount > 0 )
+		{
+			html += "<li class='hitHeader'>Standard reports</li>";
+			for ( var i in data.reports )
+			{
+				var o = data.reports[i];
+				html += "<li><a href='../dhis-web-reporting/getReportParams.action?uid=" + o.id + "&mode=report'><img src='../images/table_small.png'>" + o.name + "</a></li>";
+			}
+		}
+		
+		if ( data.resourceCount > 0 )
+		{
+			html += "<li class='hitHeader'>Resources</li>";
+			for ( var i in data.resources )
+			{
+				var o = data.resources[i];
+				html += "<li><a href='../api/documents/" + o.id + "/data'><img src='../images/document_small.png'>" + o.name + "</a></li>";
+			}
+		}
+	}
+	else
+	{
+		html += "<li class='hitHeader'>No results found</li>";
+	}
+	
+	html += "</ul>";
+	
+	return html;
+}
+
 function hideSearch()
 {
 	$( "#hitDiv" ).hide();

=== modified file 'dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/style/dashboard.css'
--- dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/style/dashboard.css	2013-07-04 16:05:38 +0000
+++ dhis-2/dhis-web/dhis-web-dashboard-integration/src/main/webapp/dhis-web-dashboard-integration/style/dashboard.css	2013-07-22 15:17:19 +0000
@@ -124,12 +124,13 @@
   margin-top: 29px;
   left: 411px;
   width: 498px;
+  max-height: 520px;
+  overflow-y: scroll;
   border-right: 1px solid #bbb;
   border-bottom: 1px solid #bbb;
   border-left: 1px solid #bbb;
   background-color: #fff;
   display: none;
-  overflow: hidden;
   z-index: 5;
   box-shadow: #ccc 0px 1px 2px 0px;
 }
@@ -142,16 +143,34 @@
 #hitDiv a
 {
   display: block;
-  width: 100%;
   padding: 7px 6px 7px 12px;
 }
 
+#hitDiv img
+{
+  margin-right: 7px;
+}
+
+.hitHeader
+{
+  padding: 5px 6px 5px 33px;
+  margin: 2px 0;
+  border-bottom: 1px solid #ddd;
+  color: #336C8B;
+  font-family: LiberationSansBold;
+}
+
 #hitDiv a:hover
 {
   text-decoration: none;
   background-color: #eee;
 }
 
+#hitDiv::-webkit-scrollbar-track:vertical
+{
+    background-color: #fff;
+}
+
 #shareForm
 {
   display: none;