← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 113: dhis-service-import-export: Upgraded to staxwax 1.0.4. Closed readers and writers after use to re...

 

------------------------------------------------------------
revno: 113
committer: Lars Helge Oeverland larshelge@xxxxxxxxx
branch nick: trunk
timestamp: Thu 2009-03-26 08:54:33 +0100
message:
  dhis-service-import-export: Upgraded to staxwax 1.0.4. Closed readers and writers after use to reduce memory usage. Fixed bugs related to IXF import and export.
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportPipeThread.java
  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/dxf/importer/DefaultDXFImportService.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/converter/IndicatorConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/converter/SourceConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/importer/DefaultIXFImportService.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/util/IXFMappingUtil.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/pom.xml

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportPipeThread.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportPipeThread.java	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ExportPipeThread.java	2009-03-26 07:54:33 +0000
@@ -167,6 +167,8 @@
             
             StreamUtils.closeOutputStream( zipOutputStream );
             
+            writer.closeWriter();
+            
             NameMappingUtil.clearMapping();
         }
     }

=== 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	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/importer/DefaultDhis14XMLImportService.java	2009-03-26 07:54:33 +0000
@@ -225,6 +225,7 @@
                 Map<Integer, String> expressionMap = new AppendingHashMap<Integer, String>();
                 
                 setMessage( "importing_meta_data" );
+                
                 log.info( "Importing meta data" );
         
                 XMLReader reader = XMLFactory.getXMLReader( zipIn );
@@ -275,6 +276,8 @@
                         periodConverter.read( reader, params );
                     }
                 }
+                
+                reader.closeReader();
             }
             else if ( zipEntry.getName().toLowerCase().trim().equals( DATA_FILE_NAME ) )
             {
@@ -283,6 +286,7 @@
                 // -------------------------------------------------------------
 
                 setMessage( "importing_data_values" );
+                
                 log.info( "Importing DataValues" );
     
                 BufferedReader streamReader = new BufferedReader( new InputStreamReader( zipIn ) );
@@ -308,14 +312,15 @@
         {
             setOutput( importAnalyser.getImportAnalysis() );
         }
+
+        log.info( "Import process done" );
         
         setMessage( "import_process_done" );
-        log.info( "Import process done" );
         
+        StreamUtils.closeInputStream( zipIn );
+
         NameMappingUtil.clearMapping();
         
-        StreamUtils.closeInputStream( zipIn );
-        
         cacheManager.clearCache();
     }
 }

=== 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-03-09 12:11:46 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/importer/DefaultDXFImportService.java	2009-03-26 07:54:33 +0000
@@ -1080,12 +1080,14 @@
                 }
             }
         }
-        
+                
         setMessage( "import_process_done" );
         
+        StreamUtils.closeInputStream( zipIn );
+
+        reader.closeReader();
+
         NameMappingUtil.clearMapping();
-                
-        StreamUtils.closeInputStream( zipIn );
         
         cacheManager.clearCache();
     }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/converter/IndicatorConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/converter/IndicatorConverter.java	2009-03-09 12:11:46 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/converter/IndicatorConverter.java	2009-03-26 07:54:33 +0000
@@ -31,6 +31,7 @@
 
 import java.util.Collection;
 import java.util.Map;
+import java.util.Random;
 
 import org.amplecode.staxwax.reader.XMLReader;
 import org.amplecode.staxwax.writer.XMLWriter;
