← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1931: Centralized part of the code from ImportObjectManager

 

------------------------------------------------------------
revno: 1931
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Mon 2010-05-31 17:06:26 +0200
message:
  Centralized part of the code from ImportObjectManager
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OlapUrlImporter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitImporter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitLevelImporter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/service/DefaultImportObjectManager.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/importer/OlapUrlImporter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OlapUrlImporter.java	2010-05-31 13:53:07 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OlapUrlImporter.java	2010-05-31 15:06:26 +0000
@@ -27,7 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import org.amplecode.quick.BatchHandler;
 import org.hisp.dhis.importexport.GroupMemberType;
 import org.hisp.dhis.importexport.ImportParams;
 import org.hisp.dhis.importexport.Importer;
@@ -47,9 +46,8 @@
     {
     }
     
-    public OlapUrlImporter( BatchHandler<OlapURL> batchHandler, OlapURLService olapURLService )
+    public OlapUrlImporter( OlapURLService olapURLService )
     {
-        this.batchHandler = batchHandler;
         this.olapURLService = olapURLService;
     }
     

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitImporter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitImporter.java	2010-05-31 13:53:07 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitImporter.java	2010-05-31 15:06:26 +0000
@@ -27,6 +27,8 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import static org.apache.commons.lang.StringUtils.defaultIfEmpty;
+
 import org.amplecode.quick.BatchHandler;
 import org.hisp.dhis.importexport.GroupMemberType;
 import org.hisp.dhis.importexport.ImportParams;
@@ -51,9 +53,10 @@
     {
     }
     
-    public OrganisationUnitImporter( BatchHandler<OrganisationUnit> batchHandler, OrganisationUnitService organisationUnitService )
+    public OrganisationUnitImporter( BatchHandler<OrganisationUnit> batchHandler, BatchHandler<Source> sourceBatchHandler, OrganisationUnitService organisationUnitService )
     {
         this.batchHandler = batchHandler;
+        this.sourceBatchHandler = sourceBatchHandler;
         this.organisationUnitService = organisationUnitService;
     }
     
@@ -86,9 +89,9 @@
         match.setClosedDate( object.getClosedDate() );
         match.setActive( object.isActive() );
         match.setComment( object.getComment() );
-        match.setGeoCode( object.getGeoCode() );
-        match.setFeatureType( object.getFeatureType() );
-        match.setCoordinates( object.getCoordinates() );
+        match.setGeoCode( defaultIfEmpty( object.getGeoCode(), match.getGeoCode() ) );
+        match.setFeatureType( defaultIfEmpty( object.getFeatureType(), match.getFeatureType() ) );
+        match.setCoordinates( defaultIfEmpty( object.getCoordinates(), match.getCoordinates() ) );
         match.setLastUpdated( object.getLastUpdated() );
         
         organisationUnitService.updateOrganisationUnit( match );

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitLevelImporter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitLevelImporter.java	2010-05-31 13:53:07 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/OrganisationUnitLevelImporter.java	2010-05-31 15:06:26 +0000
@@ -27,7 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import org.amplecode.quick.BatchHandler;
 import org.hisp.dhis.importexport.GroupMemberType;
 import org.hisp.dhis.importexport.ImportParams;
 import org.hisp.dhis.importexport.Importer;
@@ -47,9 +46,8 @@
     {
     }
     
-    public OrganisationUnitLevelImporter( BatchHandler<OrganisationUnitLevel> batchHandler, OrganisationUnitService organisationUnitService )
+    public OrganisationUnitLevelImporter( OrganisationUnitService organisationUnitService )
     {
-        this.batchHandler = batchHandler;
         this.organisationUnitService = organisationUnitService;
     }
     

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/service/DefaultImportObjectManager.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/service/DefaultImportObjectManager.java	2010-05-28 19:17:07 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/service/DefaultImportObjectManager.java	2010-05-31 15:06:26 +0000
@@ -37,6 +37,7 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.datadictionary.DataDictionary;
+import org.hisp.dhis.datadictionary.DataDictionaryService;
 import org.hisp.dhis.datadictionary.ExtendedDataElement;
 import org.hisp.dhis.dataelement.CalculatedDataElement;
 import org.hisp.dhis.dataelement.DataElement;
@@ -50,6 +51,7 @@
 import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.dataset.CompleteDataSetRegistration;
 import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.expression.ExpressionService;
 import org.hisp.dhis.importexport.GroupMemberAssociation;
