← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 940: factored out dxfv1 parsing into separate method

 

------------------------------------------------------------
revno: 940
committer: Bob Jolliffe <bobj@bobj-laptop>
branch nick: trunk
timestamp: Fri 2009-10-30 13:52:10 +0000
message:
  factored out dxfv1 parsing into separate method
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/importer/DefaultDXFImportService.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/importer/DefaultDXFImportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/importer/DefaultDXFImportService.java	2009-10-30 12:51:29 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/importer/DefaultDXFImportService.java	2009-10-30 13:52:10 +0000
@@ -344,23 +344,42 @@
         // assume default version 1
         int dxfVersion = 1;
         
-        while ( reader.next() )
+        // move to root element
+        reader.next();
+        
+        if (reader.isStartElement( ROOT_NAME)  )
         {
-            if (reader.isStartElement( ROOT_NAME)  )
-            {
-            		if (reader.getXmlStreamReader().getNamespaceURI() ==  DXF2_NAMESPACE_URI)
-            		{
-            			dxfVersion = 2;
-            		}
-            		else
-            		{
-            			dxfVersion = 1;
-            		}
-            	log.info("dxf version "+dxfVersion);
-            }
-
-            // dxfv1 only 
-            if ( reader.isStartElement( DataValueConverter.COLLECTION_NAME ) && params.isDataValues() )
+        	if (reader.getXmlStreamReader().getNamespaceURI() ==  DXF2_NAMESPACE_URI)
+        	{
+        		dxfVersion = 2;
+            	log.info("parsing dxf version "+dxfVersion);
+        	}
+        	else
+        	{
+        		dxfVersion = 1;
+        		parseDXFv1(params, reader);
+        	}
+        		
+        }
+            
+        //setMessage( "import_process_done" );
+        
+        StreamUtils.closeInputStream( zipIn );
+        
+        reader.closeReader();
+        
+        NameMappingUtil.clearMapping();
+            
+        cacheManager.clearCache();
+
+    }
+    
+
+    void parseDXFv1(ImportParams params, XMLReader reader)
+    {
+    	while (reader.next()) {
+
+    		if ( reader.isStartElement( DataValueConverter.COLLECTION_NAME ) && params.isDataValues() )
             {
                 if ( params.skipMapping() == false && lockingManager.currentImportContainsLockedData() )
                 {
@@ -370,8 +389,6 @@
                 }
                 else
                 {
-                    //setMessage( "importing_data_values" );
-                    
                     BatchHandler<DataValue> batchHandler = batchHandlerFactory.createBatchHandler( DataValueBatchHandler.class );
                     
                     BatchHandler<ImportDataValue> importDataValueBatchHandler = batchHandlerFactory.createBatchHandler( ImportDataValueBatchHandler.class );
@@ -401,9 +418,9 @@
                 }
             }
             
-            else if ( reader.isStartElement( DataElementCategoryOptionConverter.COLLECTION_NAME ) && dxfVersion==1)
+            else if ( reader.isStartElement( DataElementCategoryOptionConverter.COLLECTION_NAME ))
             {
-                //setMessage( "importing_data_element_category_options" );
+            	//setMessage( "importing_data_element_category_options" );
                 
                 BatchHandler<DataElementCategoryOption> batchHandler = batchHandlerFactory.createBatchHandler( DataElementCategoryOptionBatchHandler.class );
                 
@@ -1117,15 +1134,5 @@
             }
             
         }
-                
-        //setMessage( "import_process_done" );
-        
-        StreamUtils.closeInputStream( zipIn );
-
-        reader.closeReader();
-
-        NameMappingUtil.clearMapping();
-        
-        cacheManager.clearCache();
-    }
+    }           
 }