← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 954: Implemented dxf1 import of groupsets. Preview next.

 

------------------------------------------------------------
revno: 954
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Mon 2009-11-02 10:20:10 +0100
message:
  Implemented dxf1 import of groupsets. Preview next.
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
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupMemberConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupSetConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupSetMemberConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/IndicatorGroupSetMemberConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/importer/DefaultDXFImportService.java
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataElementGroupSetMemberBatchHandler.java
  dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/IndicatorGroupSetMemberBatchHandler.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-10-18 22:44:41 +0000
+++ 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
@@ -117,7 +117,7 @@
             {
                 if ( category.getCategoryOptions() != null )
                 {
-                    int sortOrder = 0;
+                    int sortOrder = 1;
                 	
                     for ( DataElementCategoryOption categoryOption : category.getCategoryOptions() )
                     {

=== 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-10-18 22:44:41 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/CategoryComboCategoryAssociationConverter.java	2009-11-02 09:20:10 +0000
@@ -118,7 +118,7 @@
             {
                 if ( categoryCombo.getCategories() != null )
                 {
-                    int sortOrder = 0;
+                    int sortOrder = 1;
                     
                     for ( DataElementCategory category : categoryCombo.getCategories() )
                     {

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupMemberConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupMemberConverter.java	2009-08-12 21:06:37 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupMemberConverter.java	2009-11-02 09:20:10 +0000
@@ -110,19 +110,16 @@
             
             for ( DataElementGroup group : groups )
             {
-                if ( group.getMembers() != null )
-                {                    
-                    for ( DataElement element : group.getMembers() )
+                for ( DataElement element : group.getMembers() )
+                {
+                    if ( elements.contains( element ) )
                     {
-                        if ( elements.contains( element ) )
-                        {
-                            writer.openElement( ELEMENT_NAME );
-                            
-                            writer.writeElement( FIELD_DATAELEMENT_GROUP, String.valueOf( group.getId() ) );
-                            writer.writeElement( FIELD_DATAELEMENT, String.valueOf( element.getId() ) );
-                            
-                            writer.closeElement();
-                        }
+                        writer.openElement( ELEMENT_NAME );
+                        
+                        writer.writeElement( FIELD_DATAELEMENT_GROUP, String.valueOf( group.getId() ) );
+                        writer.writeElement( FIELD_DATAELEMENT, String.valueOf( element.getId() ) );
+                        
+                        writer.closeElement();
                     }
                 }
             }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupSetConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupSetConverter.java	2009-11-01 20:57:16 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupSetConverter.java	2009-11-02 09:20:10 +0000
@@ -30,6 +30,7 @@
 import java.util.Collection;
 import java.util.Map;
 
+import org.amplecode.quick.BatchHandler;
 import org.amplecode.staxwax.reader.XMLReader;
 import org.amplecode.staxwax.writer.XMLWriter;
 import org.hisp.dhis.dataelement.DataElementGroup;
@@ -66,10 +67,13 @@
         this.dataElementService = dataElementService;
     }
 
-    public DataElementGroupSetConverter( DataElementService dataElementService, ImportObjectService importObjectService )
+    public DataElementGroupSetConverter( BatchHandler<DataElementGroupSet> batchHandler, 
+        ImportObjectService importObjectService,
+        DataElementService dataElementService )
     {
-        this.dataElementService = dataElementService;
+        this.batchHandler = batchHandler;
         this.importObjectService = importObjectService;
+        this.dataElementService = dataElementService;
     }
 
     // -------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupSetMemberConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupSetMemberConverter.java	2009-11-01 20:57:16 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataElementGroupSetMemberConverter.java	2009-11-02 09:20:10 +0000
@@ -58,6 +58,7 @@
     
     private static final String FIELD_DATAELEMENT_GROUP = "dataElementGroup";
     private static final String FIELD_DATAELEMENT_GROUP_SET = "dataElementGroupSet";
+    private static final String FIELD_SORT_ORDER = "sortOrder";
 
     // -------------------------------------------------------------------------
     // Properties
@@ -110,20 +111,20 @@
             writer.openElement( COLLECTION_NAME );
             
             for ( DataElementGroupSet groupSet : groupSets )
-            {
-                if ( groupSet.getMembers() != null )
+            {           
+                int sortOrder = 1;
+                
+                for ( DataElementGroup group : groupSet.getMembers() )
                 {                    
-                    for ( DataElementGroup group : groupSet.getMembers() )
+                    if ( groups.contains( group ) )
                     {
-                        if ( groups.contains( group ) )
-                        {
-                            writer.openElement( ELEMENT_NAME );
-                            
-                            writer.writeElement( FIELD_DATAELEMENT_GROUP_SET, String.valueOf( groupSet.getId() ) );
-                            writer.writeElement( FIELD_DATAELEMENT_GROUP, String.valueOf( group.getId() ) );
-                            
-                            writer.closeElement();
-                        }
+                        writer.openElement( ELEMENT_NAME );
+                        
+                        writer.writeElement( FIELD_DATAELEMENT_GROUP_SET, String.valueOf( groupSet.getId() ) );
+                        writer.writeElement( FIELD_DATAELEMENT_GROUP, String.valueOf( group.getId() ) );
+                        writer.writeElement( FIELD_SORT_ORDER, String.valueOf( sortOrder++ ) );
+                        
+                        writer.closeElement();
                     }
                 }
             }
@@ -142,6 +143,7 @@
             
             association.setGroupId( dataElementGroupSetMapping.get( Integer.parseInt( values.get( FIELD_DATAELEMENT_GROUP_SET )) ) );
             association.setMemberId( dataElementGroupMapping.get( Integer.parseInt( values.get( FIELD_DATAELEMENT_GROUP ) ) ) );
+            association.setSortOrder( Integer.parseInt( values.get( FIELD_SORT_ORDER ) ) );
             
             read( association, GroupMemberType.DATAELEMENTGROUP, params );
         }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/IndicatorGroupSetMemberConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/IndicatorGroupSetMemberConverter.java	2009-11-01 20:57:16 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/IndicatorGroupSetMemberConverter.java	2009-11-02 09:20:10 +0000
@@ -58,6 +58,7 @@
     
     private static final String FIELD_INDICATOR_GROUP = "indicatorGroup";
     private static final String FIELD_INDICATOR_GROUP_SET = "indicatorGroupSet";
+    private static final String FIELD_SORT_ORDER = "sortOrder";
     
     // -------------------------------------------------------------------------
     // Properties
@@ -111,14 +112,17 @@
             
             for ( IndicatorGroupSet groupSet : groupSets )
             {
+                int sortOrder = 1;
+                
                 for ( IndicatorGroup group : groupSet.getMembers() )
-                {
+                {                    
                     if ( groups.contains( group ) )
                     {
                         writer.openElement( ELEMENT_NAME );
                     
                         writer.writeElement( FIELD_INDICATOR_GROUP_SET, String.valueOf( groupSet.getId() ) );
                         writer.writeElement( FIELD_INDICATOR_GROUP, String.valueOf( group.getId() ) );
+                        writer.writeElement( FIELD_SORT_ORDER, String.valueOf( sortOrder++ ) );
                     
                         writer.closeElement();
                     }
@@ -139,6 +143,7 @@
             
             association.setGroupId( indicatorGroupSetMapping.get( Integer.parseInt( values.get( FIELD_INDICATOR_GROUP_SET ) ) ) );
             association.setMemberId( indicatorGroupMapping.get( Integer.parseInt( values.get( FIELD_INDICATOR_GROUP ) ) ) );
+            association.setSortOrder( Integer.parseInt( values.get( FIELD_SORT_ORDER ) ) );
             
             read( association, GroupMemberType.INDICATORGROUP, params );
         }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/importer/DefaultDXFImportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/importer/DefaultDXFImportService.java	2009-11-01 21:32:55 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/importer/DefaultDXFImportService.java	2009-11-02 09:20:10 +0000
@@ -46,6 +46,7 @@
 import org.hisp.dhis.dataelement.DataElementCategoryOption;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataelement.DataElementGroup;
+import org.hisp.dhis.dataelement.DataElementGroupSet;
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.datamart.DataMartStore;
 import org.hisp.dhis.dataset.CompleteDataSetRegistration;
@@ -74,6 +75,8 @@
 import org.hisp.dhis.importexport.dxf.converter.DataElementConverter;
 import org.hisp.dhis.importexport.dxf.converter.DataElementGroupConverter;
 import org.hisp.dhis.importexport.dxf.converter.DataElementGroupMemberConverter;
+import org.hisp.dhis.importexport.dxf.converter.DataElementGroupSetConverter;
+import org.hisp.dhis.importexport.dxf.converter.DataElementGroupSetMemberConverter;
 import org.hisp.dhis.importexport.dxf.converter.DataSetConverter;
 import org.hisp.dhis.importexport.dxf.converter.DataSetMemberConverter;
 import org.hisp.dhis.importexport.dxf.converter.DataSetSourceAssociationConverter;
@@ -85,6 +88,8 @@
 import org.hisp.dhis.importexport.dxf.converter.IndicatorConverter;
 import org.hisp.dhis.importexport.dxf.converter.IndicatorGroupConverter;
 import org.hisp.dhis.importexport.dxf.converter.IndicatorGroupMemberConverter;
+import org.hisp.dhis.importexport.dxf.converter.IndicatorGroupSetConverter;
+import org.hisp.dhis.importexport.dxf.converter.IndicatorGroupSetMemberConverter;
 import org.hisp.dhis.importexport.dxf.converter.IndicatorTypeConverter;
 import org.hisp.dhis.importexport.dxf.converter.OlapUrlConverter;
 import org.hisp.dhis.importexport.dxf.converter.OrganisationUnitConverter;
@@ -107,6 +112,7 @@
 import org.hisp.dhis.importexport.mapping.ObjectMappingGenerator;
 import org.hisp.dhis.indicator.Indicator;
 import org.hisp.dhis.indicator.IndicatorGroup;
+import org.hisp.dhis.indicator.IndicatorGroupSet;
 import org.hisp.dhis.indicator.IndicatorService;
 import org.hisp.dhis.indicator.IndicatorType;
 import org.hisp.dhis.jdbc.batchhandler.CategoryCategoryOptionAssociationBatchHandler;
@@ -121,6 +127,8 @@
 import org.hisp.dhis.jdbc.batchhandler.DataElementCategoryOptionBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.DataElementGroupBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.DataElementGroupMemberBatchHandler;
+import org.hisp.dhis.jdbc.batchhandler.DataElementGroupSetBatchHandler;
+import org.hisp.dhis.jdbc.batchhandler.DataElementGroupSetMemberBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.DataSetBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.DataSetMemberBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.DataSetSourceAssociationBatchHandler;
@@ -132,6 +140,8 @@
 import org.hisp.dhis.jdbc.batchhandler.IndicatorBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.IndicatorGroupBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.IndicatorGroupMemberBatchHandler;
+import org.hisp.dhis.jdbc.batchhandler.IndicatorGroupSetBatchHandler;
+import org.hisp.dhis.jdbc.batchhandler.IndicatorGroupSetMemberBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.IndicatorTypeBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.OrganisationUnitBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.OrganisationUnitGroupBatchHandler;
@@ -483,8 +493,7 @@
             // dxfv1 only
             else if ( reader.isStartElement( CategoryComboCategoryAssociationConverter.COLLECTION_NAME ) )
             {
-                // setMessage( "importing_data_element_category_combo_members"
-                // );
+                // setMessage( "importing_data_element_category_combo_members" );
 
                 BatchHandler<GroupMemberAssociation> batchHandler = batchHandlerFactory
                     .createBatchHandler( CategoryComboCategoryAssociationBatchHandler.class );
@@ -595,6 +604,42 @@
 
                 log.info( "Imported DataElementGroup members" );
             }
+            else if ( reader.isStartElement( DataElementGroupSetConverter.COLLECTION_NAME ) )
+            {
+                // setMessage( "importing_data_element_group_sets" );
+                
+                BatchHandler<DataElementGroupSet> batchHandler = batchHandlerFactory.
+                    createBatchHandler( DataElementGroupSetBatchHandler.class );
+                
+                batchHandler.init();
+                
+                XMLConverter converter = new DataElementGroupSetConverter( batchHandler, importObjectService, dataElementService );
+                
+                converterInvoker.invokeRead( converter, reader, params );
+                
+                batchHandler.flush();
+                
+                log.info( "Imported DataElementGroupSets" );
+            }
+            else if ( reader.isStartElement( DataElementGroupSetMemberConverter.COLLECTION_NAME ) )
+            {
+                // setMessage( "importing_data_element_group_set_members" );
+
+                BatchHandler<GroupMemberAssociation> batchHandler = batchHandlerFactory.
+                    createBatchHandler( DataElementGroupSetMemberBatchHandler.class );
+                
+                batchHandler.init();
+                
+                XMLConverter converter = new DataElementGroupSetMemberConverter( batchHandler, importObjectService,
+                    objectMappingGenerator.getDataElementGroupMapping( params.skipMapping() ), 
+                    objectMappingGenerator.getDataElementGroupSetMapping( params.skipMapping() ) );
+                
+                converterInvoker.invokeRead( converter, reader, params );
+                
+                batchHandler.flush();
+                
+                log.info( "Imported DataElementGroupSet members" );
+            }
             else if ( reader.isStartElement( IndicatorTypeConverter.COLLECTION_NAME ) )
             {
                 // setMessage( "importing_indicator_types" );
@@ -698,6 +743,42 @@
 
                 log.info( "Imported IndicatorGroup members" );
             }
+            else if ( reader.isStartElement( IndicatorGroupSetConverter.COLLECTION_NAME ) )
+            {
+                // setMessage( "importing_indicator_group_sets" );
+                
+                BatchHandler<IndicatorGroupSet> batchHandler = batchHandlerFactory.
+                    createBatchHandler( IndicatorGroupSetBatchHandler.class );
+                
+                batchHandler.init();
+                
+                XMLConverter converter = new IndicatorGroupSetConverter( batchHandler, importObjectService, indicatorService );
+                
+                converterInvoker.invokeRead( converter, reader, params );
+                
+                batchHandler.flush();
+                
+                log.info( "Imported IndicatorGroupSets" );
+            }
+            else if ( reader.isStartElement( IndicatorGroupSetMemberConverter.COLLECTION_NAME ) )
+            {
+                // setMessage( "importing_indicator_group_set_members" );
+                
+                BatchHandler<GroupMemberAssociation> batchHandler = batchHandlerFactory.
+                    createBatchHandler( IndicatorGroupSetMemberBatchHandler.class );
+                
+                batchHandler.init();
+                
+                XMLConverter converter = new IndicatorGroupSetMemberConverter( batchHandler, importObjectService,
+                    objectMappingGenerator.getIndicatorGroupMapping( params.skipMapping() ),
+                    objectMappingGenerator.getIndicatorGroupSetMapping( params.skipMapping() ) );
+                
+                converterInvoker.invokeRead( converter, reader, params );
+                
+                batchHandler.flush();
+                
+                log.info( "Imported IndicatorGroupSet members" );
+            }
             else if ( reader.isStartElement( DataDictionaryConverter.COLLECTION_NAME ) )
             {
                 // setMessage( "importing_data_dictionaries" );

=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataElementGroupSetMemberBatchHandler.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataElementGroupSetMemberBatchHandler.java	2009-11-01 20:29:36 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataElementGroupSetMemberBatchHandler.java	2009-11-02 09:20:10 +0000
@@ -72,11 +72,13 @@
     {
         statementBuilder.setColumn( "dataelementgroupsetid" );
         statementBuilder.setColumn( "dataelementgroupid" );
+        statementBuilder.setColumn( "sort_order" );
     }
     
     protected void setValues( GroupMemberAssociation association )
     {        
         statementBuilder.setValue( association.getGroupId() );
         statementBuilder.setValue( association.getMemberId() );
+        statementBuilder.setValue( association.getSortOrder() );
     }    
 }

=== modified file 'dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/IndicatorGroupSetMemberBatchHandler.java'
--- dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/IndicatorGroupSetMemberBatchHandler.java	2009-11-01 20:29:36 +0000
+++ dhis-2/dhis-services/dhis-service-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/IndicatorGroupSetMemberBatchHandler.java	2009-11-02 09:20:10 +0000
@@ -72,11 +72,13 @@
     {
         statementBuilder.setColumn( "indicatorgroupsetid" );
         statementBuilder.setColumn( "indicatorgroupid" );
+        statementBuilder.setColumn( "sort_order" );
     }
     
     protected void setValues( GroupMemberAssociation association )
     {        
         statementBuilder.setValue( association.getGroupId() );
         statementBuilder.setValue( association.getMemberId() );
+        statementBuilder.setValue( association.getSortOrder() );
     }    
 }