@@ -185,6 +186,8 @@
     {
         while ( reader.moveToStartElement( ELEMENT_NAME, COLLECTION_NAME ) )
         {
+            final int random = new Random().nextInt( 100000 );
+            
             final DataElement element = new DataElement();
             
             reader.moveToStartElement( FIELD_DEFINITION );
@@ -193,7 +196,7 @@
             
             reader.moveToStartElement( FIELD_NAME );            
             element.setName( reader.getElementValue() );                      
-            element.setShortName( subString( element.getName(), 0, 20 ) );
+            element.setShortName( subString( element.getName(), 0, 17 ) + random );
             
             reader.moveToStartElement( FIELD_DESCRIPTION );            
             element.setDescription( reader.getElementValue() );

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/converter/SourceConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/converter/SourceConverter.java	2009-03-19 14:31:44 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/converter/SourceConverter.java	2009-03-26 07:54:33 +0000
@@ -28,6 +28,7 @@
  */
 
 import java.util.Collection;
+import java.util.Random;
 
 import org.amplecode.staxwax.reader.XMLReader;
 import org.amplecode.staxwax.writer.XMLWriter;
@@ -114,13 +115,15 @@
     {
         while ( reader.moveToStartElement( ELEMENT_NAME, COLLECTION_NAME ) )
         {
+            final int random = new Random().nextInt( 100000 );
+            
             final OrganisationUnit unit = new OrganisationUnit();
 
             unit.setUuid( reader.getAttributeValue( FIELD_KEY ) );
             
             reader.moveToStartElement( FIELD_ORG );            
             unit.setName( reader.getElementValue() );
-            unit.setShortName( subString( unit.getName(), 0, 20 ) );
+            unit.setShortName( subString( unit.getName(), 0, 17 ) + random );
             
             NameMappingUtil.addOrganisationUnitMapping( unit.getUuid(), unit.getName() );
             

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/importer/DefaultIXFImportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/importer/DefaultIXFImportService.java	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/importer/DefaultIXFImportService.java	2009-03-26 07:54:33 +0000
@@ -41,6 +41,7 @@
 import org.hisp.dhis.jdbc.batchhandler.OrganisationUnitBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.PeriodBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.SourceBatchHandler;
+import org.hisp.dhis.cache.HibernateCacheManager;
 import org.hisp.dhis.dataelement.DataElementCategoryCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryComboService;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
@@ -128,6 +129,13 @@
         this.objectMappingGenerator = objectMappingGenerator;
     }
 
+    private HibernateCacheManager cacheManager;
+
+    public void setCacheManager( HibernateCacheManager cacheManager )
+    {
+        this.cacheManager = cacheManager;
+    }
+
     // -------------------------------------------------------------------------
     // Constructor
     // -------------------------------------------------------------------------
@@ -230,8 +238,12 @@
         
         setMessage( "import_process_done" );
         
+        StreamUtils.closeInputStream( zipIn );
+        
+        reader.closeReader();
+        
         NameMappingUtil.clearMapping();
         
-        StreamUtils.closeInputStream( zipIn );
+        cacheManager.clearCache();
     }
 }

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/util/IXFMappingUtil.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/util/IXFMappingUtil.java	2009-03-03 16:46:36 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/ixf/util/IXFMappingUtil.java	2009-03-26 07:54:33 +0000
@@ -28,16 +28,19 @@
  */
 
 import java.util.Date;
-import java.util.HashMap;
 import java.util.Map;
 
 import org.hisp.dhis.indicator.IndicatorType;
 import org.hisp.dhis.period.DailyPeriodType;
 import org.hisp.dhis.period.MonthlyPeriodType;
+import org.hisp.dhis.period.OnChangePeriodType;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.period.QuarterlyPeriodType;
+import org.hisp.dhis.period.SixMonthlyPeriodType;
 import org.hisp.dhis.period.WeeklyPeriodType;
 import org.hisp.dhis.period.YearlyPeriodType;
+import org.hisp.dhis.system.util.LoggingHashMap;
 
 /**
  * @author Lars Helge Overland
@@ -53,26 +56,35 @@
     
     static
     {
-        periodTypeNameToIXFMapping = new HashMap<String, String>();
+        periodTypeNameToIXFMapping = new LoggingHashMap<String, String>();
         
         periodTypeNameToIXFMapping.put( YearlyPeriodType.NAME, "Year" );
+        periodTypeNameToIXFMapping.put( SixMonthlyPeriodType.NAME, "SixMonth" );        
+        periodTypeNameToIXFMapping.put( QuarterlyPeriodType.NAME, "Quarter" );
         periodTypeNameToIXFMapping.put( MonthlyPeriodType.NAME, "Month" );
         periodTypeNameToIXFMapping.put( WeeklyPeriodType.NAME, "Week" );
         periodTypeNameToIXFMapping.put( DailyPeriodType.NAME, "Day" );
+        periodTypeNameToIXFMapping.put( OnChangePeriodType.NAME, "OnChange" );
         
-        periodTypeNameFromIXFMapping = new HashMap<String, String>();
+        periodTypeNameFromIXFMapping = new LoggingHashMap<String, String>();
         
         periodTypeNameFromIXFMapping.put( "Year", YearlyPeriodType.NAME );
+        periodTypeNameFromIXFMapping.put( "SixMonthly", SixMonthlyPeriodType.NAME );
+        periodTypeNameFromIXFMapping.put( "Quarter", QuarterlyPeriodType.NAME );
         periodTypeNameFromIXFMapping.put( "Month", MonthlyPeriodType.NAME );
         periodTypeNameFromIXFMapping.put( "Week", WeeklyPeriodType.NAME );
         periodTypeNameFromIXFMapping.put( "Day", DailyPeriodType.NAME );
+        periodTypeNameFromIXFMapping.put( "OnChange", OnChangePeriodType.NAME );
         
-        periodTypeFromIXFMapping = new HashMap<String, PeriodType>();
+        periodTypeFromIXFMapping = new LoggingHashMap<String, PeriodType>();
         
         periodTypeFromIXFMapping.put( "Year", new YearlyPeriodType() );
+        periodTypeFromIXFMapping.put( "SixMonth", new SixMonthlyPeriodType() );
+        periodTypeFromIXFMapping.put( "Quarter", new QuarterlyPeriodType() );
         periodTypeFromIXFMapping.put( "Month", new MonthlyPeriodType() );
         periodTypeFromIXFMapping.put( "Week", new WeeklyPeriodType() );
         periodTypeFromIXFMapping.put( "Day", new DailyPeriodType() );
+        periodTypeFromIXFMapping.put( "OnChange", new OnChangePeriodType() );
     }
     
     public static String getPeriodTypeToIXF( String type )

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml	2009-03-09 14:11:42 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml	2009-03-26 07:54:33 +0000
@@ -348,6 +348,8 @@
       ref="org.hisp.dhis.jdbc.BatchHandlerFactory"/>   
     <property name="objectMappingGenerator" 
       ref="org.hisp.dhis.importexport.mapping.ObjectMappingGenerator"/>
+    <property name="cacheManager"
+      ref="org.hisp.dhis.cache.HibernateCacheManager"/>
   </bean>
   
   <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->

=== modified file 'dhis-2/pom.xml'
--- dhis-2/pom.xml	2009-03-24 14:27:01 +0000
+++ dhis-2/pom.xml	2009-03-26 07:54:33 +0000
@@ -291,7 +291,7 @@
       <dependency>
          <groupId>org.amplecode</groupId>
          <artifactId>staxwax</artifactId>
-        <version>1.0.2</version>
+        <version>1.0.4</version>
       </dependency>
       <dependency>
         <groupId>com.lowagie</groupId>



--
Trunk
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.