← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4555: Wired up dx2 data importer

 

------------------------------------------------------------
revno: 4555
committer: Bob Jolliffe bobjolliffe@xxxxxxxxx
branch nick: dhis2
timestamp: Fri 2011-09-09 12:20:37 +0100
message:
  Wired up dx2 data importer
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/DefaultImportService.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/StaXDataValueImportService.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml


--
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/DefaultImportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/DefaultImportService.java	2010-12-29 16:17:28 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/DefaultImportService.java	2011-09-09 11:20:37 +0000
@@ -48,6 +48,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.ProcessState;
 import org.hisp.dhis.importexport.dxf.converter.DXFConverter;
+import org.hisp.dhis.importexport.dxf2.service.StaXDataValueImportService;
 import org.hisp.dhis.importexport.xml.XMLPreConverter;
 import org.hisp.dhis.importexport.zip.ZipAnalyzer;
 import org.hisp.dhis.system.process.OutputHolderState;
@@ -62,6 +63,8 @@
 
     private final Log log = LogFactory.getLog( DefaultImportService.class );
 
+    static public final String DXF1URI = "http://dhis2.org/schema/dxf/1.0";;
+    static public final String DXF2URI = "http://dhis2.org/schema/dxf/2.0";;
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -80,6 +83,13 @@
         this.converter = converter;
     }
 
+    private StaXDataValueImportService dxf2converter;
+
+    public void setDxf2converter( StaXDataValueImportService dxf2converter )
+    {
+        this.dxf2converter = dxf2converter;
+    }
+
     // -------------------------------------------------------------------------
     // ImportService implementation
     // -------------------------------------------------------------------------
@@ -152,7 +162,10 @@
 
         try
         {
-            if ( documentRootName.getLocalPart().equals( DXFConverter.DXFROOT ) )
+            String rootLocalName = documentRootName.getLocalPart();
+            String rootNameSpace = documentRootName.getNamespaceURI();
+
+            if ( rootLocalName.equals( DXFConverter.DXFROOT ) )
             {                
                 log.info( "Importing DXF native stream" ); // Native DXF stream, no transform required
                 dxfReader = XMLFactory.getXMLReader( xmlDataStream );
@@ -177,8 +190,15 @@
                 dxfReader = XMLFactory.getXMLReader( dxfInStream );
             }
 
-            log.debug( "Sending DXF to converter" );
-            converter.read( dxfReader, params, state );
+            if (rootNameSpace.equals( DXF2URI )) {
+              log.debug( "Sending DXFv2 to converter" );
+              converter.read( dxfReader, params, state );
+            } else if (rootNameSpace.equals( DXF1URI )) {
+              log.debug( "Sending DXFv1 to converter" );
+              converter.read( dxfReader, params, state );
+            } else {
+                throw new ImportException("Unknown dxf version: " + rootNameSpace);
+            }
         }
         catch ( IOException ex )
         {

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/StaXDataValueImportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/StaXDataValueImportService.java	2011-09-07 19:26:45 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/StaXDataValueImportService.java	2011-09-09 11:20:37 +0000
@@ -229,7 +229,8 @@
                     }
                 }
 
-                Period outerPeriod = getPeriodObj( period );
+                int periodId = periodService.addPeriod( getPeriodObj( period ) );
+                Period outerPeriod = periodService.getPeriod( periodId );
 
                 // maps for translating identifiers
                 Map<String, Integer> dataelementMap = null;

=== 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	2011-09-09 06:18:32 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml	2011-09-09 11:20:37 +0000
@@ -217,12 +217,22 @@
     <property name="cacheManager" ref="cacheManager" />
   </bean>
 
+  <bean id="dxfv2StaXImporter" class="org.hisp.dhis.importexport.dxf2.service.StaXDataValueImportService">
+    <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
+    <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
+    <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+    <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+    <property name="periodService" ref="org.hisp.dhis.period.PeriodService" />
+    <property name="batchHandlerFactory" ref="batchHandlerFactory" />
+  </bean>
+
   <bean id="org.hisp.dhis.importexport.ImportService" class="org.hisp.dhis.importexport.DefaultImportService">
     <property name="converter" ref="dxfv1-Converter" />
+    <property name="dxf2converter" ref="dxfv2StaXImporter" />
     <property name="preConverter" ref="preConverter" />
   </bean>
 
-	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
+    <!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
 	<!-- XSLT based import                                                    -->
 	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->