@@ -60,12 +62,34 @@
 import org.hisp.dhis.importexport.ImportObjectManager;
 import org.hisp.dhis.importexport.ImportObjectStatus;
 import org.hisp.dhis.importexport.ImportObjectStore;
+import org.hisp.dhis.importexport.ImportParams;
+import org.hisp.dhis.importexport.ImportStrategy;
+import org.hisp.dhis.importexport.ImportType;
+import org.hisp.dhis.importexport.Importer;
+import org.hisp.dhis.importexport.importer.DataDictionaryImporter;
+import org.hisp.dhis.importexport.importer.DataElementCategoryComboImporter;
+import org.hisp.dhis.importexport.importer.DataElementCategoryImporter;
+import org.hisp.dhis.importexport.importer.DataElementCategoryOptionImporter;
+import org.hisp.dhis.importexport.importer.DataElementGroupImporter;
+import org.hisp.dhis.importexport.importer.DataElementGroupSetImporter;
+import org.hisp.dhis.importexport.importer.DataSetImporter;
+import org.hisp.dhis.importexport.importer.GroupSetImporter;
+import org.hisp.dhis.importexport.importer.IndicatorGroupImporter;
+import org.hisp.dhis.importexport.importer.IndicatorGroupSetImporter;
+import org.hisp.dhis.importexport.importer.IndicatorTypeImporter;
+import org.hisp.dhis.importexport.importer.OlapUrlImporter;
+import org.hisp.dhis.importexport.importer.OrganisationUnitGroupImporter;
+import org.hisp.dhis.importexport.importer.OrganisationUnitImporter;
+import org.hisp.dhis.importexport.importer.OrganisationUnitLevelImporter;
+import org.hisp.dhis.importexport.importer.ReportTableImporter;
+import org.hisp.dhis.importexport.importer.ValidationRuleImporter;
 import org.hisp.dhis.importexport.mapping.GroupMemberAssociationVerifier;
 import org.hisp.dhis.importexport.mapping.NameMappingUtil;
 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;
 import org.hisp.dhis.jdbc.batchhandler.CategoryComboCategoryAssociationBatchHandler;
@@ -104,11 +128,13 @@
 import org.hisp.dhis.olap.OlapURLService;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroup;
+import org.hisp.dhis.organisationunit.OrganisationUnitGroupService;
 import org.hisp.dhis.organisationunit.OrganisationUnitGroupSet;
 import org.hisp.dhis.organisationunit.OrganisationUnitLevel;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.reporttable.ReportTable;
+import org.hisp.dhis.reporttable.ReportTableService;
 import org.hisp.dhis.source.Source;
 import org.hisp.dhis.validation.ValidationRule;
 import org.hisp.dhis.validation.ValidationRuleService;
@@ -124,6 +150,8 @@
 {
     private static final Log log = LogFactory.getLog( DefaultImportObjectManager.class );
 
+    private final ImportParams params = new ImportParams( ImportType.IMPORT, ImportStrategy.NEW_AND_UPDATES, true );
+    
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
@@ -158,6 +186,27 @@
     {
         this.dataElementService = dataElementService;
     }
+    
+    private DataDictionaryService dataDictionaryService;
+    
+    public void setDataDictionaryService( DataDictionaryService dataDictionaryService )
+    {
+        this.dataDictionaryService = dataDictionaryService;
+    }
+
+    private IndicatorService indicatorService;
+
+    public void setIndicatorService( IndicatorService indicatorService )
+    {
+        this.indicatorService = indicatorService;
+    }
+    
+    private DataSetService dataSetService;
+
+    public void setDataSetService( DataSetService dataSetService )
+    {
+        this.dataSetService = dataSetService;
+    }
 
     private OrganisationUnitService organisationUnitService;
 
@@ -165,6 +214,13 @@
     {
         this.organisationUnitService = organisationUnitService;
     }
+    
+    private OrganisationUnitGroupService organisationUnitGroupService;
+
+    public void setOrganisationUnitGroupService( OrganisationUnitGroupService organisationUnitGroupService )
+    {
+        this.organisationUnitGroupService = organisationUnitGroupService;
+    }
 
     private ValidationRuleService validationRuleService;
 
@@ -193,6 +249,13 @@
     {
         this.importDataValueService = importDataValueService;
     }
+    
+    private ReportTableService reportTableService;
+
+    public void setReportTableService( ReportTableService reportTableService )
+    {
+        this.reportTableService = reportTableService;
+    }
 
     // -------------------------------------------------------------------------
     // ImportObjectManager implementation
@@ -207,22 +270,11 @@
         
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( DataElementCategoryOption.class );
         
+        Importer<DataElementCategoryOption> importer = new DataElementCategoryOptionImporter( batchHandler, categoryService );
+        
         for ( ImportObject importObject : importObjects )
         {
-            DataElementCategoryOption object = (DataElementCategoryOption) importObject.getObject();
-            
-            NameMappingUtil.addCategoryOptionMapping( object.getId(), object.getName() );
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                DataElementCategoryOption compareObject = (DataElementCategoryOption) importObject.getCompareObject();
-                
-                object.setId( compareObject.getId() );
-            }
-            
-            importObject.setObject( object );
-            
-            addOrUpdateObject( batchHandler, importObject );
+            importer.importObject( (DataElementCategoryOption) importObject.getObject(), params );
         }
         
         batchHandler.flush();
