← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6441: Impl stax based mapper for DataValueSets

 

------------------------------------------------------------
revno: 6441
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2012-03-29 23:52:27 +0200
message:
  Impl stax based mapper for DataValueSets
removed:
  dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/DefaultIndentingXMLStreamWriter.java
  dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/DefaultLineBreakingXMLStreamWriter.java
added:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/DataValueSetMapper.java
modified:
  dhis-2/dhis-dxf2/pom.xml
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/exporter/DefaultDhis14XMLExportService.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/exporter/DefaultDXFExportService.java
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java
  dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/factory/XMLFactory.java
  dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/reader/DefaultXMLStreamReader.java
  dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/DefaultXMLStreamWriter.java
  dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/XMLWriter.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.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-dxf2/pom.xml'
--- dhis-2/dhis-dxf2/pom.xml	2012-03-28 18:27:56 +0000
+++ dhis-2/dhis-dxf2/pom.xml	2012-03-29 21:52:27 +0000
@@ -32,6 +32,10 @@
       <groupId>org.hisp.dhis</groupId>
       <artifactId>dhis-support-test</artifactId>
     </dependency>
+    <dependency>
+      <groupId>org.hisp.dhis</groupId>
+      <artifactId>dhis-support-xml</artifactId>
+    </dependency>
 	
     <dependency>
       <groupId>org.codehaus.jackson</groupId>

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java	2012-03-29 16:45:18 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java	2012-03-29 21:52:27 +0000
@@ -114,4 +114,10 @@
     {
         this.dataValues = dataValues;
     }
+    
+    @Override
+    public String toString()
+    {
+        return "[" + dataSet + ", " + completeDate + ", " + period + ", " + orgUnit + ", " + dataValues.size() + "]";
+    }
 }

