dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #32208
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16451: Use @NodeRoot to fetch itemName if available and no itemName is set on a @NodeCollection
------------------------------------------------------------
revno: 16451
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-08-20 12:24:14 +0700
message:
Use @NodeRoot to fetch itemName if available and no itemName is set on a @NodeCollection
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/NodePropertyIntrospectorService.java
dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldCollectionNodePropertyIntrospectorServiceTest.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-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/NodePropertyIntrospectorService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/NodePropertyIntrospectorService.java 2014-08-17 13:37:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/NodePropertyIntrospectorService.java 2014-08-20 05:24:14 +0000
@@ -38,6 +38,7 @@
import org.hisp.dhis.node.annotation.NodeAnnotation;
import org.hisp.dhis.node.annotation.NodeCollection;
import org.hisp.dhis.node.annotation.NodeComplex;
+import org.hisp.dhis.node.annotation.NodeRoot;
import org.hisp.dhis.node.annotation.NodeSimple;
import org.hisp.dhis.system.util.ReflectionUtils;
import org.springframework.util.StringUtils;
@@ -224,6 +225,18 @@
{
property.setName( nodeCollection.itemName() );
}
+ else // if itemName is not set, check to see if itemKlass have a @RootNode with a name
+ {
+ if ( property.getItemKlass() != null && property.getItemKlass().isAnnotationPresent( NodeRoot.class ) )
+ {
+ NodeRoot nodeRoot = property.getItemKlass().getAnnotation( NodeRoot.class );
+
+ if ( !StringUtils.isEmpty( nodeRoot.value() ) )
+ {
+ property.setName( nodeRoot.value() );
+ }
+ }
+ }
}
private Method getGetter( Class<?> klass, Field field )
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldCollectionNodePropertyIntrospectorServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldCollectionNodePropertyIntrospectorServiceTest.java 2014-08-17 13:37:34 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/schema/FieldCollectionNodePropertyIntrospectorServiceTest.java 2014-08-20 05:24:14 +0000
@@ -29,6 +29,7 @@
*/
import org.hisp.dhis.node.annotation.NodeCollection;
+import org.hisp.dhis.node.annotation.NodeRoot;
import org.hisp.dhis.node.annotation.NodeSimple;
import org.junit.Before;
import org.junit.Test;
@@ -39,7 +40,7 @@
import static org.junit.Assert.*;
-class Item
+@NodeRoot( value = "collectionItem" ) class Item
{
@NodeSimple
private String value;
@@ -160,10 +161,16 @@
@Test
public void testItemName()
{
- assertEquals( "items1", propertyMap.get( "items1" ).getName() );
+ assertEquals( "collectionItem", propertyMap.get( "items1" ).getName() );
assertEquals( "items1", propertyMap.get( "items1" ).getCollectionName() );
assertEquals( "item", propertyMap.get( "items" ).getName() );
assertEquals( "items", propertyMap.get( "items" ).getCollectionName() );
}
+
+ @Test
+ public void testItemKlass()
+ {
+ assertTrue( Item.class.equals( propertyMap.get( "items1" ).getItemKlass() ) );
+ }
}