dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20368
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9261: Extended OrganisationUnit{Store, Service} to support getting OUs based on active/lastUpdated
------------------------------------------------------------
revno: 9261
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-12-11 12:10:15 +0300
message:
Extended OrganisationUnit{Store, Service} to support getting OUs based on active/lastUpdated
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java
dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.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/organisationunit/OrganisationUnitService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2012-10-31 17:24:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2012-12-11 09:10:15 +0000
@@ -114,6 +114,34 @@
Collection<OrganisationUnit> getAllOrganisationUnits();
/**
+ * Returns all OrganisationUnits by status.
+ *
+ * @param active Get active or inactive
+ * @return a collection of all OrganisationUnits, or an empty collection if
+ * there are no OrganisationUnits.
+ */
+ Collection<OrganisationUnit> getAllOrganisationUnitsByStatus( boolean active );
+
+ /**
+ * Returns all OrganisationUnits by lastUpdated.
+ *
+ * @param lastUpdated OrganisationUnits from this date
+ * @return a collection of all OrganisationUnits, or an empty collection if
+ * there are no OrganisationUnits.
+ */
+ Collection<OrganisationUnit> getAllOrganisationUnitsByLastUpdated( Date lastUpdated );
+
+ /**
+ * Returns all OrganisationUnits by status and lastUpdated.
+ *
+ * @param active Get active or inactive
+ * @param lastUpdated OrganisationUnits from this date
+ * @return a collection of all OrganisationUnits, or an empty collection if
+ * there are no OrganisationUnits.
+ */
+ Collection<OrganisationUnit> getAllOrganisationUnitsByStatusLastUpdated( boolean active, Date lastUpdated );
+
+ /**
* Returns all OrganisationUnits with corresponding name key based on the given list.
*
* @param orgUnits the collection of organization unit objects.
@@ -165,11 +193,11 @@
/**
* Returns the level of the organisation unit with the given identifier.
- *
+ *
* @return the level of the organisation unit with the given identifier.
*/
int getLevelOfOrganisationUnit( int id );
-
+
/**
* Returns all OrganisationUnits which are part of the subtree of the
* OrganisationUnit with the given identifer and have no children.
@@ -241,10 +269,10 @@
/**
* Returns all OrganisationUnit which names are like the given name, or which
* code or uid are equal the given name, and are within the given groups.
- *
- * @param query the query to match on name, code or uid.
+ *
+ * @param query the query to match on name, code or uid.
* @param groups the organisation unit groups.
- * @param limit the limit of returned objects.
+ * @param limit the limit of returned objects.
* @return a collection of OrganisationUnits.
*/
Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, boolean limit );
@@ -252,10 +280,10 @@
/**
* Returns all OrganisationUnit which names are like the given name, or which
* code or uid are equal the given name, and are within the given groups.
- *
- * @param query the query to match on name, code or uid.
+ *
+ * @param query the query to match on name, code or uid.
* @param groups the organisation unit groups.
- * @param limit the limit of returned objects.
+ * @param limit the limit of returned objects.
* @return a collection of OrganisationUnits.
*/
Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name, Collection<OrganisationUnitGroup> groups, OrganisationUnit parent, boolean limit );
@@ -265,9 +293,9 @@
void filterOrganisationUnitsWithoutData( Collection<OrganisationUnit> organisationUnits );
Collection<OrganisationUnit> getOrganisationUnitsBetween( int first, int max );
-
+
Collection<OrganisationUnit> getOrganisationUnitsBetweenByName( String name, int first, int max );
-
+
// -------------------------------------------------------------------------
// OrganisationUnitHierarchy
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java 2012-10-31 17:24:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java 2012-12-11 09:10:15 +0000
@@ -30,6 +30,7 @@
import org.hisp.dhis.common.GenericNameableObjectStore;
import java.util.Collection;
+import java.util.Date;
import java.util.Map;
import java.util.Set;
@@ -49,6 +50,34 @@
// -------------------------------------------------------------------------
/**
+ * Returns all OrganisationUnits by status.
+ *
+ * @param active Get active or inactive
+ * @return a collection of all OrganisationUnits, or an empty collection if
+ * there are no OrganisationUnits.
+ */
+ Collection<OrganisationUnit> getAllOrganisationUnitsByStatus( boolean active );
+
+ /**
+ * Returns all OrganisationUnits by lastUpdated.
+ *
+ * @param lastUpdated OrganisationUnits from this date
+ * @return a collection of all OrganisationUnits, or an empty collection if
+ * there are no OrganisationUnits.
+ */
+ Collection<OrganisationUnit> getAllOrganisationUnitsByLastUpdated( Date lastUpdated );
+
+ /**
+ * Returns all OrganisationUnits by status and lastUpdated.
+ *
+ * @param active Get active or inactive
+ * @param lastUpdated OrganisationUnits from this date
+ * @return a collection of all OrganisationUnits, or an empty collection if
+ * there are no OrganisationUnits.
+ */
+ Collection<OrganisationUnit> getAllOrganisationUnitsByStatusLastUpdated( boolean active, Date lastUpdated );
+
+ /**
* Returns an OrganisationUnit with a given name. Case is ignored.
*
* @param name the name of the OrganisationUnit to return.
@@ -75,10 +104,10 @@
/**
* Returns all OrganisationUnit which names are like the given name, or which
* code or uid are equal the given name, and are within the given groups.
- *
- * @param query the query to match on name, code or uid.
+ *
+ * @param query the query to match on name, code or uid.
* @param groups the organisation unit groups.
- * @param limit the limit of returned objects.
+ * @param limit the limit of returned objects.
* @return a collection of OrganisationUnits.
*/
Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String query, Collection<OrganisationUnitGroup> groups, boolean limit );
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2012-11-25 19:22:52 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2012-12-11 09:10:15 +0000
@@ -151,6 +151,24 @@
return organisationUnitStore.getAll();
}
+ @Override
+ public Collection<OrganisationUnit> getAllOrganisationUnitsByStatus( boolean active )
+ {
+ return organisationUnitStore.getAllOrganisationUnitsByStatus( active );
+ }
+
+ @Override
+ public Collection<OrganisationUnit> getAllOrganisationUnitsByLastUpdated( Date lastUpdated )
+ {
+ return organisationUnitStore.getAllOrganisationUnitsByLastUpdated( lastUpdated );
+ }
+
+ @Override
+ public Collection<OrganisationUnit> getAllOrganisationUnitsByStatusLastUpdated( boolean active, Date lastUpdated )
+ {
+ return organisationUnitStore.getAllOrganisationUnitsByStatusLastUpdated( active, lastUpdated );
+ }
+
public void searchOrganisationUnitByName( List<OrganisationUnit> orgUnits, String key )
{
Iterator<OrganisationUnit> iterator = orgUnits.iterator();
@@ -422,7 +440,7 @@
return organisationUnitStore.getOrganisationUnitsByNameAndGroups( query, groups, limit );
}
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String name,
Collection<OrganisationUnitGroup> groups, OrganisationUnit parent, boolean limit )
{
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java 2012-10-31 17:24:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java 2012-12-11 09:10:15 +0000
@@ -27,29 +27,20 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Timestamp;
-import java.util.Collection;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
-import org.hisp.dhis.organisationunit.OrganisationUnitHierarchy;
-import org.hisp.dhis.organisationunit.OrganisationUnitService;
-import org.hisp.dhis.organisationunit.OrganisationUnitStore;
+import org.hisp.dhis.organisationunit.*;
import org.hisp.dhis.system.objectmapper.OrganisationUnitRelationshipRowMapper;
import org.springframework.jdbc.core.RowCallbackHandler;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
+import java.util.*;
+
/**
* @author Kristian Nordal
*/
@@ -61,25 +52,53 @@
// OrganisationUnit
// -------------------------------------------------------------------------
- @Override
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public Collection<OrganisationUnit> getAllOrganisationUnitsByStatus( boolean active )
+ {
+ Query query = getQuery( "from OrganisationUnit o where o.active is :active" );
+ query.setParameter( "active", active );
+
+ return query.list();
+ }
+
+ @Override
+ public Collection<OrganisationUnit> getAllOrganisationUnitsByLastUpdated( Date lastUpdated )
+ {
+ return getByLastUpdated( lastUpdated );
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public Collection<OrganisationUnit> getAllOrganisationUnitsByStatusLastUpdated( boolean active, Date lastUpdated )
+ {
+ return getCriteria().add( Restrictions.ge( "lastUpdated", lastUpdated ) ).add( Restrictions.eq( "active", active ) ).list();
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
public OrganisationUnit getOrganisationUnitByNameIgnoreCase( String name )
{
return (OrganisationUnit) getCriteria( Restrictions.eq( "name", name ).ignoreCase() ).uniqueResult();
}
+ @Override
@SuppressWarnings( "unchecked" )
public Collection<OrganisationUnit> getRootOrganisationUnits()
{
return getQuery( "from OrganisationUnit o where o.parent is null" ).list();
}
- @SuppressWarnings( "unchecked" )
+ @Override
+ @SuppressWarnings("unchecked")
public Collection<OrganisationUnit> getOrganisationUnitsWithoutGroups()
{
return getQuery( "from OrganisationUnit o where o.groups.size = 0" ).list();
}
- @SuppressWarnings( "unchecked" )
+ @Override
+ @SuppressWarnings("unchecked")
public Collection<OrganisationUnit> getOrganisationUnitsByNameAndGroups( String query,
Collection<OrganisationUnitGroup> groups, boolean limit )
{
@@ -110,7 +129,7 @@
}
Query q = sessionFactory.getCurrentSession().createQuery( hql.toString() );
-
+
if ( query != null )
{
q.setString( "expression", "%" + query.toLowerCase() + "%" );