← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16428: minor refactor in NodePropertyIntrospectorService

 

------------------------------------------------------------
revno: 16428
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-08-16 23:27:06 +0700
message:
  minor refactor in NodePropertyIntrospectorService
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/NodePropertyIntrospectorService.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-16 15:59:51 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/NodePropertyIntrospectorService.java	2014-08-16 16:27:06 +0000
@@ -117,77 +117,17 @@
             if ( field.isAnnotationPresent( NodeSimple.class ) )
             {
                 NodeSimple nodeSimple = field.getAnnotation( NodeSimple.class );
-                property.setSimple( true );
-                property.setAttribute( nodeSimple.isAttribute() );
-                property.setPersisted( nodeSimple.isPersisted() );
-                property.setNamespace( nodeSimple.namespace() );
-                property.setWritable( nodeSimple.isWritable() );
-                property.setReadable( nodeSimple.isReadable() );
-
-                if ( !nodeSimple.isWritable() )
-                {
-                    property.setSetterMethod( null );
-                }
-
-                if ( !nodeSimple.isReadable() )
-                {
-                    property.setGetterMethod( null );
-                }
-
-                if ( !StringUtils.isEmpty( nodeSimple.value() ) )
-                {
-                    property.setName( nodeSimple.value() );
-                }
+                handleNodeSimple( nodeSimple, property );
             }
             else if ( field.isAnnotationPresent( NodeComplex.class ) )
             {
                 NodeComplex nodeComplex = field.getAnnotation( NodeComplex.class );
-                property.setSimple( false );
-                property.setNamespace( nodeComplex.namespace() );
-                property.setWritable( nodeComplex.isWritable() );
-                property.setReadable( nodeComplex.isReadable() );
-
-                if ( !nodeComplex.isWritable() )
-                {
-                    property.setSetterMethod( null );
-                }
-
-                if ( !nodeComplex.isReadable() )
-                {
-                    property.setGetterMethod( null );
-                }
-
-                if ( !StringUtils.isEmpty( nodeComplex.value() ) )
-                {
-                    property.setName( nodeComplex.value() );
-                }
+                handleNodeComplex( nodeComplex, property );
             }
             else if ( field.isAnnotationPresent( NodeCollection.class ) )
             {
                 NodeCollection nodeCollection = field.getAnnotation( NodeCollection.class );
-                property.setCollectionWrapping( nodeCollection.useWrapping() );
-                property.setWritable( nodeCollection.isWritable() );
-                property.setReadable( nodeCollection.isReadable() );
-
-                if ( !nodeCollection.isWritable() )
-                {
-                    property.setSetterMethod( null );
-                }
-
-                if ( !nodeCollection.isReadable() )
-                {
-                    property.setGetterMethod( null );
-                }
-
-                if ( !StringUtils.isEmpty( nodeCollection.value() ) )
-                {
-                    property.setCollectionName( nodeCollection.value() );
-                }
-
-                if ( !StringUtils.isEmpty( nodeCollection.itemName() ) )
-                {
-                    property.setName( nodeCollection.itemName() );
-                }
+                handleNodeCollection( nodeCollection, property );
             }
 
             propertyMap.put( property.getName(), property );
@@ -196,6 +136,81 @@
         return propertyMap;
     }
 
+    private void handleNodeSimple( NodeSimple nodeSimple, Property property )
+    {
+        property.setSimple( true );
+        property.setAttribute( nodeSimple.isAttribute() );
+        property.setPersisted( nodeSimple.isPersisted() );
+        property.setNamespace( nodeSimple.namespace() );
+        property.setWritable( nodeSimple.isWritable() );
+        property.setReadable( nodeSimple.isReadable() );
+
+        if ( !nodeSimple.isWritable() )
+        {
+            property.setSetterMethod( null );
+        }
+
+        if ( !nodeSimple.isReadable() )
+        {
+            property.setGetterMethod( null );
+        }
+
+        if ( !StringUtils.isEmpty( nodeSimple.value() ) )
+        {
+            property.setName( nodeSimple.value() );
+        }
+    }
+
+    private void handleNodeComplex( NodeComplex nodeComplex, Property property )
+    {
+        property.setSimple( false );
+        property.setNamespace( nodeComplex.namespace() );
+        property.setWritable( nodeComplex.isWritable() );
+        property.setReadable( nodeComplex.isReadable() );
+
+        if ( !nodeComplex.isWritable() )
+        {
+            property.setSetterMethod( null );
+        }
+
+        if ( !nodeComplex.isReadable() )
+        {
+            property.setGetterMethod( null );
+        }
+
+        if ( !StringUtils.isEmpty( nodeComplex.value() ) )
+        {
+            property.setName( nodeComplex.value() );
+        }
+    }
+
+    private void handleNodeCollection( NodeCollection nodeCollection, Property property )
+    {
+        property.setCollectionWrapping( nodeCollection.useWrapping() );
+        property.setWritable( nodeCollection.isWritable() );
+        property.setReadable( nodeCollection.isReadable() );
+
+        if ( !nodeCollection.isWritable() )
+        {
+            property.setSetterMethod( null );
+        }
+
+        if ( !nodeCollection.isReadable() )
+        {
+            property.setGetterMethod( null );
+        }
+
+        if ( !StringUtils.isEmpty( nodeCollection.value() ) )
+        {
+            property.setCollectionName( nodeCollection.value() );
+        }
+
+        if ( !StringUtils.isEmpty( nodeCollection.itemName() ) )
+        {
+            property.setName( nodeCollection.itemName() );
+        }
+    }
+
     private Method getGetter( Class<?> klass, Field field )
     {
         return getMethodWithPrefix( klass, field, Lists.newArrayList( "get", "is", "has" ), false );