← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17833: extend hibgenstor and idobjectmanager to include methods for getting full list of entities withou...

 

------------------------------------------------------------
revno: 17833
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-12-30 10:38:00 +0100
message:
  extend hibgenstor and idobjectmanager to include methods for getting full list of entities without using acl
modified:
  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


--
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/GenericStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericStore.java	2014-12-12 17:48:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericStore.java	2014-12-30 09:38:00 +0000
@@ -100,4 +100,10 @@
      * @return the count of objects.
      */
     int getCount();
+
+    List<T> getAllNoAcl();
+
+    List<T> getAllNoAcl( int first, int max );
+
+    int getCountNoAcl();
 }

=== 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-12 17:48:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java	2014-12-30 09:38:00 +0000
@@ -94,7 +94,7 @@
     <T extends IdentifiableObject> Collection<T> getByLastUpdatedSorted( Class<T> clazz, Date lastUpdated );
 
     <T extends IdentifiableObject> Collection<T> getByCreatedSorted( Class<T> clazz, Date created );
-    
+
     <T extends IdentifiableObject> Date getLastUpdated( Class<T> clazz );
 
     void delete( IdentifiableObject object );
@@ -134,4 +134,10 @@
     <T extends IdentifiableObject> T getNoAcl( Class<T> clazz, String uid );
 
     <T extends IdentifiableObject> void updateNoAcl( T object );
+
+    <T extends IdentifiableObject> int getCountNoAcl( Class<T> clazz );
+
+    <T extends IdentifiableObject> Collection<T> getAllNoAcl( Class<T> clazz );
+
+    <T extends IdentifiableObject> Collection<T> getBetweenNoAcl( Class<T> clazz, int first, int max );
 }

=== 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-12 17:48:12 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java	2014-12-30 09:38:00 +0000
@@ -743,6 +743,47 @@
         }
     }
 
+    @Override
+    public <T extends IdentifiableObject> int getCountNoAcl( Class<T> clazz )
+    {
+        GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
+
+        if ( store != null )
+        {
+            return store.getCountNoAcl();
+        }
+
+        return 0;
+    }
+
+    @Override
+    @SuppressWarnings( "unchecked" )
+    public <T extends IdentifiableObject> Collection<T> getAllNoAcl( Class<T> clazz )
+    {
+        GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
+
+        if ( store == null )
+        {
+            return new ArrayList<>();
+        }
+
+        return (Collection<T>) store.getAllNoAcl();
+    }
+
+    @Override
+    @SuppressWarnings( "unchecked" )
+    public <T extends IdentifiableObject> Collection<T> getBetweenNoAcl( Class<T> clazz, int first, int max )
+    {
+        GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
+
+        if ( store == null )
+        {
+            return new ArrayList<>();
+        }
+
+        return (Collection<T>) store.getAllNoAcl( first, max );
+    }
+
     //--------------------------------------------------------------------------
     // Supportive methods
     //--------------------------------------------------------------------------

=== 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	2014-12-29 13:13:12 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2014-12-30 09:38:00 +0000
@@ -426,6 +426,31 @@
             .uniqueResult()).intValue();
     }
 
+    @Override
+    @SuppressWarnings( "unchecked" )
+    public final List<T> getAllNoAcl()
+    {
+        return getCriteria().list();
+    }
+
+    @Override
+    @SuppressWarnings( "unchecked" )
+    public final List<T> getAllNoAcl( int first, int max )
+    {
+        return getCriteria()
+            .setFirstResult( first )
+            .setMaxResults( max )
+            .list();
+    }
+
+    @Override
+    public int getCountNoAcl()
+    {
+        return ((Number) getCriteria()
+            .setProjection( Projections.countDistinct( "id" ) )
+            .uniqueResult()).intValue();
+    }
+
     //----------------------------------------------------------------------------------------------------------------
     // Helpers
     //----------------------------------------------------------------------------------------------------------------