← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 16520: update Schema with displayName, falls back to name if not present. Use displayName in dxf2 metada...

 

------------------------------------------------------------
revno: 16520
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-08-26 17:30:33 +0700
message:
  update Schema with displayName, falls back to name if not present. Use displayName in dxf2 metadata export.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java
  dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataExport.vm


--
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/schema/Schema.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java	2014-08-04 06:35:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java	2014-08-26 10:30:33 +0000
@@ -91,6 +91,11 @@
     private String name;
 
     /**
+     * A beautified (and possibly translated) name that can be used in UI.
+     */
+    private String displayName;
+
+    /**
      * This will normally be set to equal plural, and is normally used as a wrapper for a collection of
      * instances of this klass type.
      */
@@ -227,6 +232,18 @@
 
     @JsonProperty
     @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
+    public String getDisplayName()
+    {
+        return displayName != null ? displayName : name;
+    }
+
+    public void setDisplayName( String displayName )
+    {
+        this.displayName = displayName;
+    }
+
+    @JsonProperty
+    @JacksonXmlProperty( namespace = DxfNamespaces.DXF_2_0 )
     public boolean isShareable()
     {
         return shareable;

=== 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-07-30 07:57:06 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java	2014-08-26 10:30:33 +0000
@@ -67,6 +67,7 @@
 
             if ( schema.getProperties().isEmpty() )
             {
+                schema.setDisplayName( beautify( schema.getName() ) );
                 schema.setPropertyMap( Maps.newHashMap( propertyIntrospectorService.getPropertiesMap( schema.getKlass() ) ) );
             }
 
@@ -115,6 +116,7 @@
         String name = getName( klass );
 
         schema = new Schema( klass, name, name + "s" );
+        schema.setDisplayName( beautify( schema.getName() ) );
         schema.setPropertyMap( Maps.newHashMap( propertyIntrospectorService.getPropertiesMap( schema.getKlass() ) ) );
 
         updateSelf( schema );
@@ -191,4 +193,10 @@
             schema.getPropertyMap().remove( "__self__" );
         }
     }
+
+    private String beautify( String name )
+    {
+        String[] camelCaseWords = org.apache.commons.lang.StringUtils.capitalize( name ).split( "(?=[A-Z])" );
+        return org.apache.commons.lang.StringUtils.join( camelCaseWords, " " ).trim();
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataExport.vm'
--- dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataExport.vm	2014-05-28 11:02:29 +0000
+++ dhis-2/dhis-web/dhis-web-importexport/src/main/webapp/dhis-web-importexport/dxf2MetaDataExport.vm	2014-08-26 10:30:33 +0000
@@ -9,7 +9,7 @@
       $.each(data.schemas, function( idx ) {
         if( this.metadata ) {
           var o = {
-            name: this.plural,
+            name: this.displayName,
             id: this.plural
           }