=== 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 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 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 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 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 getOrganisationUnitsByNameAndGroups( String name, Collection 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 getOrganisationUnitsByNameAndGroups( String name, Collection groups, OrganisationUnit parent, boolean limit ); @@ -265,9 +293,9 @@ void filterOrganisationUnitsWithoutData( Collection organisationUnits ); Collection getOrganisationUnitsBetween( int first, int max ); - + Collection 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 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 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 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 getOrganisationUnitsByNameAndGroups( String query, Collection 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 getAllOrganisationUnitsByStatus( boolean active ) + { + return organisationUnitStore.getAllOrganisationUnitsByStatus( active ); + } + + @Override + public Collection getAllOrganisationUnitsByLastUpdated( Date lastUpdated ) + { + return organisationUnitStore.getAllOrganisationUnitsByLastUpdated( lastUpdated ); + } + + @Override + public Collection getAllOrganisationUnitsByStatusLastUpdated( boolean active, Date lastUpdated ) + { + return organisationUnitStore.getAllOrganisationUnitsByStatusLastUpdated( active, lastUpdated ); + } + public void searchOrganisationUnitByName( List orgUnits, String key ) { Iterator iterator = orgUnits.iterator(); @@ -422,7 +440,7 @@ return organisationUnitStore.getOrganisationUnitsByNameAndGroups( query, groups, limit ); } - @SuppressWarnings( "unchecked" ) + @SuppressWarnings("unchecked") public Collection getOrganisationUnitsByNameAndGroups( String name, Collection 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 getAllOrganisationUnitsByStatus( boolean active ) + { + Query query = getQuery( "from OrganisationUnit o where o.active is :active" ); + query.setParameter( "active", active ); + + return query.list(); + } + + @Override + public Collection getAllOrganisationUnitsByLastUpdated( Date lastUpdated ) + { + return getByLastUpdated( lastUpdated ); + } + + @Override + @SuppressWarnings( "unchecked" ) + public Collection 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 getRootOrganisationUnits() { return getQuery( "from OrganisationUnit o where o.parent is null" ).list(); } - @SuppressWarnings( "unchecked" ) + @Override + @SuppressWarnings("unchecked") public Collection getOrganisationUnitsWithoutGroups() { return getQuery( "from OrganisationUnit o where o.groups.size = 0" ).list(); } - @SuppressWarnings( "unchecked" ) + @Override + @SuppressWarnings("unchecked") public Collection getOrganisationUnitsByNameAndGroups( String query, Collection groups, boolean limit ) { @@ -110,7 +129,7 @@ } Query q = sessionFactory.getCurrentSession().createQuery( hql.toString() ); - + if ( query != null ) { q.setString( "expression", "%" + query.toLowerCase() + "%" );