← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 8735: Removed some boilerplate code

 

------------------------------------------------------------
revno: 8735
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2012-10-26 14:49:31 +0200
message:
  Removed some boilerplate code
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.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/GenericIdentifiableObjectStore.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java	2012-10-26 12:27:47 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java	2012-10-26 12:49:31 +0000
@@ -151,4 +151,28 @@
      * @return a list of objects.
      */
     Collection<Map> getAccessibleByUser( User user );
+
+    /**
+     * Retrieves objects which are accessible to the given user, which includes
+     * public objects and objects owned by this user, which name is like the
+     * given name.
+     * 
+     * @param user the user.
+     * @param name the name.
+     * @return a list of objects.
+     */
+    List<Map> getAccessibleByName( User user, String name );
+
+    /**
+     * Retrieves objects which are accessible to the given user, which includes
+     * public objects and objects owned by this user, which name is like the
+     * given name, limited by the given offset and max result.
+     * 
+     * @param user the user.
+     * @param name the name.
+     * @param first the first result object to return.
+     * @param max the max number of result objects to return. 
+     * @return a list of objects.
+     */
+    List<Map> getAccessibleBetweenByName( User user, String name, 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	2012-10-18 13:04:28 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java	2012-10-26 12:49:31 +0000
@@ -83,10 +83,6 @@
         {
             store.save( object );
         }
-        else
-        {
-            log.warn( "No IdentifiableObject store found for " + object.getClass() + " (save)." );
-        }
     }
 
     @Override
@@ -98,10 +94,6 @@
         {
             store.update( object );
         }
-        else
-        {
-            log.warn( "No IdentifiableObject store found for " + object.getClass() + " (update)." );
-        }
     }
 
     @Override
@@ -113,10 +105,6 @@
         {
             store.delete( object );
         }
-        else
-        {
-            log.warn( "No IdentifiableObject store found for " + object.getClass() + " (delete)." );
-        }
     }
 
     @Override
@@ -127,8 +115,6 @@
 
         if ( store == null )
         {
-            log.warn( "No IdentifiableObject store found for " + clazz + ", returning null." );
-
             return null;
         }
 
@@ -143,8 +129,6 @@
 
         if ( store == null )
         {
-            log.warn( "No IdentifiableObject store found for " + clazz + ", returning null (getByCode)." );
-
             return null;
         }
 
@@ -159,8 +143,6 @@
 
         if ( store == null )
         {
-            log.warn( "No IdentifiableObject store found for " + clazz + ", returning null (getByName)." );
-
             return null;
         }
 
@@ -193,8 +175,6 @@
 
         if ( store == null )
         {
-            log.warn( "No IdentifiableObject store found for " + clazz + ", returning empty collection (getAll)." );
-
             return new ArrayList<T>();
         }
 
@@ -209,8 +189,6 @@
 
         if ( store == null )
         {
-            log.warn( "No IdentifiableObject store found for " + clazz + ", returning empty collection (getAllSorted)." );
-
             return new ArrayList<T>();
         }
 
@@ -225,8 +203,6 @@
 
         if ( store == null )
         {
-            log.warn( "No IdentifiableObject store found for " + clazz + ", returning empty collection (getBetween)." );
-
             return new ArrayList<T>();
         }
 
@@ -241,8 +217,6 @@
 
         if ( store == null )
         {
-            log.warn( "No IdentifiableObject store found for " + clazz + ", returning empty collection (getBetweenByName)." );
-
             return new ArrayList<T>();
         }
 
@@ -257,8 +231,6 @@
 
         if ( store == null )
         {
-            log.warn( "No IdentifiableObject store found for " + clazz + ", returning empty collection (getByLastUpdated)." );
-
             return new ArrayList<T>();
         }
 
@@ -273,8 +245,6 @@
 
         if ( store == null )
         {
-            log.warn( "No IdentifiableObject store found for " + clazz + ", returning empty collection (getByLastUpdatedSorted)." );
-
             return new ArrayList<T>();
         }
 
@@ -291,8 +261,6 @@
 
         if ( store == null )
         {
-            log.warn( "No IdentifiableObject store found for " + clazz + ", returning empty map (getIdMap)." );
-
             return map;
         }
 
@@ -426,10 +394,6 @@
         {
             return store.getCount();
         }
-        else
-        {
-            log.warn( "No IdentifiableObject store found for " + clazz + " (getCount)." );
-        }
 
         return 0;
     }
@@ -440,6 +404,8 @@
 
         if ( store == null )
         {
+            log.warn( "No IdentifiableObjectStore found for class: " + clazz );
+            
             store = identifiableObjectStoreMap.get( clazz.getSuperclass() );
         }
 
@@ -452,6 +418,8 @@
 
         if ( store == null )
         {
+            log.warn( "No NameableObjectStore found for class: " + clazz );
+            
             store = nameableObjectStoreMap.get( clazz.getSuperclass() );
         }
 

=== 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-10-26 12:27:47 +0000
+++ dhis-2/dhis-support/dhis-support-hibernate/src/main/java/org/hisp/dhis/hibernate/HibernateGenericStore.java	2012-10-26 12:49:31 +0000
@@ -389,4 +389,26 @@
             Restrictions.eq( "user", user ),
             Restrictions.isNull( "user" ) ) ).list();
     }
+
+    @SuppressWarnings( "unchecked" )
+    public List<Map> getAccessibleByName( User user, String name )
+    {
+        Criteria criteria = getCriteria();
+        criteria.add( Restrictions.ilike( "name", "%" + name + "%" ) );
+        criteria.add( Restrictions.or( Restrictions.eq( "user", user ), Restrictions.isNull( "user" ) ) );
+        criteria.addOrder( Order.asc( "name" ) );
+        return criteria.list();
+    }
+    
+    @SuppressWarnings( "unchecked" )
+    public List<Map> getAccessibleBetweenByName( User user, String name, int first, int max )
+    {
+        Criteria criteria = getCriteria();
+        criteria.add( Restrictions.ilike( "name", "%" + name + "%" ) );
+        criteria.add( Restrictions.or( Restrictions.eq( "user", user ), Restrictions.isNull( "user" ) ) );
+        criteria.addOrder( Order.asc( "name" ) );
+        criteria.setFirstResult( first );
+        criteria.setMaxResults( max );
+        return criteria.list();
+    }
 }