← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 1938: Centralized import of calculated data element

 

------------------------------------------------------------
revno: 1938
committer: Lars <larshelg@larshelg-laptop>
branch nick: trunk
timestamp: Tue 2010-06-01 09:57:57 +0200
message:
  Centralized import of calculated data element
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/CalculatedDataElementImporter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/service/DefaultImportObjectManager.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/importer/CalculatedDataElementImporter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/CalculatedDataElementImporter.java	2010-05-31 13:53:07 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/CalculatedDataElementImporter.java	2010-06-01 07:57:57 +0000
@@ -27,7 +27,6 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import org.amplecode.quick.BatchHandler;
 import org.hisp.dhis.dataelement.CalculatedDataElement;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementService;
@@ -49,9 +48,8 @@
     {
     }
     
-    public CalculatedDataElementImporter( BatchHandler<CalculatedDataElement> batchHandler, DataElementService dataElementService )
+    public CalculatedDataElementImporter( DataElementService dataElementService )
     {
-        this.batchHandler = batchHandler;
         this.dataElementService = dataElementService;
     }
     

=== 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-31 16:47:43 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/service/DefaultImportObjectManager.java	2010-06-01 07:57:57 +0000
@@ -65,6 +65,7 @@
 import org.hisp.dhis.importexport.ImportStrategy;
 import org.hisp.dhis.importexport.ImportType;
 import org.hisp.dhis.importexport.Importer;
+import org.hisp.dhis.importexport.importer.CalculatedDataElementImporter;
 import org.hisp.dhis.importexport.importer.DataDictionaryImporter;
 import org.hisp.dhis.importexport.importer.DataElementCategoryComboImporter;
 import org.hisp.dhis.importexport.importer.DataElementCategoryImporter;
@@ -411,11 +412,11 @@
     public void importDataElements()
     {
         BatchHandler<DataElement> batchHandler = batchHandlerFactory.createBatchHandler( DataElementBatchHandler.class );
+
+        batchHandler.init();
         
         Map<Object, Integer> categoryComboMapping = objectMappingGenerator.getCategoryComboMapping( false );
         
-        batchHandler.init();
-        
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( DataElement.class );
         
         Importer<DataElement> importer = new DataElementImporter( batchHandler, dataElementService );
@@ -443,33 +444,15 @@
 
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( CalculatedDataElement.class );
 
+        Importer<CalculatedDataElement> importer = new CalculatedDataElementImporter( dataElementService );
+        
         for ( ImportObject importObject : importObjects )
         {
             CalculatedDataElement object = (CalculatedDataElement) importObject.getObject();
-
-            NameMappingUtil.addDataElementMapping( object.getId(), object.getName() );
-
-            if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                DataElement compareObject = (DataElement) importObject.getCompareObject();
-                
-                object.setId( compareObject.getId() );
-            }
-
             object.getCategoryCombo().setId( categoryComboMapping.get( object.getCategoryCombo().getId() ) );
             object.getExpression().setExpression( expressionService.convertExpression( 
                 object.getExpression().getExpression(), dataElementMapping, categoryOptionComboMapping ) );
-            
-            importObject.setObject( object );
-            
-            if ( importObject.getStatus() == ImportObjectStatus.NEW )
-            {
-                dataElementService.addDataElement( object );
-            }
-            else if ( importObject.getStatus() == ImportObjectStatus.UPDATE )
-            {
-                dataElementService.updateDataElement( object );
-            }
+            importer.importObject( object, params );            
         }
         
         importObjectStore.deleteImportObjects( CalculatedDataElement.class );
@@ -794,10 +777,8 @@
         {
             GroupMemberAssociation object = (GroupMemberAssociation) importObject.getObject();
             
-            OrganisationUnit child = organisationUnitService.getOrganisationUnit( organisationUnitMapping.get( object.getMemberId() ) );
-            
-            OrganisationUnit parent = organisationUnitService.getOrganisationUnit( organisationUnitMapping.get( object.getGroupId() ) );
-            
+            OrganisationUnit child = organisationUnitService.getOrganisationUnit( organisationUnitMapping.get( object.getMemberId() ) );            
+            OrganisationUnit parent = organisationUnitService.getOrganisationUnit( organisationUnitMapping.get( object.getGroupId() ) );            
             child.setParent( parent );
             
             batchHandler.updateObject( child );