=== added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/DataValueSetMapper.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/DataValueSetMapper.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/DataValueSetMapper.java	2012-03-29 21:52:27 +0000
@@ -0,0 +1,122 @@
+package org.hisp.dhis.dxf2.utils;
+
+/*
+ * Copyright (c) 2008, the original author or authors.
+ * 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 AmpleCode 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 static org.hisp.dhis.system.util.TextUtils.valueOf;
+
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.amplecode.staxwax.factory.XMLFactory;
+import org.amplecode.staxwax.reader.XMLReader;
+import org.amplecode.staxwax.writer.XMLWriter;
+import org.hisp.dhis.dxf2.datavalue.DataValue;
+import org.hisp.dhis.dxf2.datavalueset.DataValueSet;
+
+public class DataValueSetMapper
+{
+    private static final String XMLNS = "xmlns";
+    private static final String NS = "http://dhis2.org/schema/dxf/2.0";;
+    
+    private static final String FIELD_DATAVALUESET = "dataValueSet";
+    private static final String FIELD_DATAVALUE = "dataValue";
+    private static final String FIELD_DATASET = "dataSet";
+    private static final String FIELD_COMPLETEDATE = "completeDate";
+    private static final String FIELD_DATAELEMENT = "dataElement";
+    private static final String FIELD_CATEGORY_OPTION_COMBO = "categoryOptionCombo";
+    private static final String FIELD_PERIOD = "period";
+    private static final String FIELD_ORGUNIT = "orgUnit";
+    private static final String FIELD_VALUE = "value";
+    private static final String FIELD_STOREDBY = "storedBy";
+    private static final String FIELD_TIMESTAMP = "timestamp";
+    private static final String FIELD_COMMENT = "comment";
+    private static final String FIELD_FOLLOWUP = "followUp";
+    
+    public static void toXml( DataValueSet dataValueSet, OutputStream out )
+    {
+        XMLWriter writer = XMLFactory.getXMLWriter( out );
+        
+        writer.openDocument();        
+        writer.openElement( FIELD_DATAVALUESET, XMLNS, NS,
+            FIELD_DATASET, dataValueSet.getDataSet(),
+            FIELD_COMPLETEDATE, dataValueSet.getCompleteDate(),
+            FIELD_PERIOD, dataValueSet.getPeriod(),
+            FIELD_ORGUNIT, dataValueSet.getOrgUnit() );
+        
+        for ( DataValue dataValue : dataValueSet.getDataValues() )
+        {
+            writer.writeElement( FIELD_DATAVALUE, null,
+                FIELD_DATAELEMENT, dataValue.getDataElement(),
+                FIELD_CATEGORY_OPTION_COMBO, dataValue.getCategoryOptionCombo(),
+                FIELD_PERIOD, dataValueSet.getPeriod(),
+                FIELD_ORGUNIT, dataValueSet.getOrgUnit(),
+                FIELD_VALUE, dataValue.getValue(),
+                FIELD_STOREDBY, dataValue.getStoredBy(),
+                FIELD_TIMESTAMP, dataValue.getTimestamp(),
+                FIELD_COMMENT, dataValue.getComment(),
+                FIELD_FOLLOWUP, valueOf( dataValue.getFollowup() ) );
+        }
+        
+        writer.closeElement();
+        writer.closeDocument();
+    }
+    
+    public static DataValueSet fromXml( InputStream in )
+    {
+        XMLReader reader = XMLFactory.getXMLReader( in );
+
+        reader.moveToStartElement( FIELD_DATAVALUESET );
+        
+        DataValueSet dataValueSet = new DataValueSet();
+        
+        dataValueSet.setDataSet( reader.getAttributeValue( FIELD_DATASET ) );
+        dataValueSet.setCompleteDate( reader.getAttributeValue( FIELD_COMPLETEDATE ) );
+        dataValueSet.setPeriod( reader.getAttributeValue( FIELD_PERIOD ) );
+        dataValueSet.setOrgUnit( reader.getAttributeValue( FIELD_ORGUNIT ) );
+        
+        while ( reader.moveToStartElement( FIELD_DATAVALUE, FIELD_DATAVALUESET ) )
+        {
+            DataValue dataValue = new DataValue();
+            
+            dataValue.setDataElement( reader.getAttributeValue( FIELD_DATAELEMENT ) );
+            dataValue.setCategoryOptionCombo( reader.getAttributeValue( FIELD_CATEGORY_OPTION_COMBO ) );
+            dataValue.setPeriod( reader.getAttributeValue( FIELD_PERIOD ) );
+            dataValue.setOrgUnit( reader.getAttributeValue( FIELD_ORGUNIT ) );
+            dataValue.setValue( reader.getAttributeValue( FIELD_VALUE ) );
+            dataValue.setStoredBy( reader.getAttributeValue( FIELD_STOREDBY ) );
+            dataValue.setTimestamp( reader.getAttributeValue( FIELD_TIMESTAMP ) );
+            dataValue.setComment( reader.getAttributeValue( FIELD_COMMENT ) );
+            dataValue.setFollowup( valueOf( reader.getAttributeValue( FIELD_FOLLOWUP ) ) );
+            
+            dataValueSet.getDataValues().add( dataValue );
+        }
+        
+        return dataValueSet;
+    }
+}

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/exporter/DefaultDhis14XMLExportService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/exporter/DefaultDhis14XMLExportService.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dhis14/xml/exporter/DefaultDhis14XMLExportService.java	2012-03-29 21:52:27 +0000
@@ -156,7 +156,7 @@
             
             zipOut.putNextEntry( new ZipEntry( ZIP_ENTRY_NAME ) );
 
-            XMLWriter writer = XMLFactory.getPlainXMLWriter( zipOut );
+            XMLWriter writer = XMLFactory.getXMLWriter( zipOut );
 
             // -------------------------------------------------------------------------
             // Writes to one end of the pipe 

=== 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	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf/exporter/DefaultDXFExportService.java	2012-03-29 21:52:27 +0000
@@ -268,7 +268,7 @@
 
             zipOut.putNextEntry( new ZipEntry( ZIP_ENTRY_NAME ) );
 
-            XMLWriter writer = XMLFactory.getPlainXMLWriter( zipOut );
+            XMLWriter writer = XMLFactory.getXMLWriter( zipOut );
 
             // -----------------------------------------------------------------
             // Writes to one end of the pipe

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java	2012-02-09 18:32:12 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/TextUtils.java	2012-03-29 21:52:27 +0000
@@ -168,4 +168,28 @@
     {
         return s1 == null ? s2 == null : s1.equals( s2 );
     }
+    
+    /**
+     * Returns the string value of the given boolean. Returns null if argument
+     * is null.
+     * 
+     * @param value the boolean.
+     * @return the string value.
+     */
+    public static String valueOf( Boolean value )
+    {
+        return value != null ? String.valueOf( value ) : null;
+    }
+    
+    /**
+     * Returns the boolean value of the given string. Returns null if argument
+     * is null.
+     * 
+     * @param value the string value.
+     * @return the boolean.
+     */
+    public static Boolean valueOf( String value )
+    {
+        return value != null ? Boolean.valueOf( value ) : null;
+    }
 }

