← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9843: FRED-API: make sure that dataSets are always in same order

 

------------------------------------------------------------
revno: 9843
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-02-19 18:50:18 +0700
message:
  FRED-API: make sure that dataSets are always in same order
modified:
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/OrganisationUnitToFacilityConverter.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-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/OrganisationUnitToFacilityConverter.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/OrganisationUnitToFacilityConverter.java	2013-02-04 18:03:10 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/OrganisationUnitToFacilityConverter.java	2013-02-19 11:50:18 +0000
@@ -27,6 +27,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.hisp.dhis.common.comparator.IdentifiableObjectNameComparator;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
@@ -38,6 +39,7 @@
 import org.springframework.stereotype.Component;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import static org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo;
@@ -100,9 +102,13 @@
             facility.getIdentifiers().add( identifier );
         }
 
+        // make sure that dataSets always come in the same order. This is a must for safe ETag generation.
+        List<DataSet> ouDataSets = new ArrayList<DataSet>( organisationUnit.getDataSets() );
+        Collections.sort( ouDataSets, new IdentifiableObjectNameComparator() );
+
         List<String> dataSets = new ArrayList<String>();
 
-        for ( DataSet dataSet : organisationUnit.getDataSets() )
+        for ( DataSet dataSet : ouDataSets )
         {
             dataSets.add( dataSet.getUid() );
         }