← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16662: changed confusing naming in IdOjectManager, getCountByName/getCountByShortName was counting by LI...

 

------------------------------------------------------------
revno: 16662
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-09-09 11:59:32 +0700
message:
  changed confusing naming in IdOjectManager, getCountByName/getCountByShortName was counting by LIKE, renamed getCountLikeName, getCountLikeShortName, also added proper getCountEqName (getCountByName), getCountEqShortName (getCountByShortName) which counts on equality (useful where we don't have uniqueness on name/shortName)
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/IdentifiableObjectManager.java
  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/hibernate/HibernateIdentifiableObjectStore.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/IdentifiableObjectManagerTest.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/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	2014-09-08 13:02:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/GenericIdentifiableObjectStore.java	2014-09-09 04:59:32 +0000
@@ -167,6 +167,22 @@
     List<T> getAllOrderedLastUpdated( int first, int max );
 
     /**
+     * Gets the count of objects which name is equal the given name.
+     *
+     * @param name the name which result object names must be like.
+     * @return the count of objects.
+     */
+    int getCountEqName( String name );
+
+    /**
+     * Gets the count of objects which shortName is equal the given shortName.
+     *
+     * @param shortName the shortName which result object shortNames must be like.
+     * @return the count of objects.
+     */
+    int getCountEqShortName( String shortName );
+
+    /**
      * Gets the count of objects which name is like the given name.
      *
      * @param name the name which result object names must be like.

=== 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-09-08 13:02:43 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/common/IdentifiableObjectManager.java	2014-09-09 04:59:32 +0000
@@ -110,6 +110,10 @@
 
     <T extends IdentifiableObject> int getCountByShortName( Class<T> clazz, String shortName );
 
+    <T extends IdentifiableObject> int getCountLikeName( Class<T> clazz, String name );
+
+    <T extends IdentifiableObject> int getCountLikeShortName( Class<T> clazz, String shortName );
+
     // -------------------------------------------------------------------------
     // NO ACL
     // -------------------------------------------------------------------------

=== 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-09-08 13:02:43 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/DefaultIdentifiableObjectManager.java	2014-09-09 04:59:32 +0000
@@ -256,7 +256,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public <T extends IdentifiableObject> Collection<T> getAllByName( Class<T> clazz, String name )
     {
         GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
@@ -270,7 +270,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public <T extends IdentifiableObject> Collection<T> getAllByNameIgnoreCase( Class<T> clazz, String name )
     {
         GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
@@ -298,7 +298,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public <T extends IdentifiableObject> Collection<T> getAllSortedByLastUpdated( Class<T> clazz )
     {
         GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
@@ -326,12 +326,51 @@
     }
 
     @Override
+    public <T extends IdentifiableObject> int getCount( Class<T> clazz )
+    {
+        GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
+
+        if ( store != null )
+        {
+            return store.getCount();
+        }
+
+        return 0;
+    }
+
+    @Override
     public <T extends IdentifiableObject> int getCountByName( Class<T> clazz, String name )
     {
         GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
 
         if ( store != null )
         {
+            return store.getCountEqName( name );
+        }
+
+        return 0;
+    }
+
+    @Override
+    public <T extends IdentifiableObject> int getCountByShortName( Class<T> clazz, String shortName )
+    {
+        GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
+
+        if ( store != null )
+        {
+            return store.getCountEqShortName( shortName );
+        }
+
+        return 0;
+    }
+
+    @Override
+    public <T extends IdentifiableObject> int getCountLikeName( Class<T> clazz, String name )
+    {
+        GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
+
+        if ( store != null )
+        {
             return store.getCountLikeName( name );
         }
 
@@ -339,7 +378,7 @@
     }
 
     @Override
-    public <T extends IdentifiableObject> int getCountByShortName( Class<T> clazz, String shortName )
+    public <T extends IdentifiableObject> int getCountLikeShortName( Class<T> clazz, String shortName )
     {
         GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
 
@@ -590,19 +629,6 @@
     }
 
     @Override
-    public <T extends IdentifiableObject> int getCount( Class<T> clazz )
-    {
-        GenericIdentifiableObjectStore<IdentifiableObject> store = getIdentifiableObjectStore( clazz );
-
-        if ( store != null )
-        {
-            return store.getCount();
-        }
-
-        return 0;
-    }
-
-    @Override
     @SuppressWarnings("unchecked")
     public <T extends IdentifiableObject> T getNoAcl( Class<T> clazz, String uid )
     {

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java	2014-09-08 13:02:43 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/common/hibernate/HibernateIdentifiableObjectStore.java	2014-09-09 04:59:32 +0000
@@ -178,7 +178,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getAllEqName( String name )
     {
         return getSharingCriteria()
@@ -188,7 +188,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getAllEqNameIgnoreCase( String name )
     {
         return getSharingCriteria()
@@ -198,7 +198,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getAllEqShortName( String shortName )
     {
         return getSharingCriteria()
@@ -208,7 +208,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getAllEqShortNameIgnoreCase( String shortName )
     {
         return getSharingCriteria()
@@ -218,7 +218,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getAllLikeName( String name )
     {
         return getSharingCriteria()
@@ -228,7 +228,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getAllLikeName( String name, int first, int max )
     {
         return getSharingCriteria()
@@ -240,7 +240,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getAllLikeShortName( String shortName )
     {
         if ( NameableObject.class.isAssignableFrom( clazz ) )
@@ -255,7 +255,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getAllOrderedName()
     {
         return getSharingCriteria()
@@ -264,7 +264,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getAllOrderedName( int first, int max )
     {
         return getSharingCriteria()
@@ -274,7 +274,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getAllOrderedLastUpdated()
     {
         return getSharingCriteria()
@@ -283,7 +283,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getAllOrderedLastUpdated( int first, int max )
     {
         return getSharingCriteria()
@@ -293,6 +293,24 @@
     }
 
     @Override
+    public int getCountEqName( String name )
+    {
+        return ((Number) getSharingCriteria()
+            .add( Restrictions.eq( "name", name ).ignoreCase() )
+            .setProjection( Projections.countDistinct( "id" ) )
+            .uniqueResult()).intValue();
+    }
+
+    @Override
+    public int getCountEqShortName( String shortName )
+    {
+        return ((Number) getSharingCriteria()
+            .add( Restrictions.eq( "shortName", shortName ).ignoreCase() )
+            .setProjection( Projections.countDistinct( "id" ) )
+            .uniqueResult()).intValue();
+    }
+
+    @Override
     public int getCountLikeName( String name )
     {
         return ((Number) getSharingCriteria()
@@ -342,7 +360,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getAllGeLastUpdated( Date lastUpdated )
     {
         Query query = sharingEnabled() ? getQueryAllGeLastUpdatedAcl( lastUpdated ) : getQueryAllGeLastUpdated( lastUpdated );
@@ -374,7 +392,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getAllGeCreated( Date created )
     {
         Query query = sharingEnabled() ? getQueryAllGeCreatedAcl( created ) : getQueryAllGeCreated( created );
@@ -406,7 +424,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getAllGeLastUpdatedOrderedName( Date lastUpdated )
     {
         Query query = sharingEnabled() ? getQueryAllGeLastUpdatedOrderedNameAcl( lastUpdated ) : getQueryAllGeLastUpdatedOrderedName( lastUpdated );
@@ -438,7 +456,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getByUser( User user )
     {
         Query query = getQuery( "from " + clazz.getName() + " c where user = :user" );
@@ -448,7 +466,7 @@
     }
 
     @Override
-    @SuppressWarnings( "unchecked" )
+    @SuppressWarnings("unchecked")
     public List<T> getByDataDimension( boolean dataDimension )
     {
         Query query = getQuery( "from " + clazz.getName() + " c where c.dataDimension = :dataDimension" );

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/IdentifiableObjectManagerTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/IdentifiableObjectManagerTest.java	2014-09-09 04:35:55 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/common/IdentifiableObjectManagerTest.java	2014-09-09 04:59:32 +0000
@@ -121,10 +121,10 @@
         identifiableObjectManager.save( createDataElement( 'C' ) );
         identifiableObjectManager.save( createDataElement( 'D' ) );
 
-        assertEquals( 1, identifiableObjectManager.getCountByName( DataElement.class, "DataElementA" ) );
-        assertEquals( 1, identifiableObjectManager.getCountByName( DataElement.class, "DataElementB" ) );
-        assertEquals( 1, identifiableObjectManager.getCountByName( DataElement.class, "DataElementC" ) );
-        assertEquals( 1, identifiableObjectManager.getCountByName( DataElement.class, "DataElementD" ) );
+        assertEquals( 1, identifiableObjectManager.getCountLikeName( DataElement.class, "DataElementA" ) );
+        assertEquals( 1, identifiableObjectManager.getCountLikeName( DataElement.class, "DataElementB" ) );
+        assertEquals( 1, identifiableObjectManager.getCountLikeName( DataElement.class, "DataElementC" ) );
+        assertEquals( 1, identifiableObjectManager.getCountLikeName( DataElement.class, "DataElementD" ) );
     }
 
     @Test
@@ -178,8 +178,8 @@
         identifiableObjectManager.save( createDataElement( 'C' ) );
         identifiableObjectManager.save( createDataElement( 'D' ) );
 
-        assertEquals( 4, identifiableObjectManager.getCountByName( DataElement.class, "DataElement" ) );
-        assertEquals( 4, identifiableObjectManager.getCountByName( DataElement.class, "dataElement" ) );
+        assertEquals( 4, identifiableObjectManager.getCountLikeName( DataElement.class, "DataElement" ) );
+        assertEquals( 4, identifiableObjectManager.getCountLikeName( DataElement.class, "dataElement" ) );
 
         assertEquals( 4, identifiableObjectManager.getLikeName( DataElement.class, "DataElement" ).size() );
         assertEquals( 4, identifiableObjectManager.getLikeName( DataElement.class, "dataElement" ).size() );
@@ -193,8 +193,8 @@
         identifiableObjectManager.save( createDataElement( 'C' ) );
         identifiableObjectManager.save( createDataElement( 'D' ) );
 
-        assertEquals( 4, identifiableObjectManager.getCountByShortName( DataElement.class, "DataElementShort" ) );
-        assertEquals( 4, identifiableObjectManager.getCountByShortName( DataElement.class, "dataElementSHORT" ) );
+        assertEquals( 4, identifiableObjectManager.getCountLikeShortName( DataElement.class, "DataElementShort" ) );
+        assertEquals( 4, identifiableObjectManager.getCountLikeShortName( DataElement.class, "dataElementSHORT" ) );
 
         assertEquals( 4, identifiableObjectManager.getLikeShortName( DataElement.class, "DataElementShort" ).size() );
         assertEquals( 4, identifiableObjectManager.getLikeShortName( DataElement.class, "dataElementSHORT" ).size() );
@@ -291,7 +291,7 @@
         identifiableObjectManager.save( dataElement );
 
         dataElement.setUser( user );
-        dataElement.setPublicAccess( AccessStringHelper.newInstance().build() );
+        dataElement.setPublicAccess( AccessStringHelper.DEFAULT );
         sessionFactory.getCurrentSession().update( dataElement );
 
         identifiableObjectManager.delete( dataElement );
@@ -329,7 +329,7 @@
         for ( DataElement dataElement : dataElements )
         {
             dataElement.setUser( user );
-            dataElement.setPublicAccess( AccessStringHelper.newInstance().build() );
+            dataElement.setPublicAccess( AccessStringHelper.DEFAULT );
 
             sessionFactory.getCurrentSession().update( dataElement );
         }
@@ -365,7 +365,7 @@
             dataElement.setPublicAccess( AccessStringHelper.newInstance().build() );
 
             UserGroupAccess userGroupAccess = new UserGroupAccess();
-            userGroupAccess.setAccess( AccessStringHelper.newInstance().enable( AccessStringHelper.Permission.READ ).build() );
+            userGroupAccess.setAccess( AccessStringHelper.READ );
             userGroupAccess.setUserGroup( userGroup );
 
             sessionFactory.getCurrentSession().save( userGroupAccess );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-08-29 16:08:39 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AbstractCrudController.java	2014-09-09 04:59:32 +0000
@@ -169,7 +169,7 @@
 
             if ( name != null )
             {
-                int count = manager.getCountByName( getEntityClass(), name );
+                int count = manager.getCountLikeName( getEntityClass(), name );
 
                 Pager pager = new Pager( options.getPage(), count, options.getPageSize() );
                 metaData.setPager( pager );