← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15685: if schema is not present, try and generate a more usable name (using JacksonXmlRootElement and Gu...

 

------------------------------------------------------------
revno: 15685
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2014-06-15 15:07:12 +0200
message:
  if schema is not present, try and generate a more usable name (using JacksonXmlRootElement and Guava CaseFormat)
modified:
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.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/DefaultSchemaService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java	2014-06-09 12:27:37 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java	2014-06-15 13:07:12 +0000
@@ -28,11 +28,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
+import com.google.common.base.CaseFormat;
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import org.hisp.dhis.system.util.ReflectionUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.OrderComparator;
+import org.springframework.util.StringUtils;
 
 import javax.annotation.PostConstruct;
 import java.util.Collections;
@@ -109,7 +112,9 @@
 
         klass = ReflectionUtils.getRealClass( klass );
 
-        schema = new Schema( klass, klass.getName(), klass.getName() );
+        String name = getName( klass );
+
+        schema = new Schema( klass, name, name );
         schema.setPropertyMap( Maps.newHashMap( propertyIntrospectorService.getPropertiesMap( schema.getKlass() ) ) );
 
         updateSelf( schema );
@@ -117,6 +122,21 @@
         return schema;
     }
 
+    private String getName( Class<?> klass )
+    {
+        if ( klass.isAnnotationPresent( JacksonXmlRootElement.class ) )
+        {
+            JacksonXmlRootElement rootElement = klass.getAnnotation( JacksonXmlRootElement.class );
+
+            if ( !StringUtils.isEmpty( rootElement.localName() ) )
+            {
+                return rootElement.localName();
+            }
+        }
+
+        return CaseFormat.UPPER_CAMEL.to( CaseFormat.LOWER_CAMEL, klass.getSimpleName() );
+    }
+
     @Override
     public Schema getSchemaBySingularName( String name )
     {