dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #17793
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 7219: Added getAllSorted and getByLastUpdatedSorted to generic stores and idObjectManager. Which means ...
------------------------------------------------------------
revno: 7219
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-06-06 15:31:45 +0200
message:
Added getAllSorted and getByLastUpdatedSorted to generic stores and idObjectManager. Which means that resources are rendered sorted in the webapi, regardless of the paging flag.
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/GenericStore.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-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.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 2012-05-29 21:23:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java 2012-06-06 13:31:45 +0000
@@ -116,6 +116,15 @@
List<T> getByLastUpdated( Date lastUpdated );
/**
+ * Returns all objects that are equal to or newer than given date.
+ * (sorted by name)
+ *
+ * @param lastUpdated Date to compare to.
+ * @return All objects equal or newer than given date.
+ */
+ List<T> getByLastUpdatedSorted( Date lastUpdated );
+
+ /**
* Returns the number of objects that are equal to or newer than given date.
*
* @param lastUpdated Date to compare to.
=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericStore.java 2012-03-22 12:34:46 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericStore.java 2012-06-06 13:31:45 +0000
@@ -96,6 +96,13 @@
Collection<T> getAll();
/**
+ * Retrieves a Collection of all objects (sorted on name).
+ *
+ * @return a Collection of all objects.
+ */
+ Collection<T> getAllSorted();
+
+ /**
* Removes the given object instance.
*
* @param object the object instance to delete.
=== 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 2012-05-27 21:50:00 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java 2012-06-06 13:31:45 +0000
@@ -53,12 +53,16 @@
<T extends IdentifiableObject> Collection<T> getAll( Class<T> clazz );
+ <T extends IdentifiableObject> Collection<T> getAllSorted( Class<T> clazz );
+
<T extends IdentifiableObject> Collection<T> getBetween( Class<T> clazz, int first, int max );
<T extends IdentifiableObject> Collection<T> getBetweenByName( Class<T> clazz, String name, int first, int max );
<T extends IdentifiableObject> Collection<T> getByLastUpdated( Class<T> clazz, Date lastUpdated );
+ <T extends IdentifiableObject> Collection<T> getByLastUpdatedSorted( Class<T> clazz, Date lastUpdated );
+
void delete( IdentifiableObject object );
<T extends IdentifiableObject> Map<String, T> getIdMap( Class<T> clazz, IdentifiableProperty property );
=== 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 2012-06-04 13:02:01 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java 2012-06-06 13:31:45 +0000
@@ -203,6 +203,22 @@
@Override
@SuppressWarnings( "unchecked" )
+ public <T extends IdentifiableObject> Collection<T> getAllSorted( Class<T> clazz )
+ {
+ GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
+
+ if ( store == null )
+ {
+ log.warn( "No IdentifiableObject store found for " + clazz + ", returning empty collection (getAllSorted)." );
+
+ return new ArrayList<T>();
+ }
+
+ return (Collection<T>) store.getAllSorted();
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
public <T extends IdentifiableObject> Collection<T> getBetween( Class<T> clazz, int first, int max )
{
GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
@@ -225,7 +241,7 @@
if ( store == null )
{
- log.warn( "No IdentifiableObject store found for " + clazz + ", returning empty collection (getBetween)." );
+ log.warn( "No IdentifiableObject store found for " + clazz + ", returning empty collection (getBetweenByName)." );
return new ArrayList<T>();
}
@@ -241,7 +257,7 @@
if ( store == null )
{
- log.warn( "No IdentifiableObject store found for " + clazz + ", returning empty collection (getBetween)." );
+ log.warn( "No IdentifiableObject store found for " + clazz + ", returning empty collection (getByLastUpdated)." );
return new ArrayList<T>();
}
@@ -251,6 +267,22 @@
@Override
@SuppressWarnings( "unchecked" )
+ public <T extends IdentifiableObject> Collection<T> getByLastUpdatedSorted( Class<T> clazz, Date lastUpdated )
+ {
+ GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
+
+ if ( store == null )
+ {
+ log.warn( "No IdentifiableObject store found for " + clazz + ", returning empty collection (getByLastUpdatedSorted)." );
+
+ return new ArrayList<T>();
+ }
+
+ return (Collection<T>) store.getByLastUpdatedSorted( lastUpdated );
+ }
+
+ @Override
+ @SuppressWarnings( "unchecked" )
public <T extends IdentifiableObject> Map<String, T> getIdMap( Class<T> clazz, IdentifiableProperty property )
{
Map<String, T> map = new HashMap<String, T>();
=== modified file 'dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java'
--- dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java 2012-05-29 21:23:47 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java 2012-06-06 13:31:45 +0000
@@ -270,6 +270,13 @@
}
@Override
+ @SuppressWarnings( "unchecked" )
+ public final Collection<T> getAllSorted()
+ {
+ return getCriteria().addOrder( Order.asc( "name" ) ).list();
+ }
+
+ @Override
public final void delete( T object )
{
sessionFactory.getCurrentSession().delete( object );
@@ -353,7 +360,14 @@
{
return getCriteria().add( Restrictions.ge( "lastUpdated", lastUpdated ) ).list();
}
-
+
+ @Override
+ @SuppressWarnings( "unchecked" )
+ public List<T> getByLastUpdatedSorted( Date lastUpdated )
+ {
+ return getCriteria().add( Restrictions.ge( "lastUpdated", lastUpdated ) ).addOrder( Order.asc( "name" ) ).list();
+ }
+
@Override
public long getCountByLastUpdated( Date lastUpdated )
{
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java 2012-06-06 12:48:05 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java 2012-06-06 13:31:45 +0000
@@ -166,7 +166,7 @@
if ( lastUpdated != null )
{
- entityList = new ArrayList<T>( manager.getByLastUpdated( getEntityClass(), lastUpdated ) );
+ entityList = new ArrayList<T>( manager.getByLastUpdatedSorted( getEntityClass(), lastUpdated ) );
}
else if ( options.hasPaging() )
{
@@ -179,7 +179,7 @@
}
else
{
- entityList = new ArrayList<T>( manager.getAll( getEntityClass() ) );
+ entityList = new ArrayList<T>( manager.getAllSorted( getEntityClass() ) );
}
return entityList;