dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #20403
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9295: updated orgunitservice to support paging on status/lastUpdated
------------------------------------------------------------
revno: 9295
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-12-13 13:47:58 +0300
message:
updated orgunitservice to support paging on status/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-12-11 20:46:36 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitService.java 2012-12-13 10:47:58 +0000
@@ -29,7 +29,11 @@
import org.hisp.dhis.hierarchy.HierarchyViolationException;
-import java.util.*;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
/**
* Defines methods for working with OrganisationUnits.
@@ -120,7 +124,7 @@
* @return a collection of all OrganisationUnits, or an empty collection if
* there are no OrganisationUnits.
*/
- Collection<OrganisationUnit> getAllOrganisationUnitsByStatus( boolean active );
+ Collection<OrganisationUnit> getAllOrganisationUnitsByStatus( boolean status );
/**
* Returns all OrganisationUnits by lastUpdated.
@@ -134,12 +138,12 @@
/**
* Returns all OrganisationUnits by status and lastUpdated.
*
- * @param active Get active or inactive
+ * @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 );
+ Collection<OrganisationUnit> getAllOrganisationUnitsByStatusLastUpdated( boolean status, Date lastUpdated );
/**
* Returns all OrganisationUnits with corresponding name key based on the given list.
@@ -200,11 +204,11 @@
/**
* Returns the level of the organisation unit with the given uid.
- *
+ *
* @return the level of the organisation unit with the given uid.
*/
int getLevelOfOrganisationUnit( String uid );
-
+
/**
* Returns all OrganisationUnits which are part of the subtree of the
* OrganisationUnit with the given identifer and have no children.
@@ -303,6 +307,12 @@
Collection<OrganisationUnit> getOrganisationUnitsBetweenByName( String name, int first, int max );
+ Collection<OrganisationUnit> getOrganisationUnitsBetweenByStatus( boolean status, int first, int max );
+
+ Collection<OrganisationUnit> getOrganisationUnitsBetweenByLastUpdated( Date lastUpdated, int first, int max );
+
+ Collection<OrganisationUnit> getOrganisationUnitsBetweenByStatusLastUpdated( boolean status, Date lastUpdated, 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-12-11 09:10:15 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/organisationunit/OrganisationUnitStore.java 2012-12-13 10:47:58 +0000
@@ -70,7 +70,7 @@
/**
* Returns all OrganisationUnits by status and lastUpdated.
*
- * @param active Get active or inactive
+ * @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.
@@ -116,6 +116,42 @@
Set<Integer> getOrganisationUnitIdsWithoutData();
+
+ /**
+ * Retrieves the objects determined by the given first result and max result
+ * which status is like the current status.
+ *
+ * @param status the name which result object names must be like.
+ * @param first the first result object to return.
+ * @param max the max number of result objects to return.
+ * @return collection of objects.
+ */
+ Collection<OrganisationUnit> getBetweenByStatus( boolean status, int first, int max );
+
+ /**
+ * Retrieves the objects determined by the given first result and max result
+ * which lastUpdated is larger or equal.
+ *
+ * @param lastUpdated the name which result object names must be like.
+ * @param first the first result object to return.
+ * @param max the max number of result objects to return.
+ * @return collection of objects.
+ */
+ Collection<OrganisationUnit> getBetweenByLastUpdated( Date lastUpdated, int first, int max );
+
+
+ /**
+ * Retrieves the objects determined by the given first result and max result
+ * which status is like the current status, and lastUpdated is larger or equal.
+ *
+ * @param status the name which result object names must be like.
+ * @param lastUpdated the name which result object names must be like.
+ * @param first the first result object to return.
+ * @param max the max number of result objects to return.
+ * @return collection of objects.
+ */
+ Collection<OrganisationUnit> getBetweenByStatusLastUpdated( boolean status, Date lastUpdated, int first, int max );
+
// -------------------------------------------------------------------------
// OrganisationUnitHierarchy
// -------------------------------------------------------------------------
=== 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-12-11 20:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/DefaultOrganisationUnitService.java 2012-12-13 10:47:58 +0000
@@ -39,7 +39,17 @@
import org.hisp.dhis.version.VersionService;
import org.springframework.transaction.annotation.Transactional;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.UUID;
/**
* @author Torgeir Lorange Ostby
@@ -152,9 +162,9 @@
}
@Override
- public Collection<OrganisationUnit> getAllOrganisationUnitsByStatus( boolean active )
+ public Collection<OrganisationUnit> getAllOrganisationUnitsByStatus( boolean status )
{
- return organisationUnitStore.getAllOrganisationUnitsByStatus( active );
+ return organisationUnitStore.getAllOrganisationUnitsByStatus( status );
}
@Override
@@ -164,9 +174,9 @@
}
@Override
- public Collection<OrganisationUnit> getAllOrganisationUnitsByStatusLastUpdated( boolean active, Date lastUpdated )
+ public Collection<OrganisationUnit> getAllOrganisationUnitsByStatusLastUpdated( boolean status, Date lastUpdated )
{
- return organisationUnitStore.getAllOrganisationUnitsByStatusLastUpdated( active, lastUpdated );
+ return organisationUnitStore.getAllOrganisationUnitsByStatusLastUpdated( status, lastUpdated );
}
public void searchOrganisationUnitByName( List<OrganisationUnit> orgUnits, String key )
@@ -550,6 +560,24 @@
return organisationUnitStore.getBetweenByName( name, first, max );
}
+ @Override
+ public Collection<OrganisationUnit> getOrganisationUnitsBetweenByStatus( boolean status, int first, int max )
+ {
+ return organisationUnitStore.getBetweenByStatus( status, first, max );
+ }
+
+ @Override
+ public Collection<OrganisationUnit> getOrganisationUnitsBetweenByLastUpdated( Date lastUpdated, int first, int max )
+ {
+ return organisationUnitStore.getBetweenByLastUpdated( lastUpdated, first, max );
+ }
+
+ @Override
+ public Collection<OrganisationUnit> getOrganisationUnitsBetweenByStatusLastUpdated( boolean status, Date lastUpdated, int first, int max )
+ {
+ return organisationUnitStore.getBetweenByStatusLastUpdated( status, lastUpdated, first, max );
+ }
+
// -------------------------------------------------------------------------
// OrganisationUnitHierarchy
// -------------------------------------------------------------------------
=== 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-12-12 12:32:51 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/organisationunit/hibernate/HibernateOrganisationUnitStore.java 2012-12-13 10:47:58 +0000
@@ -27,18 +27,9 @@
* 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.Criteria;
import org.hibernate.Query;
import org.hibernate.criterion.Restrictions;
import org.hisp.dhis.common.hibernate.HibernateIdentifiableObjectStore;
@@ -50,6 +41,16 @@
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.Collection;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+
/**
* @author Kristian Nordal
*/
@@ -63,7 +64,7 @@
@Override
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
public Collection<OrganisationUnit> getAllOrganisationUnitsByStatus( boolean active )
{
Query query = getQuery( "from OrganisationUnit o where o.active is :active" );
@@ -79,7 +80,7 @@
}
@Override
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
public Collection<OrganisationUnit> getAllOrganisationUnitsByStatusLastUpdated( boolean active, Date lastUpdated )
{
return getCriteria().add( Restrictions.ge( "lastUpdated", lastUpdated ) ).add( Restrictions.eq( "active", active ) ).list();
@@ -92,7 +93,7 @@
}
@Override
- @SuppressWarnings( "unchecked" )
+ @SuppressWarnings("unchecked")
public Collection<OrganisationUnit> getRootOrganisationUnits()
{
return getQuery( "from OrganisationUnit o where o.parent is null" ).list();
@@ -208,6 +209,36 @@
return units;
}
+ @Override
+ public Collection<OrganisationUnit> getBetweenByStatus( boolean status, int first, int max )
+ {
+ Criteria criteria = getCriteria().add( Restrictions.eq( "active", status ) );
+ criteria.setFirstResult( first );
+ criteria.setMaxResults( max );
+
+ return criteria.list();
+ }
+
+ @Override
+ public Collection<OrganisationUnit> getBetweenByLastUpdated( Date lastUpdated, int first, int max )
+ {
+ Criteria criteria = getCriteria().add( Restrictions.ge( "lastUpdated", lastUpdated ) );
+ criteria.setFirstResult( first );
+ criteria.setMaxResults( max );
+
+ return criteria.list();
+ }
+
+ @Override
+ public Collection<OrganisationUnit> getBetweenByStatusLastUpdated( boolean status, Date lastUpdated, int first, int max )
+ {
+ Criteria criteria = getCriteria().add( Restrictions.ge( "lastUpdated", lastUpdated ) ).add( Restrictions.eq( "active", status ) );
+ criteria.setFirstResult( first );
+ criteria.setMaxResults( max );
+
+ return criteria.list();
+ }
+
// -------------------------------------------------------------------------
// OrganisationUnitHierarchy
// -------------------------------------------------------------------------