← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1430: Improved and fixed a bug in dhis 1.4 xml import.

 

------------------------------------------------------------
revno: 1430
committer: Lars Helge Oeverland <larshelge@xxxxxxxxx>
branch nick: trunk
timestamp: Mon 2010-02-15 11:47:13 +0100
message:
  Improved and fixed a bug in dhis 1.4 xml import.
added:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementCategoryConverter.java
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementCategoryComboConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementCategoryOptionComboConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementCategoryOptionConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/importer/DefaultDhis14XMLImportService.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/dhis14/xml/converter/DataElementCategoryComboConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementCategoryComboConverter.java	2009-10-18 22:44:41 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementCategoryComboConverter.java	2010-02-15 10:47:13 +0000
@@ -39,6 +39,7 @@
 import org.hisp.dhis.importexport.ImportParams;
 import org.hisp.dhis.importexport.XMLConverter;
 import org.hisp.dhis.importexport.converter.AbstractDataElementCategoryComboConverter;
+import org.hisp.dhis.importexport.mapping.NameMappingUtil;
 
 /**
  * @author Lars Helge Overland
@@ -71,10 +72,9 @@
     
     public void read( XMLReader reader, ImportParams params )
     {
-        final DataElementCategoryCombo categoryCombo = new DataElementCategoryCombo();
-        
-        categoryCombo.setId( 1 );
-        categoryCombo.setName( DEFAULT_CATEGORY_COMBO_NAME );
+        DataElementCategoryCombo categoryCombo = categoryService.getDataElementCategoryComboByName( DEFAULT_CATEGORY_COMBO_NAME );
+
+        NameMappingUtil.addCategoryComboMapping( categoryCombo.getId(), categoryCombo.getName() );
         
         read( categoryCombo, GroupMemberType.NONE, params );
     }

=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementCategoryConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementCategoryConverter.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementCategoryConverter.java	2010-02-15 10:47:13 +0000
@@ -0,0 +1,80 @@
+package org.hisp.dhis.importexport.dhis14.xml.converter;
+
+/*
+ * 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 static org.hisp.dhis.dataelement.DataElementCategory.DEFAULT_NAME;
+
+import org.amplecode.staxwax.reader.XMLReader;
+import org.amplecode.staxwax.writer.XMLWriter;
+import org.hisp.dhis.dataelement.DataElementCategory;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.importexport.ExportParams;
+import org.hisp.dhis.importexport.GroupMemberType;
+import org.hisp.dhis.importexport.ImportObjectService;
+import org.hisp.dhis.importexport.ImportParams;
+import org.hisp.dhis.importexport.XMLConverter;
+import org.hisp.dhis.importexport.converter.AbstractDataElementCategoryConverter;
+import org.hisp.dhis.importexport.mapping.NameMappingUtil;
+
+/**
+ * @author Lars Helge Overland
+ */
+public class DataElementCategoryConverter
+    extends AbstractDataElementCategoryConverter implements XMLConverter
+{
+    /**
+     * Constructor for read operations.
+     * 
+     * @param importObjectService the importObjectService to use.
+     * @param categoryOptionService the dataElementCategoryOptionService to use.
+     */
+    public DataElementCategoryConverter( ImportObjectService importObjectService,
+        DataElementCategoryService categoryService )
+    {
+        this.importObjectService = importObjectService;
+        this.categoryService = categoryService;
+    }    
+
+    // -------------------------------------------------------------------------
+    // XMLConverter implementation
+    // -------------------------------------------------------------------------
+
+    public void write( XMLWriter writer, ExportParams params )
+    {
+        // Not implemented
+    }
+    
+    public void read( XMLReader reader, ImportParams params )
+    {
+        DataElementCategory category = categoryService.getDataElementCategoryByName( DEFAULT_NAME );
+        
+        NameMappingUtil.addCategoryMapping( category.getId(), category.getName() );
+        
+        read( category, GroupMemberType.NONE, params );
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementCategoryOptionComboConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementCategoryOptionComboConverter.java	2009-10-18 22:44:41 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementCategoryOptionComboConverter.java	2010-02-15 10:47:13 +0000
@@ -29,8 +29,6 @@
 
 import org.amplecode.staxwax.reader.XMLReader;
 import org.amplecode.staxwax.writer.XMLWriter;
-import org.hisp.dhis.dataelement.DataElementCategoryCombo;
-import org.hisp.dhis.dataelement.DataElementCategoryOption;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.importexport.ExportParams;
@@ -39,6 +37,7 @@
 import org.hisp.dhis.importexport.ImportParams;
 import org.hisp.dhis.importexport.XMLConverter;
 import org.hisp.dhis.importexport.converter.AbstractDataElementCategoryOptionComboConverter;
+import org.hisp.dhis.importexport.mapping.NameMappingUtil;
 
 /**
  * @author Lars Helge Overland
@@ -71,23 +70,9 @@
     
     public void read( XMLReader reader, ImportParams params )
     {
-        final DataElementCategoryOptionCombo categoryOptionCombo = new DataElementCategoryOptionCombo();
-        
-        categoryOptionCombo.setId( 1 );
-        
-        final DataElementCategoryCombo categoryCombo = new DataElementCategoryCombo();
-        
-        categoryCombo.setId( 1 );
-        categoryCombo.setName( DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME );
-        
-        categoryOptionCombo.setCategoryCombo( categoryCombo );
-        
-        final DataElementCategoryOption categoryOption = new DataElementCategoryOption();
-        
-        categoryOption.setId( 1 );
-        categoryOption.setName( DataElementCategoryOption.DEFAULT_NAME );
-        
-        categoryOptionCombo.getCategoryOptions().add( categoryOption );
+        DataElementCategoryOptionCombo categoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
+
+        NameMappingUtil.addCategoryOptionComboMapping( categoryOptionCombo.getId(), categoryOptionCombo );
         
         read( categoryOptionCombo, GroupMemberType.NONE, params );
     }        

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementCategoryOptionConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementCategoryOptionConverter.java	2009-10-18 22:44:41 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataElementCategoryOptionConverter.java	2010-02-15 10:47:13 +0000
@@ -37,6 +37,9 @@
 import org.hisp.dhis.importexport.ImportParams;
 import org.hisp.dhis.importexport.XMLConverter;
 import org.hisp.dhis.importexport.converter.AbstractDataElementCategoryOptionConverter;
+import org.hisp.dhis.importexport.mapping.NameMappingUtil;
+
+import static org.hisp.dhis.dataelement.DataElementCategoryCombo.DEFAULT_CATEGORY_COMBO_NAME;
 
 /**
  * @author Lars Helge Overland
@@ -69,11 +72,9 @@
     
     public void read( XMLReader reader, ImportParams params )
     {
-        final DataElementCategoryOption categoryOption = new DataElementCategoryOption();
+        DataElementCategoryOption categoryOption = categoryService.getDataElementCategoryOptionByName( DEFAULT_CATEGORY_COMBO_NAME );
         
-        categoryOption.setId( 1 );
-        categoryOption.setName( DataElementCategoryOption.DEFAULT_NAME );
-        categoryOption.setShortName( DataElementCategoryOption.DEFAULT_NAME );
+        NameMappingUtil.addCategoryOptionMapping( categoryOption.getId(), categoryOption.getName() );
         
         read( categoryOption, GroupMemberType.NONE, params );
     }   

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/importer/DefaultDhis14XMLImportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/importer/DefaultDhis14XMLImportService.java	2010-02-08 07:04:26 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/importer/DefaultDhis14XMLImportService.java	2010-02-15 10:47:13 +0000
@@ -54,6 +54,7 @@
 import org.hisp.dhis.importexport.analysis.ImportAnalyser;
 import org.hisp.dhis.importexport.dhis14.xml.converter.CalculatedDataElementAssociationConverter;
 import org.hisp.dhis.importexport.dhis14.xml.converter.DataElementCategoryComboConverter;
+import org.hisp.dhis.importexport.dhis14.xml.converter.DataElementCategoryConverter;
 import org.hisp.dhis.importexport.dhis14.xml.converter.DataElementCategoryOptionComboConverter;
 import org.hisp.dhis.importexport.dhis14.xml.converter.DataElementCategoryOptionConverter;
 import org.hisp.dhis.importexport.dhis14.xml.converter.DataElementConverter;
@@ -231,6 +232,7 @@
                 XMLReader reader = XMLFactory.getXMLReader( zipIn );
                 
                 XMLConverter categoryOptionConverter = new DataElementCategoryOptionConverter( importObjectService, categoryService );
+                XMLConverter categoryConverter = new DataElementCategoryConverter( importObjectService, categoryService );
                 XMLConverter categoryComboConverter = new DataElementCategoryComboConverter( importObjectService, categoryService );
                 XMLConverter categoryOptionComboConverter = new DataElementCategoryOptionComboConverter( importObjectService, categoryService );
                 XMLConverter calculatedDataElementAssociationConverter = new CalculatedDataElementAssociationConverter( expressionMap );
@@ -242,9 +244,10 @@
                 XMLConverter hierarchyConverter = new OrganisationUnitHierarchyConverter( importObjectService, organisationUnitService );
                 XMLConverter periodConverter = new PeriodConverter( importObjectService, periodService, objectMappingGenerator.getPeriodTypeMapping() );
 
-                categoryOptionConverter.read( reader, params );
-                categoryComboConverter.read( reader, params );
-                categoryOptionComboConverter.read( reader, params );
+                converterInvoker.invokeRead( categoryOptionConverter, reader, params );
+                converterInvoker.invokeRead( categoryConverter, reader, params );
+                converterInvoker.invokeRead( categoryComboConverter, reader, params );
+                converterInvoker.invokeRead( categoryOptionComboConverter, reader, params );
                 
                 while ( reader.next() )
                 {