← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 15938: Sorting of sections in form resource

 

------------------------------------------------------------
revno: 15938
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2014-07-02 16:37:35 +0200
message:
  Sorting of sections in form resource
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/SectionOrderComparator.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/FormUtils.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/dataset/comparator/SectionOrderComparator.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/SectionOrderComparator.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataset/comparator/SectionOrderComparator.java	2014-07-02 14:37:35 +0000
@@ -35,6 +35,8 @@
 public class SectionOrderComparator
     implements Comparator<Section>
 {
+    public static final SectionOrderComparator INSTANCE = new SectionOrderComparator();
+    
     public int compare( Section o1, Section o2 )
     {
         if ( o1.getDataSet() != null && o2.getDataSet() != null )

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/FormUtils.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/FormUtils.java	2014-06-30 07:40:07 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/utils/FormUtils.java	2014-07-02 14:37:35 +0000
@@ -37,6 +37,7 @@
 import org.hisp.dhis.dataelement.DataElementOperand;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.dataset.Section;
+import org.hisp.dhis.dataset.comparator.SectionOrderComparator;
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.program.Program;
 import org.hisp.dhis.program.ProgramStage;
@@ -47,6 +48,7 @@
 
 import java.util.ArrayList;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -66,7 +68,10 @@
 
         if ( dataSet.getSections().size() > 0 )
         {
-            for ( Section section : dataSet.getSections() )
+            List<Section> sections = new ArrayList<Section>( dataSet.getSections() );
+            Collections.sort( sections, SectionOrderComparator.INSTANCE );
+            
+            for ( Section section : sections )
             {
                 List<Field> fields = inputsFromDataElements( new ArrayList<DataElement>( section.getDataElements() ), new ArrayList<DataElementOperand>( section.getGreyedFields() ) );