@@ -241,22 +293,11 @@
         
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( DataElementCategory.class );
 
+        Importer<DataElementCategory> importer = new DataElementCategoryImporter( batchHandler, categoryService );
+        
         for ( ImportObject importObject : importObjects )
         {
-            DataElementCategory object = (DataElementCategory) importObject.getObject();
-            
-            NameMappingUtil.addCategoryMapping( object.getId(), object.getName() );
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                DataElementCategory compareObject = (DataElementCategory) importObject.getCompareObject();
-                
-                object.setId( compareObject.getId() );
-            }            
-
-            importObject.setObject( object );
-            
-            addOrUpdateObject( batchHandler, importObject );
+            importer.importObject( (DataElementCategory) importObject.getObject(), params );
         }
 
         batchHandler.flush();
@@ -275,22 +316,11 @@
         
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( DataElementCategoryCombo.class );
 
+        Importer<DataElementCategoryCombo> importer = new DataElementCategoryComboImporter( batchHandler, categoryService );
+        
         for ( ImportObject importObject : importObjects )
         {
-            DataElementCategoryCombo object = (DataElementCategoryCombo) importObject.getObject();
-            
-            NameMappingUtil.addCategoryComboMapping( object.getId(), object.getName() );
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                DataElementCategoryCombo compareObject = (DataElementCategoryCombo) importObject.getCompareObject();
-                
-                object.setId( compareObject.getId() );
-            }
-            
-            importObject.setObject( object );
-            
-            addOrUpdateObject( batchHandler, importObject );
+            importer.importObject( (DataElementCategoryCombo) importObject.getObject(), params );
         }
         
         batchHandler.flush();
@@ -497,22 +527,11 @@
             
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( DataElementGroup.class );
 
+        Importer<DataElementGroup> importer = new DataElementGroupImporter( batchHandler, dataElementService );
+        
         for ( ImportObject importObject : importObjects )
         {
-            DataElementGroup object = (DataElementGroup) importObject.getObject();
-
-            NameMappingUtil.addDataElementGroupMapping( object.getId(), object.getName() );
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                DataElementGroup compareObject = (DataElementGroup) importObject.getCompareObject();
-                
-                object.setId( compareObject.getId() );
-            }
-            
-            importObject.setObject( object );
-            
-            addOrUpdateObject( batchHandler, importObject );
+            importer.importObject( (DataElementGroup) importObject.getObject(), params );
         }
         
         batchHandler.flush();
@@ -543,22 +562,11 @@
         
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( DataElementGroupSet.class );
         
+        Importer<DataElementGroupSet> importer = new DataElementGroupSetImporter( batchHandler, dataElementService );
+        
         for ( ImportObject importObject : importObjects )
         {
-            DataElementGroupSet object = (DataElementGroupSet) importObject.getObject();
-            
-            NameMappingUtil.addDataElementGroupSetMapping( object.getId(), object.getName() );
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                DataElementGroupSet compareObject = (DataElementGroupSet) importObject.getCompareObject();
-                
-                object.setId( compareObject.getId() );
-            }
-            
-            importObject.setObject( object );
-            
-            addOrUpdateObject( batchHandler, importObject );
+            importer.importObject( (DataElementGroupSet) importObject.getObject(), params );
         }
         
         batchHandler.flush();
@@ -589,22 +597,11 @@
         
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( IndicatorType.class );
 
