← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2596: Fixed bug related to preview of data entry forms

 

------------------------------------------------------------
revno: 2596
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-01-17 14:40:50 +0100
message:
  Fixed bug related to preview of data entry forms
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DXFConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataEntryFormConverter.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/DataEntryFormImporter.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/test/java/org/hisp/dhis/importexport/dxf/DXFImportServiceTest.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/converter/DXFConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DXFConverter.java	2011-01-17 11:14:18 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DXFConverter.java	2011-01-17 13:40:50 +0000
@@ -734,7 +734,7 @@
                 BatchHandler<DataEntryForm> batchHandler = batchHandlerFactory.createBatchHandler(
                     DataEntryFormBatchHandler.class ).init();
 
-                XMLConverter converter = new DataEntryFormConverter( importObjectService, dataEntryFormService, 
+                XMLConverter converter = new DataEntryFormConverter( batchHandler, importObjectService, dataEntryFormService, 
                     objectMappingGenerator.getDataElementMapping( params.skipMapping() ), objectMappingGenerator.getCategoryComboMapping( params.skipMapping() ) );
 
                 converterInvoker.invokeRead( converter, reader, params );

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataEntryFormConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataEntryFormConverter.java	2011-01-17 11:53:20 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataEntryFormConverter.java	2011-01-17 13:40:50 +0000
@@ -30,8 +30,8 @@
 import java.util.Collection;
 import java.util.Map;
 import java.util.regex.Matcher;
-import java.util.regex.Pattern;
 
+import org.amplecode.quick.BatchHandler;
 import org.amplecode.staxwax.reader.XMLReader;
 import org.amplecode.staxwax.writer.XMLWriter;
 import org.apache.commons.logging.Log;
@@ -55,8 +55,6 @@
 {
     private static final Log log = LogFactory.getLog( DataEntryFormConverter.class );
     
-    private static final Pattern ID_PATTERN = Pattern.compile( "value\\[(.*)\\].value:value\\[(.*)\\].value" );
-    
     public static final String COLLECTION_NAME = "dataEntryForms";
     public static final String ELEMENT_NAME = "dataEntryForm";
     private static final String FIELD_ID = "id";
@@ -81,11 +79,13 @@
     /**
      * Constructor for read operations.
      */
-    public DataEntryFormConverter( ImportObjectService importObjectService,
+    public DataEntryFormConverter( BatchHandler<DataEntryForm> batchHandler,
+        ImportObjectService importObjectService,
         DataEntryFormService dataEntryFormService,
         Map<Object, Integer> dataElementMapping, 
         Map<Object, Integer> categoryOptionComboMapping )
     {
+        this.batchHandler = batchHandler;
         this.importObjectService = importObjectService;
         this.dataEntryFormService = dataEntryFormService;
         this.dataElementMapping = dataElementMapping;
@@ -127,14 +127,14 @@
         {
             final DataEntryForm dataEntryForm = new DataEntryForm();
 
-            reader.moveToStartElement( FIELD_ID );
-            dataEntryForm.setId( Integer.parseInt( reader.getElementValue() ) );
-
-            reader.moveToStartElement( FIELD_NAME );
-            dataEntryForm.setName( reader.getElementValue() );
-            reader.moveToStartElement( FIELD_HTMLCODE );
-            dataEntryForm.setHtmlCode( proccessHtmlCode( reader.getElementValue(), dataEntryForm.getName() ) );
-
+            final Map<String, String> values = reader.readElements( ELEMENT_NAME );
+            
+            String htmlCode = values.get( FIELD_HTMLCODE );
+            
+            dataEntryForm.setId( Integer.parseInt( values.get( FIELD_ID ) ) );
+            dataEntryForm.setName( values.get( FIELD_NAME ) );            
+            dataEntryForm.setHtmlCode( processHtmlCode( htmlCode, dataEntryForm.getName() ) );
+            
             importObject( dataEntryForm, params );
         }
     }
@@ -143,7 +143,7 @@
     // Support method
     // -------------------------------------------------------------------------
 
-    private String proccessHtmlCode( String htmlCode, String name )
+    private String processHtmlCode( String htmlCode, String name )
     {
         if ( htmlCode == null )
         {
@@ -152,7 +152,7 @@
 
         StringBuffer buffer = new StringBuffer();
 
-        Matcher matcher = ID_PATTERN.matcher( htmlCode );
+        Matcher matcher = DataEntryForm.INPUT_PATTERN.matcher( htmlCode );
         
         while ( matcher.find() )
         {

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/DataEntryFormImporter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/DataEntryFormImporter.java	2011-01-17 11:14:18 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/DataEntryFormImporter.java	2011-01-17 13:40:50 +0000
@@ -27,6 +27,7 @@
 
 package org.hisp.dhis.importexport.importer;
 
+import org.amplecode.quick.BatchHandler;
 import org.hisp.dhis.dataentryform.DataEntryForm;
 import org.hisp.dhis.dataentryform.DataEntryFormService;
 import org.hisp.dhis.importexport.GroupMemberType;
@@ -53,8 +54,9 @@
     {
     }
 
-    public DataEntryFormImporter( DataEntryFormService dataEntryFormService )
+    public DataEntryFormImporter( BatchHandler<DataEntryForm> batchHandler, DataEntryFormService dataEntryFormService )
     {
+        this.batchHandler = batchHandler;
         this.dataEntryFormService = dataEntryFormService;
     }
 
@@ -73,7 +75,7 @@
     @Override
     protected void importUnique( DataEntryForm object )
     {
-        dataEntryFormService.addDataEntryForm( object );
+        batchHandler.addObject( object );
     }
 
     @Override
@@ -101,5 +103,4 @@
 
         return false;
     }
-
 }

=== 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	2011-01-17 12:30:42 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/service/DefaultImportObjectManager.java	2011-01-17 13:40:50 +0000
@@ -118,6 +118,7 @@
 import org.hisp.dhis.jdbc.batchhandler.DataElementGroupMemberBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.DataElementGroupSetBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.DataElementGroupSetMemberBatchHandler;
+import org.hisp.dhis.jdbc.batchhandler.DataEntryFormBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.DataSetBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.DataSetMemberBatchHandler;
 import org.hisp.dhis.jdbc.batchhandler.DataSetSourceAssociationBatchHandler;
@@ -606,8 +607,7 @@
     @Transactional
     public void importIndicators()
     {
-        BatchHandler<Indicator> batchHandler = batchHandlerFactory.createBatchHandler( IndicatorBatchHandler.class )
-            .init();
+        BatchHandler<Indicator> batchHandler = batchHandlerFactory.createBatchHandler( IndicatorBatchHandler.class ).init();
 
         Map<Object, Integer> indicatorTypeMapping = objectMappingGenerator.getIndicatorTypeMapping( false );
         Map<Object, Integer> dataElementMapping = objectMappingGenerator.getDataElementMapping( false );
@@ -752,15 +752,19 @@
     @Transactional
     public void importDataEntryForms()
     {
+        BatchHandler<DataEntryForm> batchHandler = batchHandlerFactory.createBatchHandler( DataEntryFormBatchHandler.class ).init();
+        
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( DataEntryForm.class );
 
-        Importer<DataEntryForm> importer = new DataEntryFormImporter( dataEntryFormService );
+        Importer<DataEntryForm> importer = new DataEntryFormImporter( batchHandler, dataEntryFormService );
 
         for ( ImportObject importObject : importObjects )
         {
             importer.importObject( (DataEntryForm) importObject.getObject(), params );
         }
 
+        batchHandler.flush();
+        
         importObjectStore.deleteImportObjects( DataEntryForm.class );
 
         log.info( "Imported DataEntryForms" );
@@ -771,13 +775,22 @@
     {
         BatchHandler<DataSet> batchHandler = batchHandlerFactory.createBatchHandler( DataSetBatchHandler.class ).init();
 
+        Map<Object, Integer> dataEntryFormMapping = objectMappingGenerator.getDataEntryFormMapping( false );
+        
         Collection<ImportObject> importObjects = importObjectStore.getImportObjects( DataSet.class );
 
         Importer<DataSet> importer = new DataSetImporter( batchHandler, dataSetService );
 
         for ( ImportObject importObject : importObjects )
         {
-            importer.importObject( (DataSet) importObject.getObject(), params );
+            DataSet object = (DataSet) importObject.getObject();
+            
+            if ( object.getDataEntryForm() != null )
+            {
+                object.getDataEntryForm().setId( dataEntryFormMapping.get( object.getDataEntryForm().getId() ) );
+            }
+            
+            importer.importObject( object, params );
         }
 
         batchHandler.flush();

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/DXFImportServiceTest.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/DXFImportServiceTest.java	2010-10-29 08:56:13 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf/DXFImportServiceTest.java	2011-01-17 13:40:50 +0000
@@ -281,7 +281,6 @@
         importService.importData( importParams, inputStreamExcelx );
 
         assertEquals( organisationUnitService.getAllOrganisationUnits().size(), 49 );
-
     }
 
     @Ignore