dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #09632
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2588: Fixed bug in dataentryform import
------------------------------------------------------------
revno: 2588
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2011-01-17 12:14:18 +0100
message:
Fixed bug in dataentryform import
modified:
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/ConceptConverter.java
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/dxf/exporter/DefaultDXFExportService.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/DataEntryFormImporter.java
dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/light_blue/light_blue.css
dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJrxmlResult.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/ConceptConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/ConceptConverter.java 2010-09-17 21:30:59 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/ConceptConverter.java 2011-01-17 11:14:18 +0000
@@ -32,50 +32,19 @@
* @author bobj
* @version created 15-Sep-2010
*/
-import org.hisp.dhis.concept.Concept;
-import org.hisp.dhis.concept.ConceptService;
-import org.hisp.dhis.importexport.importer.ConceptImporter;
-
-
-/*
- * Copyright (c) 2004-2010, University of Oslo
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions are met:
- * * Redistributions of source code must retain the above copyright notice, this
- * list of conditions and the following disclaimer.
- * * Redistributions in binary form must reproduce the above copyright notice,
- * this list of conditions and the following disclaimer in the documentation
- * and/or other materials provided with the distribution.
- * * Neither the name of the HISP project nor the names of its contributors may
- * be used to endorse or promote products derived from this software without
- * specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
- * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
- * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
- * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
- * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
- * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
- * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- */
-
import java.util.Collection;
import java.util.Map;
import org.amplecode.quick.BatchHandler;
import org.amplecode.staxwax.reader.XMLReader;
import org.amplecode.staxwax.writer.XMLWriter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.concept.Concept;
+import org.hisp.dhis.concept.ConceptService;
import org.hisp.dhis.importexport.ExportParams;
import org.hisp.dhis.importexport.ImportObjectService;
import org.hisp.dhis.importexport.ImportParams;
import org.hisp.dhis.importexport.XMLConverter;
+import org.hisp.dhis.importexport.importer.ConceptImporter;
/**
* @author Bob Jolliffe
@@ -84,9 +53,6 @@
public class ConceptConverter
extends ConceptImporter implements XMLConverter
{
-
- private final Log log = LogFactory.getLog( ConceptConverter.class );
-
public static final String COLLECTION_NAME = "concepts";
public static final String ELEMENT_NAME = "concept";
@@ -126,9 +92,9 @@
// -------------------------------------------------------------------------
// XMLConverter implementation
// -------------------------------------------------------------------------
+
public void write( XMLWriter writer, ExportParams params )
{
- log.debug("ConceptConverter : write()");
Collection<Concept> concepts = conceptService.getAllConcepts();
if ( concepts != null && concepts.size() > 0 )
@@ -151,7 +117,6 @@
public void read( XMLReader reader, ImportParams params )
{
- log.debug("ConceptConverter : read()");
while ( reader.moveToStartElement( ELEMENT_NAME, COLLECTION_NAME ) )
{
final Map<String, String> values = reader.readElements( ELEMENT_NAME );
=== 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 2010-12-23 11:56:44 +0000
+++ 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
@@ -351,7 +351,7 @@
batchHandler.flush();
- log.info( "Imported Conceptss" );
+ log.info( "Imported Concepts" );
}
else if ( reader.isStartElement( DataElementCategoryOptionConverter.COLLECTION_NAME ) )
{
@@ -734,8 +734,8 @@
BatchHandler<DataEntryForm> batchHandler = batchHandlerFactory.createBatchHandler(
DataEntryFormBatchHandler.class ).init();
- XMLConverter converter = new DataEntryFormConverter( batchHandler, importObjectService,
- dataEntryFormService, dataElementService, categoryService );
+ XMLConverter converter = new DataEntryFormConverter( 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 2010-12-25 13:24:54 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/converter/DataEntryFormConverter.java 2011-01-17 11:14:18 +0000
@@ -32,13 +32,10 @@
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.hisp.dhis.dataelement.DataElement;
-import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
-import org.hisp.dhis.dataelement.DataElementCategoryService;
-import org.hisp.dhis.dataelement.DataElementService;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
import org.hisp.dhis.dataentryform.DataEntryForm;
import org.hisp.dhis.dataentryform.DataEntryFormService;
import org.hisp.dhis.importexport.ExportParams;
@@ -46,7 +43,6 @@
import org.hisp.dhis.importexport.ImportParams;
import org.hisp.dhis.importexport.XMLConverter;
import org.hisp.dhis.importexport.importer.DataEntryFormImporter;
-import org.hisp.dhis.importexport.mapping.NameMappingUtil;
/**
* @author Chau Thu Tran
@@ -57,41 +53,43 @@
extends DataEntryFormImporter
implements XMLConverter
{
+ 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";
-
private static final String FIELD_NAME = "name";
-
private static final String FIELD_HTMLCODE = "htmlCode";
- private DataElementService dataElementService;
-
- private DataElementCategoryService categoryService;
+ private Map<Object, Integer> dataElementMapping;
+ private Map<Object, Integer> categoryOptionComboMapping;
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
- public DataEntryFormConverter( DataEntryFormService dataEntryFormService, DataElementService dataElementService,
- DataElementCategoryService categoryService )
+ /**
+ * Constructor for write operations.
+ */
+ public DataEntryFormConverter( DataEntryFormService dataEntryFormService )
{
this.dataEntryFormService = dataEntryFormService;
- this.dataElementService = dataElementService;
- this.categoryService = categoryService;
}
- public DataEntryFormConverter( BatchHandler<DataEntryForm> batchHandler, ImportObjectService importObjectService,
- DataEntryFormService dataEntryFormService, DataElementService dataElementService,
- DataElementCategoryService categoryService )
+ /**
+ * Constructor for read operations.
+ */
+ public DataEntryFormConverter( ImportObjectService importObjectService,
+ DataEntryFormService dataEntryFormService,
+ Map<Object, Integer> dataElementMapping,
+ Map<Object, Integer> categoryOptionComboMapping )
{
- this.batchHandler = batchHandler;
this.importObjectService = importObjectService;
this.dataEntryFormService = dataEntryFormService;
- this.dataElementService = dataElementService;
- this.categoryService = categoryService;
+ this.dataElementMapping = dataElementMapping;
+ this.categoryOptionComboMapping = categoryOptionComboMapping;
}
// -------------------------------------------------------------------------
@@ -135,7 +133,7 @@
reader.moveToStartElement( FIELD_NAME );
dataEntryForm.setName( reader.getElementValue() );
reader.moveToStartElement( FIELD_HTMLCODE );
- dataEntryForm.setHtmlCode( proccessHtmlCode( reader.getElementValue() ) );
+ dataEntryForm.setHtmlCode( proccessHtmlCode( reader.getElementValue(), dataEntryForm.getName() ) );
importObject( dataEntryForm, params );
}
@@ -145,7 +143,7 @@
// Support method
// -------------------------------------------------------------------------
- private String proccessHtmlCode( String htmlCode )
+ private String proccessHtmlCode( String htmlCode, String name )
{
if ( htmlCode == null )
{
@@ -154,80 +152,39 @@
StringBuffer buffer = new StringBuffer();
- Map<Object, String> dataElementMap = NameMappingUtil.getDataElementMap();
- Map<Object, DataElementCategoryOptionCombo> categoryOptionMap = NameMappingUtil.getCategoryOptionComboMap();
-
- // ---------------------------------------------------------------------
- // Pattern to match data elements in the HTML code
- // ---------------------------------------------------------------------
-
- Pattern dataElementPattern = Pattern.compile( "(<input.*?)[/]?>", Pattern.DOTALL );
- Matcher dataElementMatcher = dataElementPattern.matcher( htmlCode );
-
- // ---------------------------------------------------------------------
- // Pattern to extract data element ID from data element field
- // ---------------------------------------------------------------------
-
- Pattern identifierPattern = Pattern.compile( "value\\[(.*)\\].value:value\\[(.*)\\].value" );
-
- // ---------------------------------------------------------------------
- // Iterate through all matching data element fields
- // ---------------------------------------------------------------------
-
- while ( dataElementMatcher.find() )
+ Matcher matcher = ID_PATTERN.matcher( htmlCode );
+ log.warn( "DE map" + dataElementMapping );
+ log.warn( "COC map " + categoryOptionComboMapping );
+
+ while ( matcher.find() )
{
- // -----------------------------------------------------------------
- // Get HTML input field code
- // -----------------------------------------------------------------
-
- String dataElementCode = dataElementMatcher.group( 1 );
-
- Matcher identifierMatcher = identifierPattern.matcher( dataElementCode );
-
- if ( identifierMatcher.find() && identifierMatcher.groupCount() > 0 )
+ if ( matcher.groupCount() > 0 )
{
- // -------------------------------------------------------------
- // Get ids of old data element and category into HtmlCode
- // -------------------------------------------------------------
-
- String oldDataElementId = identifierMatcher.group( 1 );
- String oldCategoryId = identifierMatcher.group( 2 );
-
- // -------------------------------------------------------------
- // Get new data element and new category
- // -------------------------------------------------------------
-
- String dataElementName = dataElementMap.get( Integer.parseInt( oldDataElementId ) );
- DataElement dataElement = dataElementService.getDataElementByName( dataElementName );
-
- DataElementCategoryOptionCombo _categoryOption = categoryOptionMap.get( Integer
- .parseInt( oldCategoryId ) );
- DataElementCategoryOptionCombo categoryOption = categoryService
- .getDataElementCategoryOptionCombo( _categoryOption );
-
- //TODO can we avoid getting the dataelement and categoryoptioncombo
- //TODO from database since we only want to get the new identifier
- //TODO through the ObjectMappingGenerator?
-
- //TODO we can also use DataElementOperand.getOperand to centralize
-
- // -------------------------------------------------------------
- // update the new ids for htmlCode
- // -------------------------------------------------------------
-
- dataElementCode = dataElementCode.replace( oldDataElementId, dataElement.getId() + "" );
- dataElementCode = dataElementCode.replace( oldCategoryId, categoryOption.getId() + "" );
-
- // -------------------------------------------------------------
- // update htmlCode
- // -------------------------------------------------------------
-
- dataElementMatcher.appendReplacement( buffer, dataElementCode.toString() );
+ String dataElement = matcher.group( 1 );
+ String categoryOptionCombo = matcher.group( 2 );
+
+ Integer dataElementId = dataElementMapping.get( Integer.valueOf( dataElement ) );
+ Integer categoryOptionComboId = categoryOptionComboMapping.get( Integer.valueOf( categoryOptionCombo ) );
+
+ if ( dataElement == null )
+ {
+ log.warn( "Data element or category option combo does not exist for data entry form: " + name );
+ continue;
+ }
+
+ if ( categoryOptionComboId == null )
+ {
+ log.warn( "Category option combo does not exist for data entry form: " + name );
+ continue;
+ }
+
+ matcher.appendReplacement( buffer, String.valueOf( dataElementId ) );
+ matcher.appendReplacement( buffer, String.valueOf( categoryOptionComboId ) );
}
-
}
+ matcher.appendTail( buffer );
+
return buffer.toString();
}
-
}
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/exporter/DefaultDXFExportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/exporter/DefaultDXFExportService.java 2010-12-23 11:56:44 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/exporter/DefaultDXFExportService.java 2011-01-17 11:14:18 +0000
@@ -328,7 +328,7 @@
thread.registerXMLConverter( new DataDictionaryDataElementConverter( dataDictionaryService ) );
thread.registerXMLConverter( new DataDictionaryIndicatorConverter( dataDictionaryService ) );
- thread.registerXMLConverter( new DataEntryFormConverter( dataEntryFormService, dataElementService, categoryService ) );
+ thread.registerXMLConverter( new DataEntryFormConverter( dataEntryFormService ) );
thread.registerXMLConverter( new DataSetConverter( dataSetService ) );
thread.registerXMLConverter( new DataSetMemberConverter( dataSetService, dataElementService ) );
=== 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 2010-12-25 13:24:54 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/DataEntryFormImporter.java 2011-01-17 11:14:18 +0000
@@ -43,14 +43,8 @@
extends AbstractImporter<DataEntryForm>
implements Importer<DataEntryForm>
{
-
protected DataEntryFormService dataEntryFormService;
- public void setDataEntryFormService( DataEntryFormService dataEntryFormService )
- {
- this.dataEntryFormService = dataEntryFormService;
- }
-
// -------------------------------------------------------------------------
// Constructor
// -------------------------------------------------------------------------
=== modified file 'dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/light_blue/light_blue.css'
--- dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/light_blue/light_blue.css 2011-01-11 16:52:46 +0000
+++ dhis-2/dhis-web/dhis-web-commons-resources/src/main/webapp/dhis-web-commons/css/light_blue/light_blue.css 2011-01-17 11:14:18 +0000
@@ -218,7 +218,7 @@
padding-left: 10px;
padding-bottom: 5px;
padding-right: 10px;
- border: 1px solid #265687;
+ border: 1px solid #2a5a8a;
cursor: pointer;
border-radius: 3px;
-moz-border-radius: 3px; /* Firefox */
=== modified file 'dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJrxmlResult.java'
--- dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJrxmlResult.java 2011-01-14 18:10:02 +0000
+++ dhis-2/dhis-web/dhis-web-commons/src/main/java/org/hisp/dhis/result/GridJrxmlResult.java 2011-01-17 11:14:18 +0000
@@ -92,7 +92,7 @@
String filename = CodecUtils.filenameEncode( StringUtils.defaultIfEmpty( grid.getTitle(), DEFAULT_FILENAME ) ) + ".jrxml";
- ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, true, filename, false );
+ ContextUtils.configureResponse( response, ContextUtils.CONTENT_TYPE_XML, true, filename, true );
// ---------------------------------------------------------------------
// Write jrxml based on Velocity template