+        Importer<IndicatorType> importer = new IndicatorTypeImporter( batchHandler, indicatorService );
+        
         for ( ImportObject importObject : importObjects )
         {   
-            IndicatorType object = (IndicatorType) importObject.getObject();
-
-            NameMappingUtil.addIndicatorTypeMapping( object.getId(), object.getName() );
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                IndicatorType compareObject = (IndicatorType) importObject.getCompareObject();
-                
-                object.setId( compareObject.getId() );
-            }
-            
-            importObject.setObject( object );
-            
-            addOrUpdateObject( batchHandler, importObject );
+            importer.importObject( (IndicatorType) importObject.getObject(), params );
         }
         
         batchHandler.flush();
@@ -695,22 +692,11 @@
         
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( IndicatorGroup.class );
 
+        Importer<IndicatorGroup> importer = new IndicatorGroupImporter( batchHandler, indicatorService );
+        
         for ( ImportObject importObject : importObjects )
         {   
-            IndicatorGroup object = (IndicatorGroup) importObject.getObject();
-
-            NameMappingUtil.addIndicatorGroupMapping( object.getId(), object.getName() );
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                IndicatorGroup compareObject = (IndicatorGroup) importObject.getCompareObject();
-                
-                object.setId( compareObject.getId() );
-            }
-            
-            importObject.setObject( object );
-            
-            addOrUpdateObject( batchHandler, importObject );          
+            importer.importObject( (IndicatorGroup) importObject.getObject(), params );
         }
         
         batchHandler.flush();
@@ -741,22 +727,11 @@
         
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( IndicatorGroupSet.class );
         
+        Importer<IndicatorGroupSet> importer = new IndicatorGroupSetImporter( batchHandler, indicatorService );
+        
         for ( ImportObject importObject : importObjects )
         {
-            IndicatorGroupSet object = (IndicatorGroupSet) importObject.getObject();
-            
-            NameMappingUtil.addIndicatorGroupSetMapping( object.getId(), object.getName() );
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                IndicatorGroupSet compareObject = (IndicatorGroupSet) importObject.getCompareObject();
-                
-                object.setId( compareObject.getId() );
-            }
-            
-            importObject.setObject( object );
-            
-            addOrUpdateObject( batchHandler, importObject );
+            importer.importObject( (IndicatorGroupSet) importObject.getObject(), params );
         }
         
         batchHandler.flush();
@@ -787,22 +762,11 @@
         
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( DataDictionary.class );
         
+        Importer<DataDictionary> importer = new DataDictionaryImporter( batchHandler, dataDictionaryService );
+        
         for ( ImportObject importObject : importObjects )
         {
-            DataDictionary object = (DataDictionary) importObject.getObject();
-            
-            NameMappingUtil.addDataDictionaryMapping( object.getId(), object.getName() );
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                DataDictionary compareObject = (DataDictionary) importObject.getCompareObject();
-                
-                object.setId( compareObject.getId() );
-            }
-            
-            importObject.setObject( object );
-            
-            addOrUpdateObject( batchHandler, importObject );
+            importer.importObject( (DataDictionary) importObject.getObject(), params );
         }
         
         batchHandler.flush();
@@ -821,22 +785,11 @@
         
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( DataSet.class );
         
+        Importer<DataSet> importer = new DataSetImporter( batchHandler, dataSetService );
+        
         for ( ImportObject importObject : importObjects )
         {
-            DataSet object = (DataSet) importObject.getObject();
-
-            NameMappingUtil.addDataSetMapping( object.getId(), object.getName() );
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                DataSet compareObject = (DataSet) importObject.getCompareObject();
-                
-                object.setId( compareObject.getId() );
-            }
-            
-            importObject.setObject( object );
-            
-            addOrUpdateObject( batchHandler, importObject );         
+            importer.importObject( (DataSet) importObject.getObject(), params );    
         }
         
         batchHandler.flush();
@@ -893,28 +846,11 @@
         
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( OrganisationUnit.class );
         