=== modified file 'dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/factory/XMLFactory.java'
--- dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/factory/XMLFactory.java	2010-02-22 09:37:31 +0000
+++ dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/factory/XMLFactory.java	2012-03-29 21:52:27 +0000
@@ -39,8 +39,6 @@
 import org.amplecode.staxwax.reader.DefaultXMLEventReader;
 import org.amplecode.staxwax.reader.DefaultXMLStreamReader;
 import org.amplecode.staxwax.reader.XMLReader;
-import org.amplecode.staxwax.writer.DefaultIndentingXMLStreamWriter;
-import org.amplecode.staxwax.writer.DefaultLineBreakingXMLStreamWriter;
 import org.amplecode.staxwax.writer.DefaultXMLStreamWriter;
 import org.amplecode.staxwax.writer.XMLWriter;
 import org.codehaus.stax2.XMLEventReader2;
@@ -74,45 +72,14 @@
             
             XMLStreamWriter streamWriter = factory.createXMLStreamWriter( outputStream );
 
-            XMLWriter xmlWriter = new DefaultXMLStreamWriter( streamWriter );
-
-            XMLWriter indentingWriter = new DefaultIndentingXMLStreamWriter( xmlWriter );
-                
-            return indentingWriter;
-        }
-        catch ( XMLStreamException ex )
-        {
-            throw new RuntimeException( "Failed to create XMLWriter", ex );
-        }
-    }
-    
-    /**
-     * Creates an XMLWriter from a StAX-based XMLStreamWriter. The generated XML
-     * will have a line break after each natural line end and not be indented.
-     * 
-     * @param outputStream the OutputStream to write to.
-     * @return an XMLWriter.
-     */
-    public static XMLWriter getPlainXMLWriter( OutputStream outputStream )
-    {
-        try
-        {
-            XMLOutputFactory factory = new WstxOutputFactory();
-            
-            XMLStreamWriter streamWriter = factory.createXMLStreamWriter( outputStream );
-
-            XMLWriter xmlWriter = new DefaultXMLStreamWriter( streamWriter );
-
-            XMLWriter lineBreakingWriter = new DefaultLineBreakingXMLStreamWriter( xmlWriter );
-            
-            return lineBreakingWriter;
-        }
-        catch ( XMLStreamException ex )
-        {
-            throw new RuntimeException( "Failed to create XMLWriter", ex );
-        }
-    }
-    
+            return new DefaultXMLStreamWriter( streamWriter );
+        }
+        catch ( XMLStreamException ex )
+        {
+            throw new RuntimeException( "Failed to create XMLWriter", ex );
+        }
+    }
+        
     /**
      * Creates an XMLReader from a StAX-based XMLStreamReader2.
      *

=== modified file 'dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/reader/DefaultXMLStreamReader.java'
--- dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/reader/DefaultXMLStreamReader.java	2012-02-20 12:12:39 +0000
+++ dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/reader/DefaultXMLStreamReader.java	2012-03-29 21:52:27 +0000
@@ -56,8 +56,7 @@
 {
     private static final Log log = LogFactory.getLog( DefaultXMLStreamReader.class );
 
-    private static final String[] EVENTS = {
-        "None", "Start Element", "End Element", "Processing Instruction",
+    private static final String[] EVENTS = { "None", "Start Element", "End Element", "Processing Instruction",
         "Characters", "Comment", "Space", "Start Document", "End Document", "Entity Reference", "Attribute", "DTD",
         "CData", "Namespace", "Notation Declaration", "Entity Declaration" };
 
@@ -66,7 +65,7 @@
     // -------------------------------------------------------------------------
     // Constructor
     // -------------------------------------------------------------------------
-    
+
     public DefaultXMLStreamReader( XMLStreamReader2 reader )
     {
         this.reader = reader;
@@ -75,7 +74,7 @@
     // -------------------------------------------------------------------------
     // XMLReader implementation
     // -------------------------------------------------------------------------
-    
+
     @Override
     public String getElementName()
     {
@@ -100,27 +99,28 @@
             reader.next();
 
             return this.getText();
-        } catch ( XMLStreamException ex )
+        }
+        catch ( XMLStreamException ex )
         {
             throw new RuntimeException( "Failed to get element value", ex );
         }
     }
 
     @Override
-    public void moveToStartElement( )
+    public void moveToStartElement()
     {
         try
         {
-           while (reader.hasNext())  
-           { 
-               reader.next();
-               if( reader.isStartElement())
-               {
-                   break;
-               }
-           } 
+            while ( reader.hasNext() )
+            {
+                reader.next();
+                if ( reader.isStartElement() )
+                {
+                    break;
+                }
+            }
         }
-          catch ( XMLStreamException ex )
+        catch ( XMLStreamException ex )
         {
             throw new RuntimeException( "Failed to move to start element", ex );
         }
@@ -140,7 +140,8 @@
                     break;
                 }
             }
-        } catch ( XMLStreamException ex )
+        }
+        catch ( XMLStreamException ex )
         {
             throw new RuntimeException( "Failed to move to start element", ex );
         }
@@ -167,7 +168,8 @@
             }
 
             return false;
-        } catch ( XMLStreamException ex )
+        }
+        catch ( XMLStreamException ex )
         {
             throw new RuntimeException( "Failed to move to start element", ex );
         }
@@ -191,7 +193,8 @@
         try
         {
             return reader.next() != END_DOCUMENT;
-        } catch ( XMLStreamException ex )
+        }
+        catch ( XMLStreamException ex )
         {
             throw new RuntimeException( "Failed to move cursor to next event", ex );
         }
@@ -202,8 +205,9 @@
     {
         try
         {
-            return !( reader.next() == END_ELEMENT && reader.getLocalName().equals( endElementName ) );
-        } catch ( XMLStreamException ex )
+            return !(reader.next() == END_ELEMENT && reader.getLocalName().equals( endElementName ));
+        }
+        catch ( XMLStreamException ex )
         {
             throw new RuntimeException( "Failed to move cursor to end element", ex );
         }
@@ -251,7 +255,7 @@
                     reader.next();
 
                     // Read text if any
-                    elements.put( currentElementName, this.getText()  );
+                    elements.put( currentElementName, this.getText() );
                 }
                 else
                 {
@@ -261,7 +265,8 @@
             }
 
             return elements;
-        } catch ( XMLStreamException ex )
+        }
+        catch ( XMLStreamException ex )
         {
             throw new RuntimeException( "Failed to read elements", ex );
         }
@@ -282,7 +287,7 @@
 
             StringBuffer text = new StringBuffer( "\n" );
 
-            while ( ( e = reader.next() ) != END_DOCUMENT )
+            while ( (e = reader.next()) != END_DOCUMENT )
             {
                 text.append( "EVENT: " + EVENTS[e] + " " );
 
@@ -309,7 +314,8 @@
             }
 
             log.info( text );
-        } catch ( XMLStreamException ex )
+        }
+        catch ( XMLStreamException ex )
         {
             throw new RuntimeException( "Failed to read elements", ex );
         }
@@ -321,7 +327,8 @@
         try
         {
             reader.close();
-        } catch ( XMLStreamException ex )
+        }
+        catch ( XMLStreamException ex )
         {
             throw new RuntimeException( "Failed to close reader", ex );
         }
@@ -336,7 +343,8 @@
         {
             XMLEventReader2 eventReader = (XMLEventReader2) fac.createXMLEventReader( reader );
             return eventReader;
-        } catch ( XMLStreamException ex )
+        }
+        catch ( XMLStreamException ex )
         {
             throw new RuntimeException( "Failed to create XML Event reader", ex );
         }
@@ -346,16 +354,16 @@
         throws XMLStreamException
     {
         StringBuffer sb = new StringBuffer();
-        
+
         while ( reader.isCharacters() || reader.getEventType() == XMLStreamReader2.CDATA )
         {
             sb.append( reader.getText() );
             reader.next();
         }
-        
+
         return sb.length() == 0 ? null : sb.toString();
     }
-    
+
     private String nullIfEmpty( String value )
     {
         return value != null && value.isEmpty() ? null : value;

=== removed file 'dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/DefaultIndentingXMLStreamWriter.java'
--- dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/DefaultIndentingXMLStreamWriter.java	2010-12-23 11:56:44 +0000
+++ dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/DefaultIndentingXMLStreamWriter.java	1970-01-01 00:00:00 +0000
@@ -1,153 +0,0 @@
-package org.amplecode.staxwax.writer;
-
-/*
- * Copyright (c) 2008, the original author or authors.
- * 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 AmpleCode 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 javax.xml.stream.XMLStreamWriter;
-
-/**
- * @author Lars Helge Overland
- * @version $Id: DefaultIndentingXMLStreamWriter.java 145 2009-06-29 14:48:33Z
- *          larshelg $
- */
-public class DefaultIndentingXMLStreamWriter
-    implements XMLWriter
-{
-    private static final String LINE_BREAK = "\n";
-
-    private static final char SPACE = ' ';
-
-    private static final int indentStep = 4; // TODO improve
-
-    private static int currentIndent = 0;
-
-    private XMLWriter writer;
-
-    // -------------------------------------------------------------------------
-    // Constructor
-    // -------------------------------------------------------------------------
-
-    public DefaultIndentingXMLStreamWriter( XMLWriter writer )
-    {
-        this.writer = writer;
-    }
-
-    // -------------------------------------------------------------------------
-    // Supportive methods
-    // -------------------------------------------------------------------------
-
-    public String getWhiteSpace( int indent )
-    {
-        final StringBuffer buffer = new StringBuffer();
-
-        final int length = indent * indentStep;
-
-        for ( int i = 0; i < length; i++ )
-        {
-            buffer.append( SPACE );
-        }
-
-        return LINE_BREAK + buffer.toString();
-    }
-
-    // -------------------------------------------------------------------------
-    // XMLWriter implementation
-    // -------------------------------------------------------------------------
-
-    public void openDocument( String encoding, String version )
-    {
-        writer.openDocument( encoding, version );
-    }
-
-    public void openElement( String name )
-    {
-        writer.writeCharacters( getWhiteSpace( currentIndent++ ) );
-
-        writer.openElement( name );
-    }
-
-    public void openElement( String name, String... attributeNameValuePairs )
-    {
-        writer.writeCharacters( getWhiteSpace( currentIndent++ ) );
-
-        writer.openElement( name, attributeNameValuePairs );
-    }
-
-    public void writeElement( String name, String value )
-    {
-        writer.writeCharacters( getWhiteSpace( currentIndent ) );
-
-        writer.writeElement( name, value );
-    }
-
-    public void writeElement( String name, String value, String... attributeNameValuePairs )
-    {
-        writer.writeCharacters( getWhiteSpace( currentIndent ) );
-
-        writer.writeElement( name, value, attributeNameValuePairs );
-    }
-
-    public void writeCharacters( String characters )
-    {
-        writer.writeCharacters( characters );
-    }
-
-    public void writeCData( String cData )
-    {
-        writer.writeCData( cData );
-    }
-
-    public void writeCData( String name, String cData )
-    {
-        writer.writeCData( name, cData );
-    }
-
-    public XMLStreamWriter getXmlStreamWriter()
-    {
-        return writer.getXmlStreamWriter();
-    }
-
-    public void closeElement()
-    {
-        writer.writeCharacters( getWhiteSpace( --currentIndent ) );
-
-        writer.closeElement();
-    }
-
-    public void closeDocument()
-    {
-        writer.writeCharacters( getWhiteSpace( --currentIndent ) );
-
-        writer.closeDocument();
-    }
-
-    public void closeWriter()
-    {
-        writer.closeWriter();
-    }
-}

