← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15449: implement Ordered interface on Schema, using default value for now. Sort SchemaService.getMetadat...

 

------------------------------------------------------------
revno: 15449
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-05-28 13:24:18 +0200
message:
  implement Ordered interface on Schema, using default value for now. Sort SchemaService.getMetadataSchemas() based on this, important to get proper order on metadata import (but will also be used for 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


--
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-05-28 09:57:38 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/schema/Schema.java	2014-05-28 11:24:18 +0000
@@ -37,6 +37,7 @@
 import org.hisp.dhis.common.DxfNamespaces;
 import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.NameableObject;
+import org.springframework.core.Ordered;
 
 import java.util.List;
 import java.util.Map;
@@ -45,7 +46,7 @@
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
 @JacksonXmlRootElement( localName = "schema", namespace = DxfNamespaces.DXF_2_0 )
-public class Schema
+public class Schema implements Ordered
 {
     /**
      * Class that is described in this schema.
@@ -101,6 +102,11 @@
      */
     private List<Property> properties = Lists.newArrayList();
 
+    /**
+     * Used for sorting of schema list when doing metadata import/export.
+     */
+    private int order = Ordered.LOWEST_PRECEDENCE;
+
     public Schema( Class<?> klass, String singular, String plural )
     {
         this.klass = klass;
@@ -250,6 +256,18 @@
         return authorityMap.get( type );
     }
 
+    // TODO not exposed right now, should we?
+    @Override
+    public int getOrder()
+    {
+        return order;
+    }
+
+    public void setOrder( int order )
+    {
+        this.order = order;
+    }
+
     @Override
     public String toString()
     {

=== 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-05-28 11:02:29 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/schema/DefaultSchemaService.java	2014-05-28 11:24:18 +0000
@@ -31,8 +31,10 @@
 import com.google.common.collect.Lists;
 import com.google.common.collect.Maps;
 import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.OrderComparator;
 
 import javax.annotation.PostConstruct;
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
@@ -126,6 +128,8 @@
             }
         }
 
+        Collections.sort( schemas, OrderComparator.INSTANCE );
+
         return schemas;
     }
 }