+        Importer<OrganisationUnit> importer = new OrganisationUnitImporter( organisationUnitBatchHandler, sourceBatchHandler, organisationUnitService );
+        
         for ( ImportObject importObject : importObjects )
         {
-            OrganisationUnit object = (OrganisationUnit) importObject.getObject();
-
-            NameMappingUtil.addOrganisationUnitMapping( object.getId(), object.getName() );
-            
-            if ( importObject.getStatus() == ImportObjectStatus.NEW )
-            {
-                int id = sourceBatchHandler.insertObject( object, true );
-                
-                object.setId( id );
-            }
-            else if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                OrganisationUnit compareObject = (OrganisationUnit) importObject.getCompareObject();
-                
-                object.setId( compareObject.getId() );
-            }
-            
-            importObject.setObject( object );
-            
-            addOrUpdateObject( organisationUnitBatchHandler, importObject );
+            importer.importObject( (OrganisationUnit) importObject.getObject(), params );
         }
         
         sourceBatchHandler.flush();
@@ -965,22 +901,11 @@
         
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( OrganisationUnitGroup.class );
         
+        Importer<OrganisationUnitGroup> importer = new OrganisationUnitGroupImporter( batchHandler, organisationUnitGroupService );
+        
         for ( ImportObject importObject : importObjects )
         {
-            OrganisationUnitGroup object = (OrganisationUnitGroup) importObject.getObject();
-
-            NameMappingUtil.addOrganisationUnitGroupMapping( object.getId(), object.getName() );
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                OrganisationUnitGroup compareObject = (OrganisationUnitGroup) importObject.getCompareObject();
-                
-                object.setId( compareObject.getId() );
-            }
-            
-            importObject.setObject( object );
-            
-            addOrUpdateObject( batchHandler, importObject );
+            importer.importObject( (OrganisationUnitGroup) importObject.getObject(), params );
         }
         
         batchHandler.flush();
@@ -1011,22 +936,11 @@
         
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( OrganisationUnitGroupSet.class );
         
+        Importer<OrganisationUnitGroupSet> importer = new GroupSetImporter( batchHandler, organisationUnitGroupService );
+        
         for ( ImportObject importObject : importObjects )
         {
-            OrganisationUnitGroupSet object = (OrganisationUnitGroupSet) importObject.getObject();
-
-            NameMappingUtil.addGroupSetMapping( object.getId(), object.getName() );
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                OrganisationUnitGroupSet compareObject = (OrganisationUnitGroupSet) importObject.getCompareObject();
-                
-                object.setId( compareObject.getId() );
-            }
-            
-            importObject.setObject( object );
-            
-            addOrUpdateObject( batchHandler, importObject );            
+            importer.importObject( (OrganisationUnitGroupSet) importObject.getObject(), params );         
         }
         
         batchHandler.flush();
@@ -1053,22 +967,11 @@
     {
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( OrganisationUnitLevel.class );
         
+        Importer<OrganisationUnitLevel> importer = new OrganisationUnitLevelImporter( organisationUnitService );
+        
         for ( ImportObject importObject : importObjects )
         {
-            OrganisationUnitLevel object = (OrganisationUnitLevel) importObject.getObject();
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                OrganisationUnitLevel compare = (OrganisationUnitLevel) importObject.getCompareObject();
-                
-                object = updateOrganisationUnitLevel( compare, object );
-                
-                organisationUnitService.updateOrganisationUnitLevel( object );                
-            }
-            else if ( importObject.getStatus() == ImportObjectStatus.NEW )
-            {
-                organisationUnitService.addOrganisationUnitLevel( object );
-            }
+            importer.importObject( (OrganisationUnitLevel) importObject.getObject(), params );
         }
         
         importObjectStore.deleteImportObjects( OrganisationUnitLevel.class );
@@ -1093,30 +996,11 @@
     {
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( ValidationRule.class );
         
+        Importer<ValidationRule> importer = new ValidationRuleImporter( validationRuleService, expressionService );
+        
         for ( ImportObject importObject : importObjects )
         {
-            ValidationRule object = (ValidationRule) importObject.getObject();
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                ValidationRule compare = (ValidationRule) importObject.getCompareObject();
-                
-                validationRuleService.updateValidationRule( compare ); // Reload because of Expression
-                
-                object = updateValidationRule( compare, object );
-                
-                expressionService.updateExpression( object.getLeftSide() );
-                expressionService.updateExpression( object.getRightSide() );
-                                
-                validationRuleService.updateValidationRule( object );
-            }
-            else if ( importObject.getStatus() == ImportObjectStatus.NEW )
-            {
-                expressionService.addExpression( object.getLeftSide() );
-                expressionService.addExpression( object.getRightSide() );
-                                
-                validationRuleService.saveValidationRule( object );
-            }
+            importer.importObject( (ValidationRule) importObject.getObject(), params );
         }
         
         importObjectStore.deleteImportObjects( ValidationRule.class );