=== removed file 'dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/DefaultLineBreakingXMLStreamWriter.java'
--- dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/DefaultLineBreakingXMLStreamWriter.java	2010-12-23 11:56:44 +0000
+++ dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/DefaultLineBreakingXMLStreamWriter.java	1970-01-01 00:00:00 +0000
@@ -1,129 +0,0 @@
-package org.amplecode.staxwax.writer;
-
-/*
- * Copyright (c) 2008, the original author or authors.
- * 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 AmpleCode 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 javax.xml.stream.XMLStreamWriter;
-
-/**
- * @author Lars Helge Overland
- * @version $Id: DefaultIndentingXMLStreamWriter.java 114 2008-11-23 20:17:23Z
- *          larshelg $
- */
-public class DefaultLineBreakingXMLStreamWriter
-    implements XMLWriter
-{
-    private static final String LINE_BREAK = "\n";
-
-    private XMLWriter writer;
-
-    // -------------------------------------------------------------------------
-    // Constructor
-    // -------------------------------------------------------------------------
-
-    public DefaultLineBreakingXMLStreamWriter( XMLWriter writer )
-    {
-        this.writer = writer;
-    }
-
-    // -------------------------------------------------------------------------
-    // XMLWriter implementation
-    // -------------------------------------------------------------------------
-
-    public void openDocument( String encoding, String version )
-    {
-        writer.openDocument( encoding, version );
-
-        writer.writeCharacters( LINE_BREAK );
-    }
-
-    public void openElement( String name )
-    {
-        writer.openElement( name );
-
-        writer.writeCharacters( LINE_BREAK );
-    }
-
-    public void openElement( String name, String... attributeNameValuePairs )
-    {
-        writer.openElement( name, attributeNameValuePairs );
-
-        writer.writeCharacters( LINE_BREAK );
-    }
-
-    public void writeElement( String name, String value )
-    {
-        writer.writeElement( name, value );
-
-        writer.writeCharacters( LINE_BREAK );
-    }
-
-    public void writeElement( String name, String value, String... attributeNameValuePairs )
-    {
-        writer.writeElement( name, value, attributeNameValuePairs );
-
-        writer.writeCharacters( LINE_BREAK );
-    }
-
-    public void writeCharacters( String characters )
-    {
-        writer.writeCharacters( characters );
-    }
-
-    public void writeCData( String cData )
-    {
-        writer.writeCData( cData );
-    }
-
-    public void writeCData( String name, String cData )
-    {
-        writer.writeCData( name, cData );
-    }
-
-    public XMLStreamWriter getXmlStreamWriter()
-    {
-        return writer.getXmlStreamWriter();
-    }
-
-    public void closeElement()
-    {
-        writer.closeElement();
-
-        writer.writeCharacters( LINE_BREAK );
-    }
-
-    public void closeDocument()
-    {
-        writer.closeDocument();
-    }
-
-    public void closeWriter()
-    {
-        writer.closeWriter();
-    }
-}

