dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #09290
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2421: Moved CsvUtils to support-system from import-export as its general. Added missing classes.
------------------------------------------------------------
revno: 2421
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2010-12-25 14:24:54 +0100
message:
Moved CsvUtils to support-system from import-export as its general. Added missing classes.
removed:
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/util/
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/util/CsvUtil.java
added:
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-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataEntryFormBatchHandler.java
dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/CsvUtils.java
modified:
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/converter/ReportTableDataConverter.java
dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueConverter.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/csv/converter/ReportTableDataConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/converter/ReportTableDataConverter.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/converter/ReportTableDataConverter.java 2010-12-25 13:24:54 +0000
@@ -27,10 +27,10 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.importexport.csv.util.CsvUtil.CSV_EXTENSION;
-import static org.hisp.dhis.importexport.csv.util.CsvUtil.NEWLINE;
-import static org.hisp.dhis.importexport.csv.util.CsvUtil.SEPARATOR_B;
-import static org.hisp.dhis.importexport.csv.util.CsvUtil.csvEncode;
+import static org.hisp.dhis.system.util.CsvUtils.CSV_EXTENSION;
+import static org.hisp.dhis.system.util.CsvUtils.NEWLINE;
+import static org.hisp.dhis.system.util.CsvUtils.SEPARATOR_B;
+import static org.hisp.dhis.system.util.CsvUtils.csvEncode;
import java.io.BufferedReader;
import java.io.IOException;
=== removed directory 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/util'
=== removed file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/util/CsvUtil.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/util/CsvUtil.java 2010-04-12 21:23:33 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/csv/util/CsvUtil.java 1970-01-01 00:00:00 +0000
@@ -1,112 +0,0 @@
-package org.hisp.dhis.importexport.csv.util;
-
-/*
- * 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.
- */
-
-/**
- * @author Lars Helge Overland
- * @version $Id$
- */
-public class CsvUtil
-{
- public static final String SEPARATOR = ",";
- public static final byte[] SEPARATOR_B = SEPARATOR.getBytes();
- public static final byte[] NEWLINE = "\n".getBytes();
-
- public static final String CSV_EXTENSION = ".csv";
- private static final String ENCLOSURE = "\"";
- private static final String EMPTY = "";
-
- /**
- * Encodes the given value to a CSV acceptable value.
- *
- * @param value the value.
- * @return the CSV encoded value.
- */
- public static String csvEncode( int value )
- {
- return csvEncode( String.valueOf( value ) );
- }
-
- /**
- * Encodes the given value to a CSV acceptable value.
- *
- * @param value the value.
- * @return the CSV encoded value.
- */
- public static String csvEncode( String value )
- {
- if ( value == null )
- {
- value = EMPTY;
- }
- else
- {
- value = value.replaceAll( ENCLOSURE, ENCLOSURE + ENCLOSURE );
- value = ENCLOSURE + value + ENCLOSURE;
- }
-
- return value;
- }
-
- /**
- * Appends a separator to the value and returns the value as a byte array.
- *
- * @param value the value.
- * @return a byte araray.
- */
- public static byte[] getCsvValue( int value )
- {
- return getCsvEndValue( value + SEPARATOR );
- }
-
- /**
- * Appends a separator to the value and returns the value as a byte array.
- *
- * @param value the value.
- * @return a byte araray.
- */
- public static byte[] getCsvValue( String value )
- {
- return getCsvEndValue( value + SEPARATOR );
- }
-
- public static byte[] getCsvEndValue( int value )
- {
- return getCsvEndValue( String.valueOf( value ) );
- }
-
- public static byte[] getCsvEndValue( String value )
- {
- if ( value == null )
- {
- return EMPTY.getBytes();
- }
-
- return ( value ).getBytes();
- }
-}
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueConverter.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueConverter.java 2010-08-31 05:47:11 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/converter/DataValueConverter.java 2010-12-25 13:24:54 +0000
@@ -27,11 +27,11 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import static org.hisp.dhis.importexport.csv.util.CsvUtil.NEWLINE;
-import static org.hisp.dhis.importexport.csv.util.CsvUtil.SEPARATOR_B;
-import static org.hisp.dhis.importexport.csv.util.CsvUtil.csvEncode;
-import static org.hisp.dhis.importexport.csv.util.CsvUtil.getCsvEndValue;
-import static org.hisp.dhis.importexport.csv.util.CsvUtil.getCsvValue;
+import static org.hisp.dhis.system.util.CsvUtils.NEWLINE;
+import static org.hisp.dhis.system.util.CsvUtils.SEPARATOR_B;
+import static org.hisp.dhis.system.util.CsvUtils.csvEncode;
+import static org.hisp.dhis.system.util.CsvUtils.getCsvEndValue;
+import static org.hisp.dhis.system.util.CsvUtils.getCsvValue;
import java.io.BufferedReader;
import java.io.IOException;
=== added 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 1970-01-01 00:00:00 +0000
+++ 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
@@ -0,0 +1,233 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.importexport.dxf.converter;
+
+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.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataentryform.DataEntryForm;
+import org.hisp.dhis.dataentryform.DataEntryFormService;
+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.DataEntryFormImporter;
+import org.hisp.dhis.importexport.mapping.NameMappingUtil;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version $ID: DataEntryFormConverter.java Dec 20, 2010 09:34:28 AM $
+ */
+public class DataEntryFormConverter
+ extends DataEntryFormImporter
+ implements XMLConverter
+{
+ 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;
+
+ // -------------------------------------------------------------------------
+ // Constructor
+ // -------------------------------------------------------------------------
+
+ public DataEntryFormConverter( DataEntryFormService dataEntryFormService, DataElementService dataElementService,
+ DataElementCategoryService categoryService )
+ {
+ this.dataEntryFormService = dataEntryFormService;
+ this.dataElementService = dataElementService;
+ this.categoryService = categoryService;
+ }
+
+ public DataEntryFormConverter( BatchHandler<DataEntryForm> batchHandler, ImportObjectService importObjectService,
+ DataEntryFormService dataEntryFormService, DataElementService dataElementService,
+ DataElementCategoryService categoryService )
+ {
+ this.batchHandler = batchHandler;
+ this.importObjectService = importObjectService;
+ this.dataEntryFormService = dataEntryFormService;
+ this.dataElementService = dataElementService;
+ this.categoryService = categoryService;
+ }
+
+ // -------------------------------------------------------------------------
+ // Override methods
+ // -------------------------------------------------------------------------
+
+ @Override
+ public void write( XMLWriter writer, ExportParams params )
+ {
+ Collection<DataEntryForm> dataEntryForms = dataEntryFormService.getDataEntryForms( params.getDataEntryForms() );
+
+ if ( dataEntryForms != null && dataEntryForms.size() > 0 )
+ {
+ writer.openElement( COLLECTION_NAME );
+
+ for ( DataEntryForm dataEntryForm : dataEntryForms )
+ {
+ writer.openElement( ELEMENT_NAME );
+
+ writer.writeElement( FIELD_ID, String.valueOf( dataEntryForm.getId() ) );
+ writer.writeElement( FIELD_NAME, dataEntryForm.getName() );
+ writer.writeCData( FIELD_HTMLCODE, dataEntryForm.getHtmlCode() );
+
+ writer.closeElement();
+ }
+
+ writer.closeElement();
+ }
+ }
+
+ @Override
+ public void read( XMLReader reader, ImportParams params )
+ {
+ while ( reader.moveToStartElement( ELEMENT_NAME, COLLECTION_NAME ) )
+ {
+ 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() ) );
+
+ importObject( dataEntryForm, params );
+ }
+ }
+
+ // -------------------------------------------------------------------------
+ // Support method
+ // -------------------------------------------------------------------------
+
+ private String proccessHtmlCode( String htmlCode )
+ {
+ if ( htmlCode == null )
+ {
+ return null;
+ }
+
+ 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() )
+ {
+ // -----------------------------------------------------------------
+ // Get HTML input field code
+ // -----------------------------------------------------------------
+
+ String dataElementCode = dataElementMatcher.group( 1 );
+
+ Matcher identifierMatcher = identifierPattern.matcher( dataElementCode );
+
+ if ( identifierMatcher.find() && identifierMatcher.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() );
+ }
+
+ }
+
+ return buffer.toString();
+ }
+
+}
=== added 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 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/importer/DataEntryFormImporter.java 2010-12-25 13:24:54 +0000
@@ -0,0 +1,111 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.importexport.importer;
+
+import org.hisp.dhis.dataentryform.DataEntryForm;
+import org.hisp.dhis.dataentryform.DataEntryFormService;
+import org.hisp.dhis.importexport.GroupMemberType;
+import org.hisp.dhis.importexport.ImportParams;
+import org.hisp.dhis.importexport.Importer;
+import org.hisp.dhis.importexport.mapping.NameMappingUtil;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version $ID: DataEntryFormImporter.java Dec 16, 2010 2:36:05 PM $
+ */
+public class DataEntryFormImporter
+ extends AbstractImporter<DataEntryForm>
+ implements Importer<DataEntryForm>
+{
+
+ protected DataEntryFormService dataEntryFormService;
+
+ public void setDataEntryFormService( DataEntryFormService dataEntryFormService )
+ {
+ this.dataEntryFormService = dataEntryFormService;
+ }
+
+ // -------------------------------------------------------------------------
+ // Constructor
+ // -------------------------------------------------------------------------
+
+ public DataEntryFormImporter( )
+ {
+ }
+
+ public DataEntryFormImporter( DataEntryFormService dataEntryFormService )
+ {
+ this.dataEntryFormService = dataEntryFormService;
+ }
+
+ // -------------------------------------------------------------------------
+ // Override methods
+ // -------------------------------------------------------------------------
+
+ @Override
+ public void importObject( DataEntryForm object, ImportParams params )
+ {
+ NameMappingUtil.addDataEntryFormMapping( object.getId(), object.getName() );
+
+ read( object, GroupMemberType.NONE, params );
+ }
+
+ @Override
+ protected void importUnique( DataEntryForm object )
+ {
+ dataEntryFormService.addDataEntryForm( object );
+ }
+
+ @Override
+ protected void importMatching( DataEntryForm object, DataEntryForm match )
+ {
+ match.setName( object.getName() );
+ match.setHtmlCode( object.getHtmlCode() );
+
+ dataEntryFormService.updateDataEntryForm( match );
+ }
+
+ @Override
+ protected DataEntryForm getMatching( DataEntryForm object )
+ {
+ return dataEntryFormService.getDataEntryFormByName( object.getName() );
+ }
+
+ @Override
+ protected boolean isIdentical( DataEntryForm object, DataEntryForm existing )
+ {
+ if ( object.getName().equals( existing.getName() ) )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+}
=== added file 'dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataEntryFormBatchHandler.java'
--- dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataEntryFormBatchHandler.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-jdbc/src/main/java/org/hisp/dhis/jdbc/batchhandler/DataEntryFormBatchHandler.java 2010-12-25 13:24:54 +0000
@@ -0,0 +1,100 @@
+/*
+ * 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.
+ */
+
+package org.hisp.dhis.jdbc.batchhandler;
+
+import org.amplecode.quick.JdbcConfiguration;
+import org.amplecode.quick.batchhandler.AbstractBatchHandler;
+import org.hisp.dhis.dataentryform.DataEntryForm;
+
+/**
+ * @author Chau Thu Tran
+ *
+ * @version $ID: DataEntryFormBatchHandler.java Dec 17, 2010 10:15:18 AM $
+ */
+public class DataEntryFormBatchHandler
+extends AbstractBatchHandler<DataEntryForm>
+{
+ // -------------------------------------------------------------------------
+ // Constructor
+ // -------------------------------------------------------------------------
+
+ public DataEntryFormBatchHandler( JdbcConfiguration config )
+ {
+ super( config, true, true );
+ }
+
+ // -------------------------------------------------------------------------
+ // AbstractBatchHandler implementation
+ // -------------------------------------------------------------------------
+
+ protected void setTableName()
+ {
+ statementBuilder.setTableName( "dataentryform" );
+ }
+
+ @Override
+ protected void setAutoIncrementColumn()
+ {
+ statementBuilder.setAutoIncrementColumn( "dataentryformid" );
+ }
+
+ @Override
+ protected void setIdentifierColumns()
+ {
+ statementBuilder.setIdentifierColumn( "dataentryformid" );
+ }
+
+ @Override
+ protected void setIdentifierValues( DataEntryForm dataEntryForm )
+ {
+ statementBuilder.setIdentifierValue( dataEntryForm.getId() );
+ }
+
+ protected void setUniqueColumns()
+ {
+ statementBuilder.setUniqueColumn( "name" );
+ }
+
+ protected void setUniqueValues( DataEntryForm dataEntryForm )
+ {
+ statementBuilder.setUniqueValue( dataEntryForm.getName() );
+ }
+
+ protected void setColumns()
+ {
+ statementBuilder.setColumn( "name" );
+ statementBuilder.setColumn( "htmlcode" );
+ }
+
+ protected void setValues( DataEntryForm dataEntryForm )
+ {
+ statementBuilder.setValue( dataEntryForm.getName() );
+ statementBuilder.setValue( dataEntryForm.getHtmlCode() );
+ }
+}
+
=== added file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/CsvUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/CsvUtils.java 1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/CsvUtils.java 2010-12-25 13:24:54 +0000
@@ -0,0 +1,112 @@
+package org.hisp.dhis.system.util;
+
+/*
+ * 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.
+ */
+
+/**
+ * @author Lars Helge Overland
+ * @version $Id$
+ */
+public class CsvUtils
+{
+ public static final String SEPARATOR = ",";
+ public static final byte[] SEPARATOR_B = SEPARATOR.getBytes();
+ public static final byte[] NEWLINE = "\n".getBytes();
+
+ public static final String CSV_EXTENSION = ".csv";
+ private static final String ENCLOSURE = "\"";
+ private static final String EMPTY = "";
+
+ /**
+ * Encodes the given value to a CSV acceptable value.
+ *
+ * @param value the value.
+ * @return the CSV encoded value.
+ */
+ public static String csvEncode( int value )
+ {
+ return csvEncode( String.valueOf( value ) );
+ }
+
+ /**
+ * Encodes the given value to a CSV acceptable value.
+ *
+ * @param value the value.
+ * @return the CSV encoded value.
+ */
+ public static String csvEncode( String value )
+ {
+ if ( value == null )
+ {
+ value = EMPTY;
+ }
+ else
+ {
+ value = value.replaceAll( ENCLOSURE, ENCLOSURE + ENCLOSURE );
+ value = ENCLOSURE + value + ENCLOSURE;
+ }
+
+ return value;
+ }
+
+ /**
+ * Appends a separator to the value and returns the value as a byte array.
+ *
+ * @param value the value.
+ * @return a byte araray.
+ */
+ public static byte[] getCsvValue( int value )
+ {
+ return getCsvEndValue( value + SEPARATOR );
+ }
+
+ /**
+ * Appends a separator to the value and returns the value as a byte array.
+ *
+ * @param value the value.
+ * @return a byte araray.
+ */
+ public static byte[] getCsvValue( String value )
+ {
+ return getCsvEndValue( value + SEPARATOR );
+ }
+
+ public static byte[] getCsvEndValue( int value )
+ {
+ return getCsvEndValue( String.valueOf( value ) );
+ }
+
+ public static byte[] getCsvEndValue( String value )
+ {
+ if ( value == null )
+ {
+ return EMPTY.getBytes();
+ }
+
+ return ( value ).getBytes();
+ }
+}