← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1255: Fixed bug in import-export of categorycombos and categories leading to confusing output. Problem ...

 

------------------------------------------------------------
revno: 1255
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Sun 2009-12-20 20:55:29 +0100
message:
  Fixed bug in import-export of categorycombos and categories leading to confusing output. Problem was caused by missing import of sort order of associations.
added:
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Counter.java
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryCategoryOptionAssociationConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryComboCategoryAssociationConverter.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-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryCategoryOptionAssociationConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryCategoryOptionAssociationConverter.java	2009-11-02 09:20:10 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryCategoryOptionAssociationConverter.java	2009-12-20 19:55:29 +0000
@@ -44,6 +44,7 @@
 import org.hisp.dhis.importexport.ImportParams;
 import org.hisp.dhis.importexport.XMLConverter;
 import org.hisp.dhis.importexport.converter.AbstractGroupMemberConverter;
+import org.hisp.dhis.system.util.Counter;
 
 /**
  * @author Lars Helge Overland
@@ -141,7 +142,7 @@
     
     public void read( XMLReader reader, ImportParams params )
     {
-        int sortOrder = 1;
+        Counter counter = new Counter(); // Used for backwards compatibility
         
         while ( reader.moveToStartElement( ELEMENT_NAME, COLLECTION_NAME ) )
         {
@@ -150,9 +151,9 @@
             final GroupMemberAssociation association = new GroupMemberAssociation( AssociationType.LIST );
             
             association.setGroupId( categoryMapping.get( Integer.parseInt( values.get( FIELD_CATEGORY ) ) ) );
-            association.setMemberId( categoryOptionMapping.get( Integer.parseInt( values.get( FIELD_CATEGORY_OPTION ) ) ) );
-            association.setSortOrder( sortOrder++ ); //TODO Fix
-            //association.setSortOrder( values.containsKey( FIELD_SORT_ORDER ) ? categoryMapping.get( Integer.parseInt( values.get( FIELD_SORT_ORDER ) ) ) : 0 );
+            association.setMemberId( categoryOptionMapping.get( Integer.parseInt( values.get( FIELD_CATEGORY_OPTION ) ) ) );            
+            association.setSortOrder( values.containsKey( FIELD_SORT_ORDER ) ? 
+                Integer.parseInt( values.get( FIELD_SORT_ORDER ) ) : counter.count( association.getGroupId() ) );
             
             read( association, GroupMemberType.CATEGORY_CATEGORYOPTION, params );
         }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryComboCategoryAssociationConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryComboCategoryAssociationConverter.java	2009-12-18 08:56:52 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryComboCategoryAssociationConverter.java	2009-12-20 19:55:29 +0000
@@ -44,6 +44,7 @@
 import org.hisp.dhis.importexport.ImportParams;
 import org.hisp.dhis.importexport.XMLConverter;
 import org.hisp.dhis.importexport.converter.AbstractGroupMemberConverter;
+import org.hisp.dhis.system.util.Counter;
 
 /**
  * @author Lars Helge Overland
@@ -142,7 +143,7 @@
 
     public void read( XMLReader reader, ImportParams params )
     {
-        int sortOrder = 1;
+        Counter counter = new Counter(); // Used for backwards compatibility
         
         while ( reader.moveToStartElement( ELEMENT_NAME, COLLECTION_NAME ) )
         {
@@ -152,8 +153,8 @@
             
             association.setGroupId( categoryComboMapping.get( Integer.parseInt( values.get( FIELD_CATEGORY_COMBO ) ) ) );            
             association.setMemberId( categoryMapping.get( Integer.parseInt( values.get( FIELD_CATEGORY ) ) ) );
-            association.setSortOrder( sortOrder++ ); //TODO Fix
-            //association.setSortOrder( values.containsKey( FIELD_SORT_ORDER ) ? categoryMapping.get( Integer.parseInt( values.get( FIELD_SORT_ORDER ) ) ) : 0 );
+            association.setSortOrder( values.containsKey( FIELD_SORT_ORDER ) ? 
+                Integer.parseInt( values.get( FIELD_SORT_ORDER ) ) : counter.count( association.getGroupId() ) );
             
             read( association, GroupMemberType.CATEGORYCOMBO_CATEGORY, params );
         }

=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Counter.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Counter.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/Counter.java	2009-12-20 19:55:29 +0000
@@ -0,0 +1,58 @@
+package org.hisp.dhis.system.util;
+
+/*
+ * Copyright (c) 2004-2007, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class Counter
+{
+    private Map<Integer, Integer> map;
+    
+    public Counter()
+    {
+        map = new HashMap<Integer, Integer>();
+    }
+    
+    public int count( int key )
+    {
+        if ( !map.containsKey( key ) )
+        {
+            map.put( key, 0 );
+        }
+        
+        int count = map.get( key );
+        
+        map.put( key, ++count );
+        
+        return count;
+    }
+}