=== modified file 'dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/DefaultXMLStreamWriter.java'
--- dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/DefaultXMLStreamWriter.java	2010-12-23 11:56:44 +0000
+++ dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/DefaultXMLStreamWriter.java	2012-03-29 21:52:27 +0000
@@ -52,7 +52,12 @@
     // -------------------------------------------------------------------------
     // XMLWriter implementation
     // -------------------------------------------------------------------------
-    
+
+    public void openDocument()
+    {
+        openDocument( "UTF-8", "1.0" );
+    }
+
     public void openDocument( String encoding, String version )
     {
         try
@@ -123,7 +128,10 @@
             {
                 for ( int i = 0; i < attributeNameValuePairs.length; i += 2 )
                 {
-                    writer.writeAttribute( verifyNotNull( attributeNameValuePairs[ i ] ), replaceNull( attributeNameValuePairs[ i + 1 ] ) );
+                    if ( attributeNameValuePairs[ i + 1 ] != null )
+                    {
+                        writer.writeAttribute( verifyNotNull( attributeNameValuePairs[ i ] ), attributeNameValuePairs[ i + 1 ] );
+                    }
                 }
             }
             

=== modified file 'dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/XMLWriter.java'
--- dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/XMLWriter.java	2010-12-23 11:56:44 +0000
+++ dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/XMLWriter.java	2012-03-29 21:52:27 +0000
@@ -44,6 +44,14 @@
      * @param encoding the encoding the XML file.
      * @param version the version of the XML file.
      */
+    void openDocument();
+    
+    /**
+     * Writes the XML declaration to ouput.
+     * 
+     * @param encoding the encoding the XML file.
+     * @param version the version of the XML file.
+     */
     void openDocument( String encoding, String version );
     
     /**

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java	2012-03-29 16:45:18 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java	2012-03-29 21:52:27 +0000
@@ -37,11 +37,11 @@
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
-import org.hisp.dhis.dxf2.datavalue.DataValue;
 import org.hisp.dhis.dxf2.datavalueset.DataValueSet;
 import org.hisp.dhis.dxf2.datavalueset.DataValueSetService;
 import org.hisp.dhis.dxf2.datavalueset.DataValueSets;
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
+import org.hisp.dhis.dxf2.utils.DataValueSetMapper;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
 import org.hisp.dhis.importexport.ImportStrategy;
 import org.springframework.beans.factory.annotation.Autowired;
@@ -69,7 +69,7 @@
     {
         DataValueSets dataValueSets = new DataValueSets();
         dataValueSets.getDataValueSets().add( new DataValueSet() );
-
+        
         model.addAttribute( "model", dataValueSets );
 
         return "dataValueSets";
@@ -87,11 +87,11 @@
         IdentifiableProperty _idScheme = IdentifiableProperty.valueOf( idScheme.toUpperCase() );        
         ImportStrategy _strategy = ImportStrategy.valueOf( strategy.toUpperCase() );
         
-        DataValueSet dataValueSet = JacksonUtils.fromXml( input, DataValueSet.class );
+        DataValueSet dataValueSet = DataValueSetMapper.fromXml( input );
         
         ImportSummary summary = dataValueSetService.saveDataValueSet( dataValueSet, _idScheme, dryRun, _strategy );
 
-        log.info( "Data values saved using id scheme: " + _idScheme + ", dry run: " + dryRun + ", strategy: " + _strategy );    
+        log.info( "Data values " + dataValueSet + " saved using id scheme: " + _idScheme + ", dry run: " + dryRun + ", strategy: " + _strategy );    
 
         response.setContentType( CONTENT_TYPE_XML );        
         JacksonUtils.toXml( response.getOutputStream(), summary );
@@ -103,30 +103,4 @@
     {
         response.sendError( HttpServletResponse.SC_CONFLICT, ex.getMessage() );
     }
-
-    @RequestMapping( value = "/test",  method = RequestMethod.GET )
-    public String getDataValueSetTest( Model model ) throws Exception
-    {
-        DataValueSets dataValueSets = new DataValueSets();
-        
-        DataValue v1 = new DataValue();
-        v1.setDataElement( "de" );
-        v1.setValue( "va" );
-
-        DataValue v2 = new DataValue();
-        v2.setDataElement( "de" );
-        v2.setValue( "va" );
-        
-        DataValueSet d = new DataValueSet();
-        d.setDataSet( "ds" );
-        d.setOrgUnit( "ou" );
-        d.setPeriod( "pe" );
-        d.getDataValues().add( v1 );
-        d.getDataValues().add( v2 );        
-        dataValueSets.getDataValueSets().add( d );
-
-        model.addAttribute( "model", dataValueSets );
-
-        return "dataValueSets";
-    }
 }