dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #35108
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18018: Dashboard, implemented smarter search within words.
------------------------------------------------------------
revno: 18018
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-01-16 12:13:34 +0100
message:
Dashboard, implemented smarter search within words.
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java
dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.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/common/GenericIdentifiableObjectStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java 2014-11-17 19:21:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java 2015-01-16 11:13:34 +0000
@@ -31,6 +31,7 @@
import java.util.Collection;
import java.util.Date;
import java.util.List;
+import java.util.Set;
/**
* @author Lars Helge Overland
@@ -140,6 +141,17 @@
List<T> getAllLikeName( String name, int first, int max );
/**
+ * Retrieves a List of objects where the name matches the conjunction of the
+ * given set of words.
+ *
+ * @param words the set of words.
+ * @param first the first result object to return.
+ * @param max the max number of result objects to return.
+ * @return a List of objects.
+ */
+ List<T> getAllLikeName( Set<String> words, int first, int max );
+
+ /**
* Retrieves a List of objects where the shortName is like the given shortName.
*
* @param shortName the shortName.
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2014-12-30 12:06:44 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2015-01-16 11:13:34 +0000
@@ -86,6 +86,8 @@
<T extends IdentifiableObject> List<T> getBetweenSorted( Class<T> clazz, int first, int max );
<T extends IdentifiableObject> List<T> getBetweenLikeName( Class<T> clazz, String name, int first, int max );
+
+ <T extends IdentifiableObject> List<T> getBetweenLikeName( Class<T> clazz, Set<String> words, int first, int max );
<T extends IdentifiableObject> Collection<T> getByLastUpdated( Class<T> clazz, Date lastUpdated );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2014-12-30 13:05:45 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2015-01-16 11:13:34 +0000
@@ -492,6 +492,20 @@
@Override
@SuppressWarnings( "unchecked" )
+ public <T extends IdentifiableObject> List<T> getBetweenLikeName( Class<T> clazz, Set<String> words, int first, int max )
+ {
+ GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
+
+ if ( store == null )
+ {
+ return new ArrayList<>();
+ }
+
+ return (List<T>) store.getAllLikeName( words, first, max );
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
public <T extends IdentifiableObject> Collection<T> getByLastUpdated( Class<T> clazz, Date lastUpdated )
{
GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java 2014-11-17 19:21:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java 2015-01-16 11:13:34 +0000
@@ -32,10 +32,12 @@
import java.util.Collection;
import java.util.Date;
import java.util.List;
+import java.util.Set;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
+import org.hibernate.criterion.Conjunction;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Projections;
import org.hibernate.criterion.Restrictions;
@@ -248,6 +250,25 @@
@Override
@SuppressWarnings("unchecked")
+ public List<T> getAllLikeName( Set<String> nameWords, int first, int max )
+ {
+ Conjunction conjunction = Restrictions.conjunction();
+
+ for ( String word : nameWords )
+ {
+ conjunction.add( Restrictions.like( "name", "%" + word + "%" ).ignoreCase() );
+ }
+
+ return getSharingCriteria()
+ .add( conjunction )
+ .addOrder( Order.asc( "name" ) )
+ .setFirstResult( first )
+ .setMaxResults( max )
+ .list();
+ }
+
+ @Override
+ @SuppressWarnings("unchecked")
public List<T> getAllLikeShortName( String shortName )
{
if ( NameableObject.class.isAssignableFrom( clazz ) )
=== 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 2015-01-14 18:17:17 +0000
+++ dhis-2/dhis-services/dhis-service-reporting/src/main/java/org/hisp/dhis/dashboard/impl/DefaultDashboardService.java 2015-01-16 11:13:34 +0000
@@ -42,11 +42,14 @@
import org.hisp.dhis.mapping.Map;
import org.hisp.dhis.report.Report;
import org.hisp.dhis.reporttable.ReportTable;
+import org.hisp.dhis.system.util.TextUtils;
import org.hisp.dhis.user.User;
import org.hisp.dhis.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
+import com.google.common.collect.Sets;
+
import java.util.HashSet;
import java.util.Set;
@@ -102,16 +105,18 @@
@Override
public DashboardSearchResult search( String query, Set<String> maxTypes )
{
+ Set<String> words = Sets.newHashSet( query.split( TextUtils.SPACE ) );
+
DashboardSearchResult result = new DashboardSearchResult();
result.setUsers( userService.getAllUsersBetweenByName( query, 0, getMax( TYPE_USERS, maxTypes ) ) );
- result.setCharts( objectManager.getBetweenLikeName( Chart.class, query, 0, getMax( TYPE_CHART, maxTypes ) ) );
- result.setEventCharts( objectManager.getBetweenLikeName( EventChart.class, query, 0, getMax( TYPE_EVENT_CHART, maxTypes ) ) );
- result.setMaps( objectManager.getBetweenLikeName( Map.class, query, 0, getMax( TYPE_MAP, maxTypes ) ) );
- result.setReportTables( objectManager.getBetweenLikeName( ReportTable.class, query, 0, getMax( TYPE_REPORT_TABLE, maxTypes ) ) );
- result.setEventReports( objectManager.getBetweenLikeName( EventReport.class, query, 0, getMax( TYPE_EVENT_REPORT, maxTypes ) ) );
- result.setReports( objectManager.getBetweenLikeName( Report.class, query, 0, getMax( TYPE_REPORTS, maxTypes ) ) );
- result.setResources( objectManager.getBetweenLikeName( Document.class, query, 0, getMax( TYPE_RESOURCES, maxTypes ) ) );
+ result.setCharts( objectManager.getBetweenLikeName( Chart.class, words, 0, getMax( TYPE_CHART, maxTypes ) ) );
+ result.setEventCharts( objectManager.getBetweenLikeName( EventChart.class, words, 0, getMax( TYPE_EVENT_CHART, maxTypes ) ) );
+ result.setMaps( objectManager.getBetweenLikeName( Map.class, words, 0, getMax( TYPE_MAP, maxTypes ) ) );
+ result.setReportTables( objectManager.getBetweenLikeName( ReportTable.class, words, 0, getMax( TYPE_REPORT_TABLE, maxTypes ) ) );
+ result.setEventReports( objectManager.getBetweenLikeName( EventReport.class, words, 0, getMax( TYPE_EVENT_REPORT, maxTypes ) ) );
+ result.setReports( objectManager.getBetweenLikeName( Report.class, words, 0, getMax( TYPE_REPORTS, maxTypes ) ) );
+ result.setResources( objectManager.getBetweenLikeName( Document.class, words, 0, getMax( TYPE_RESOURCES, maxTypes ) ) );
return result;
}