← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9016: Report table, fixed bug. Made sure correct class type is detected even if hibernate returns a pro...

 

------------------------------------------------------------
revno: 9016
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2012-11-14 10:14:44 +0100
message:
  Report table, fixed bug. Made sure correct class type is detected even if hibernate returns a proxy when generating report tables.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.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/reporttable/ReportTable.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2012-10-01 10:50:34 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/reporttable/ReportTable.java	2012-11-14 09:14:44 +0000
@@ -616,12 +616,12 @@
 
         for ( NameableObject object : objects1 )
         {
-            identifiers.add( getIdentifier( object.getClass(), object.getId() ) );
+            identifiers.add( getIdentifier( getNameableClass( object.getClass() ), object.getId() ) );
         }
 
         for ( NameableObject object : objects2 )
         {
-            identifiers.add( getIdentifier( object.getClass(), object.getId() ) );
+            identifiers.add( getIdentifier( getNameableClass( object.getClass() ), object.getId() ) );
         }
 
         return getIdentifier( identifiers.toArray( SRT ) );
@@ -636,7 +636,7 @@
 
         for ( NameableObject object : objects )
         {
-            identifiers.add( getIdentifier( object.getClass(), object.getId() ) );
+            identifiers.add( getIdentifier( getNameableClass( object.getClass() ), object.getId() ) );
         }
 
         identifiers.add( getIdentifier( clazz, id ) );
@@ -904,6 +904,25 @@
             throw new IllegalStateException( falseMessage );
         }
     }
+    
+    /**
+     * Gets the real Nameable class in case of a proxy.
+     */
+    @SuppressWarnings("unchecked")
+    public static Class<? extends NameableObject> getNameableClass( Class<?> clazz )
+    {
+        while ( clazz != null )
+        {       
+            if ( BaseNameableObject.class.equals( clazz.getSuperclass() ) )
+            {
+                return (Class<? extends NameableObject>) clazz;
+            }
+            
+            clazz = clazz.getSuperclass();
+        }
+        
+        throw new IllegalStateException( "Class is not a Nameable object: " + clazz );
+    }    
 
     // -------------------------------------------------------------------------
     // Equals and hashCode

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java	2012-07-30 10:56:25 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ReflectionUtils.java	2012-11-14 09:14:44 +0000
@@ -391,10 +391,12 @@
         try
         {
             return (T) method.invoke( target, args );
-        } catch ( InvocationTargetException e )
+        } 
+        catch ( InvocationTargetException e )
         {
             throw new RuntimeException( e );
-        } catch ( IllegalAccessException e )
+        } 
+        catch ( IllegalAccessException e )
         {
             throw new RuntimeException( e );
         }