@@ -1158,22 +1042,11 @@
         
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( ReportTable.class );
         
+        Importer<ReportTable> importer = new ReportTableImporter( reportTableService );
+        
         for ( ImportObject importObject : importObjects )
         {
-            ReportTable object = (ReportTable) importObject.getObject();
-            
-            NameMappingUtil.addReportTableMapping( object.getId(), object.getName() );
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                ReportTable compareObject = (ReportTable) importObject.getCompareObject();
-                
-                object.setId( compareObject.getId() );
-            }
-            
-            importObject.setObject( object );
-            
-            addOrUpdateObject( batchHandler, importObject );
+            importer.importObject( (ReportTable) importObject.getObject(), params );
         }
         
         batchHandler.flush();
@@ -1188,22 +1061,11 @@
     {
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( OlapURL.class );
         
+        Importer<OlapURL> importer = new OlapUrlImporter( olapURLService );
+        
         for ( ImportObject importObject : importObjects )
         {
-            OlapURL object = (OlapURL) importObject.getObject();
-            
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                OlapURL compare = (OlapURL) importObject.getObject();
-                
-                object = updateOlapURL( compare, object );
-                
-                olapURLService.updateOlapURL( object );
-            }
-            else if ( importObject.getStatus() == ImportObjectStatus.NEW )
-            {
-                olapURLService.saveOlapURL( object );
-            }            
+            importer.importObject( (OlapURL) importObject.getObject(), params );   
         }
         
         importObjectStore.deleteImportObjects( OlapURL.class );
@@ -1339,36 +1201,4 @@
         
         importObjectStore.deleteImportObjects( type );
     }
-
-    private OrganisationUnitLevel updateOrganisationUnitLevel( OrganisationUnitLevel original, OrganisationUnitLevel update )
-    {
-        original.setLevel( update.getLevel() );
-        original.setName( update.getName() );
-        
-        return original;
-    }
-    
-    private ValidationRule updateValidationRule( ValidationRule original, ValidationRule update )
-    {
-        original.setName( update.getName() );
-        original.setDescription( update.getDescription() );
-        original.setType( update.getType() );
-        original.setOperator( update.getOperator() );
-        original.getLeftSide().setExpression( update.getLeftSide().getExpression() );
-        original.getLeftSide().setDescription( update.getLeftSide().getDescription()  );
-        original.getLeftSide().setDataElementsInExpression( update.getLeftSide().getDataElementsInExpression() );
-        original.getRightSide().setExpression( update.getRightSide().getExpression() );
-        original.getRightSide().setDescription( update.getRightSide().getDescription() );
-        original.getRightSide().setDataElementsInExpression( update.getRightSide().getDataElementsInExpression() );
-        
-        return original;
-    }
-
-    private OlapURL updateOlapURL( OlapURL original, OlapURL update )
-    {
-        original.setName( update.getName() );
-        original.setUrl( update.getUrl() );
-        
-        return original;
-    }
 }

=== 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	2010-05-18 19:22:26 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml	2010-05-31 15:06:26 +0000
@@ -81,14 +81,16 @@
 		<property name="categoryService"
 			ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
 		<property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
-		<property name="organisationUnitService"
-			ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
-		<property name="validationRuleService"
-			ref="org.hisp.dhis.validation.ValidationRuleService" />
+		<property name="dataDictionaryService" ref="org.hisp.dhis.datadictionary.DataDictionaryService" />
+		<property name="indicatorService" ref="org.hisp.dhis.indicator.IndicatorService" />
+		<property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+		<property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+		<property name="organisationUnitGroupService" ref="org.hisp.dhis.organisationunit.OrganisationUnitGroupService" />
+		<property name="validationRuleService" ref="org.hisp.dhis.validation.ValidationRuleService" />
 		<property name="olapURLService" ref="org.hisp.dhis.olap.OlapURLService" />
 		<property name="expressionService" ref="org.hisp.dhis.expression.ExpressionService" />
-		<property name="importDataValueService"
-			ref="org.hisp.dhis.importexport.ImportDataValueService" />
+		<property name="importDataValueService"	ref="org.hisp.dhis.importexport.ImportDataValueService" />
+		<property name="reportTableService" ref="org.hisp.dhis.reporttable.ReportTableService" />
 	</bean>
 
 	<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->