← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 6458: Impl get method for datavalueset resource

 

------------------------------------------------------------
revno: 6458
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sun 2012-04-01 14:04:14 +0200
message:
  Impl get method for datavalueset resource
removed:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/DataValueSetMapper.java
added:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingDataValue.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetStore.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingDataValueSet.java
renamed:
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSets.java => dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/DataValueSets.java
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValue.java
  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/DataValueSetService.java
  dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java
  dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml
  dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.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
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/Resources.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/DataValueSets.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-api/src/main/java/org/hisp/dhis/period/PeriodType.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2012-03-29 16:45:18 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/period/PeriodType.java	2012-04-01 12:04:14 +0000
@@ -238,7 +238,7 @@
 
     /**
      * Parses a date from a String on the format YYYY-MM-DD.
-     *
+     * 
      * @param dateString the String to parse.
      * @return a Date based on the given String.
      */
@@ -249,7 +249,8 @@
             final SimpleDateFormat format = new SimpleDateFormat();
             format.applyPattern( "yyyy-MM-dd" );
             return dateString != null ? format.parse( dateString ) : null;
-        } catch ( ParseException ex )
+        }
+        catch ( ParseException ex )
         {
             throw new RuntimeException( "Failed to parse medium date", ex );
         }
@@ -309,7 +310,7 @@
             
             try
             {
-                return periodType != null ? periodType.createPeriod() : null;
+                return periodType != null ? periodType.createPeriod( isoPeriod ) : null;
             }
             catch ( Exception ex )
             {

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValue.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValue.java	2012-03-29 16:45:18 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/DataValue.java	2012-04-01 12:04:14 +0000
@@ -29,41 +29,45 @@
 
 import org.hisp.dhis.common.Dxf2Namespace;
 
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 
 @JacksonXmlRootElement( localName = "dataValue", namespace = Dxf2Namespace.NAMESPACE )
 public class DataValue
 {
-    private String dataElement;
-
-    private String period;
-
-    private String orgUnit;
-
-    private String categoryOptionCombo;
-
-    private String value;
+    //--------------------------------------------------------------------------
+    // Properties
+    //--------------------------------------------------------------------------
+
+    protected String dataElement;
+
+    protected String period;
+
+    protected String orgUnit;
+
+    protected String categoryOptionCombo;
+
+    protected String value;
     
-    private String storedBy;
-
-    private String timestamp;
-
-    private String comment;
-
-    private Boolean followup;
+    protected String storedBy;
+
+    protected String timestamp;
+
+    protected String comment;
+
+    protected Boolean followup;
+
+    //--------------------------------------------------------------------------
+    // Constructors
+    //--------------------------------------------------------------------------
 
     public DataValue()
     {
     }
 
-    public DataValue( String s )
-    {
-    }
+    //--------------------------------------------------------------------------
+    // Getters and setters
+    //--------------------------------------------------------------------------
 
-    @JsonProperty( required=true )
-    @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE )
     public String getDataElement()
     {
         return dataElement;
@@ -74,8 +78,6 @@
         this.dataElement = dataElement;
     }
 
-    @JsonProperty
-    @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE )
     public String getPeriod()
     {
         return period;
@@ -86,8 +88,6 @@
         this.period = period;
     }
 
-    @JsonProperty
-    @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE )
     public String getOrgUnit()
     {
         return orgUnit;
@@ -98,8 +98,6 @@
         this.orgUnit = orgUnit;
     }
 
-    @JsonProperty
-    @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE )
     public String getCategoryOptionCombo()
     {
         return categoryOptionCombo;
@@ -110,8 +108,6 @@
         this.categoryOptionCombo = categoryOptionCombo;
     }
 
-    @JsonProperty
-    @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE )
     public String getValue()
     {
         return value;
@@ -122,8 +118,6 @@
         this.value = value;
     }
 
-    @JsonProperty
-    @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE )
     public String getStoredBy()
     {
         return storedBy;
@@ -134,8 +128,6 @@
         this.storedBy = storedBy;
     }
 
-    @JsonProperty
-    @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE )
     public String getTimestamp()
     {
         return timestamp;
@@ -146,8 +138,6 @@
         this.timestamp = timestamp;
     }
 
-    @JsonProperty
-    @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE )
     public String getComment()
     {
         return comment;
@@ -158,8 +148,6 @@
         this.comment = comment;
     }
 
-    @JsonProperty
-    @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE )
     public Boolean getFollowup()
     {
         return followup;

=== added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingDataValue.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingDataValue.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalue/StreamingDataValue.java	2012-04-01 12:04:14 +0000
@@ -0,0 +1,184 @@
+package org.hisp.dhis.dxf2.datavalue;
+
+/*
+ * Copyright (c) 2011, 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 static org.hisp.dhis.system.util.TextUtils.valueOf;
+
+import org.amplecode.staxwax.reader.XMLReader;
+import org.amplecode.staxwax.writer.XMLWriter;
+
+public class StreamingDataValue
+    extends DataValue
+{
+    private static final String FIELD_DATAVALUE = "dataValue";
+    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";
+    
+    private XMLWriter writer;
+    
+    private XMLReader reader;
+
+    //--------------------------------------------------------------------------
+    // Constructors
+    //--------------------------------------------------------------------------
+
+    public StreamingDataValue( XMLWriter writer )
+    {
+        this.writer = writer;
+        
+        this.writer.openElement( FIELD_DATAVALUE );
+    }
+    
+    public StreamingDataValue( XMLReader reader )
+    {
+        this.reader = reader;
+    }
+
+    //--------------------------------------------------------------------------
+    // Getters
+    //--------------------------------------------------------------------------
+
+    @Override
+    public String getDataElement()
+    {
+        return dataElement = dataElement == null ? reader.getAttributeValue( FIELD_DATAELEMENT ) : dataElement;
+    }
+
+    @Override
+    public String getPeriod()
+    {
+        return period = period == null ? reader.getAttributeValue( FIELD_PERIOD ) : period;
+    }
+
+    @Override
+    public String getOrgUnit()
+    {
+        return orgUnit = orgUnit == null ? reader.getAttributeValue( FIELD_ORGUNIT ) : orgUnit;
+    }
+
+    @Override
+    public String getCategoryOptionCombo()
+    {
+        return categoryOptionCombo = categoryOptionCombo == null ? reader.getAttributeValue( FIELD_CATEGORY_OPTION_COMBO ) : categoryOptionCombo;
+    }
+
+    @Override
+    public String getValue()
+    {
+        return value = value == null ? reader.getAttributeValue( FIELD_VALUE ) : value;
+    }
+
+    @Override
+    public String getStoredBy()
+    {
+        return storedBy = storedBy == null ? reader.getAttributeValue( FIELD_STOREDBY ) : storedBy;
+    }
+
+    @Override
+    public String getTimestamp()
+    {
+        return timestamp = timestamp == null ? reader.getAttributeValue( FIELD_TIMESTAMP ) : timestamp;
+    }
+
+    @Override
+    public String getComment()
+    {
+        return comment = comment == null ? reader.getAttributeValue( FIELD_COMMENT ) : comment;
+    }
+
+    @Override
+    public Boolean getFollowup()
+    {
+        return followup = followup == null ? valueOf( reader.getAttributeValue( FIELD_FOLLOWUP ) ) : followup;
+    }
+
+    //--------------------------------------------------------------------------
+    // Setters
+    //--------------------------------------------------------------------------
+
+    @Override
+    public void setDataElement( String dataElement )
+    {
+        writer.writeAttribute( FIELD_DATAELEMENT, dataElement );
+    }
+
+    @Override
+    public void setPeriod( String period )
+    {
+        writer.writeAttribute( FIELD_PERIOD, period );
+    }
+
+    @Override
+    public void setOrgUnit( String orgUnit )
+    {
+        writer.writeAttribute( FIELD_ORGUNIT, orgUnit );
+    }
+
+    @Override
+    public void setCategoryOptionCombo( String categoryOptionCombo )
+    {
+        writer.writeAttribute( FIELD_CATEGORY_OPTION_COMBO, categoryOptionCombo );
+    }
+
+    @Override
+    public void setValue( String value )
+    {
+        writer.writeAttribute( FIELD_VALUE, value );
+    }
+
+    @Override
+    public void setStoredBy( String storedBy )
+    {
+        writer.writeAttribute( FIELD_STOREDBY, storedBy );
+    }
+
+    @Override
+    public void setTimestamp( String timestamp )
+    {
+        writer.writeAttribute( FIELD_TIMESTAMP, timestamp );
+    }
+
+    @Override
+    public void setComment( String comment )
+    {
+        writer.writeAttribute( FIELD_COMMENT, comment );
+    }
+
+    @Override
+    public void setFollowup( Boolean followup )
+    {
+        writer.writeAttribute( FIELD_FOLLOWUP, valueOf( followup ) );
+    }
+}

=== 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-30 11:04:07 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSet.java	2012-04-01 12:04:14 +0000
@@ -33,8 +33,6 @@
 import org.hisp.dhis.common.Dxf2Namespace;
 import org.hisp.dhis.dxf2.datavalue.DataValue;
 
-import com.fasterxml.jackson.annotation.JsonProperty;
-import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 
 @JacksonXmlRootElement( localName = "dataValueSet", namespace = Dxf2Namespace.NAMESPACE )
@@ -44,30 +42,36 @@
     // Options
     //--------------------------------------------------------------------------
 
-    private String dataElementIdScheme;
+    protected String dataElementIdScheme;
     
-    private String orgUnitIdScheme;
+    protected String orgUnitIdScheme;
     
     //--------------------------------------------------------------------------
     // Properties
     //--------------------------------------------------------------------------
 
-    private String dataSet;
-
-    private String completeDate;
-
-    private String period;
-
-    private String orgUnit;
-
-    private List<DataValue> dataValues = new ArrayList<DataValue>();
-
+    protected String dataSet;
+
+    protected String completeDate;
+
+    protected String period;
+
+    protected String orgUnit;
+
+    protected List<DataValue> dataValues = new ArrayList<DataValue>();
+
+    //--------------------------------------------------------------------------
+    // Constructors
+    //--------------------------------------------------------------------------
+
+    public DataValueSet()
+    {
+    }
+    
     //--------------------------------------------------------------------------
     // Getters and setters
     //--------------------------------------------------------------------------
 
-    @JsonProperty()
-    @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE )
     public String getDataElementIdScheme()
     {
         return dataElementIdScheme;
@@ -78,8 +82,6 @@
         this.dataElementIdScheme = dataElementIdScheme;
     }
 
-    @JsonProperty()
-    @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE )
     public String getOrgUnitIdScheme()
     {
         return orgUnitIdScheme;
@@ -90,8 +92,6 @@
         this.orgUnitIdScheme = orgUnitIdScheme;
     }
 
-    @JsonProperty()
-    @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE )
     public String getDataSet()
     {
         return dataSet;
@@ -102,8 +102,16 @@
         this.dataSet = dataSet;
     }
 
-    @JsonProperty()
-    @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE )
+    public String getCompleteDate()
+    {
+        return completeDate;
+    }
+
+    public void setCompleteDate( String completeDate )
+    {
+        this.completeDate = completeDate;
+    }
+
     public String getPeriod()
     {
         return period;
@@ -114,20 +122,6 @@
         this.period = period;
     }
 
-    @JsonProperty
-    @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE )
-    public String getCompleteDate()
-    {
-        return completeDate;
-    }
-
-    public void setCompleteDate( String completeDate )
-    {
-        this.completeDate = completeDate;
-    }
-
-    @JsonProperty()
-    @JacksonXmlProperty( isAttribute=true, namespace = Dxf2Namespace.NAMESPACE )
     public String getOrgUnit()
     {
         return orgUnit;
@@ -138,8 +132,6 @@
         this.orgUnit = orgUnit;
     }
 
-    @JsonProperty
-    @JacksonXmlProperty( namespace = Dxf2Namespace.NAMESPACE )
     public List<DataValue> getDataValues()
     {
         return dataValues;
@@ -150,6 +142,11 @@
         this.dataValues = dataValues;
     }
     
+    public DataValue getNextDataValue()
+    {
+        return dataValues.iterator().next();
+    }
+    
     @Override
     public String toString()
     {

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java	2012-03-30 11:04:07 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetService.java	2012-04-01 12:04:14 +0000
@@ -27,13 +27,16 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.io.OutputStream;
+
 import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
-import org.hisp.dhis.dxf2.datavalueset.DataValueSet;
 import org.hisp.dhis.dxf2.importsummary.ImportSummary;
 import org.hisp.dhis.importexport.ImportStrategy;
 
 public interface DataValueSetService
 {
+    void writeDataValueSet( String dataSet, String period, String orgUnit, OutputStream out );
+    
     ImportSummary saveDataValueSet( DataValueSet dataValueSet );
     
     ImportSummary saveDataValueSet( DataValueSet dataValueSet, IdentifiableProperty dataElementIdScheme, IdentifiableProperty orgUnitIdScheme, boolean dryRun, ImportStrategy strategy );

=== added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetStore.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSetStore.java	2012-04-01 12:04:14 +0000
@@ -0,0 +1,16 @@
+package org.hisp.dhis.dxf2.datavalueset;
+
+import java.io.OutputStream;
+import java.util.Date;
+import java.util.Set;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.Period;
+
+public interface DataValueSetStore
+{
+    public void writeDataValueSet( DataSet dataSet, Date completeDate, OrganisationUnit orgUnit, Period period, 
+        Set<DataElement> dataElements, Set<Period> periods, Set<OrganisationUnit> orgUnits, OutputStream out );
+}

=== modified file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2012-03-30 11:04:07 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DefaultDataValueSetService.java	2012-04-01 12:04:14 +0000
@@ -30,8 +30,10 @@
 import static org.hisp.dhis.importexport.ImportStrategy.NEW;
 import static org.hisp.dhis.importexport.ImportStrategy.NEW_AND_UPDATES;
 import static org.hisp.dhis.importexport.ImportStrategy.UPDATES;
+import static org.hisp.dhis.system.util.ConversionUtils.wrap;
 import static org.hisp.dhis.system.util.DateUtils.getDefaultDate;
 
+import java.io.OutputStream;
 import java.util.Date;
 import java.util.Map;
 
@@ -45,6 +47,7 @@
 import org.hisp.dhis.dataset.CompleteDataSetRegistration;
 import org.hisp.dhis.dataset.CompleteDataSetRegistrationService;
 import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.dxf2.importsummary.ImportConflict;
 import org.hisp.dhis.dxf2.importsummary.ImportCount;
@@ -52,6 +55,7 @@
 import org.hisp.dhis.importexport.ImportStrategy;
 import org.hisp.dhis.jdbc.batchhandler.DataValueBatchHandler;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.Period;
 import org.hisp.dhis.period.PeriodService;
 import org.hisp.dhis.period.PeriodType;
@@ -60,6 +64,7 @@
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.transaction.annotation.Transactional;
 
+@Transactional
 public class DefaultDataValueSetService
     implements DataValueSetService
 {
@@ -70,6 +75,12 @@
     private DataElementCategoryService categoryService;
     
     @Autowired
+    private DataSetService dataSetService;
+    
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+    
+    @Autowired
     private PeriodService periodService;
     
     @Autowired
@@ -81,13 +92,48 @@
     @Autowired
     private CurrentUserService currentUserService;
 
-    @Transactional
+    @Autowired
+    private DataValueSetStore dataValueSetStore;
+    
+    //--------------------------------------------------------------------------
+    // DataValueSet implementation
+    //--------------------------------------------------------------------------
+
+    public void writeDataValueSet( String dataSet, String period, String orgUnit, OutputStream out )
+    {
+        DataSet dataSet_ = dataSetService.getDataSet( dataSet );
+        Period period_ = PeriodType.getPeriodFromIsoString( period );
+        OrganisationUnit orgUnit_ = organisationUnitService.getOrganisationUnit( orgUnit );
+        
+        if ( dataSet_ == null )
+        {
+            throw new IllegalArgumentException( "Invalid data set: " + dataSet );
+        }
+        
+        if ( period_ == null )
+        {
+            throw new IllegalArgumentException( "Invalid period: " + period );
+        }
+        
+        if ( orgUnit_ == null )
+        {
+            throw new IllegalArgumentException( "Invalid org unit: " + orgUnit );
+        }
+        
+        CompleteDataSetRegistration registration = registrationService.getCompleteDataSetRegistration( dataSet_, period_, orgUnit_ );
+        
+        Date completeDate = registration != null ? registration.getDate() : null;
+        
+        period_ = periodService.reloadPeriod( period_ );
+        
+        dataValueSetStore.writeDataValueSet( dataSet_, completeDate, orgUnit_, period_, dataSet_.getDataElements(), wrap( period_ ), wrap( orgUnit_ ), out );
+    }
+    
     public ImportSummary saveDataValueSet( DataValueSet dataValueSet )
     {
         return saveDataValueSet( dataValueSet, IdentifiableProperty.UID, IdentifiableProperty.UID, false, ImportStrategy.NEW_AND_UPDATES );
     }
     
-    @Transactional
     public ImportSummary saveDataValueSet( DataValueSet dataValueSet, IdentifiableProperty dataElementIdScheme, IdentifiableProperty orgUnitIdScheme, boolean dryRun, ImportStrategy strategy )
     {
         ImportSummary summary = new ImportSummary();
@@ -104,11 +150,15 @@
         
         Period period = PeriodType.getPeriodFromIsoString( dataValueSet.getPeriod() );
         OrganisationUnit orgUnit = dataValueSet.getOrgUnit() != null ? identifiableObjectManager.getObject( OrganisationUnit.class, orgUnitIdScheme, dataValueSet.getOrgUnit() ) : null;
-
-        if ( dataSet != null )
+        
+        if ( dataSet != null && completeDate != null )
         {
             handleComplete( dataSet, completeDate, orgUnit, period, summary );
         }
+        else
+        {
+            summary.setDataSetComplete( Boolean.FALSE.toString() );
+        }
         
         DataElementCategoryOptionCombo fallbackCategoryOptionCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
 
@@ -202,44 +252,40 @@
         return summary;
     }
 
+    //--------------------------------------------------------------------------
+    // Supportive methods
+    //--------------------------------------------------------------------------
+
     private void handleComplete( DataSet dataSet, Date completeDate, OrganisationUnit orgUnit, Period period, ImportSummary summary )
     {
         if ( orgUnit == null )
         {
-            throw new IllegalArgumentException( "Org unit must be provided on data value set in order to complete data set" );
+            throw new IllegalArgumentException( "Org unit id must be provided to complete data set" );
         }
         
         if ( period == null )
         {
-            throw new IllegalArgumentException( "Period must be provided on data value set in order to complete data set" );
+            throw new IllegalArgumentException( "Period id must be provided to complete data set" );
         }
 
         CompleteDataSetRegistration completeAlready = registrationService.getCompleteDataSetRegistration( dataSet, period, orgUnit );
 
         String username = currentUserService.getCurrentUsername();
         
-        if ( completeDate == null && completeAlready != null )
-        {
-            throw new IllegalArgumentException( "Data value set is complete - a new complete date must be provided" );
+        if ( completeAlready != null )
+        {
+            completeAlready.setStoredBy( username );
+            completeAlready.setDate( completeDate );
+            
+            registrationService.updateCompleteDataSetRegistration( completeAlready );
+        }        
+        else
+        {
+            CompleteDataSetRegistration registration = new CompleteDataSetRegistration( dataSet, period, orgUnit, completeDate, username );
+            
+            registrationService.saveCompleteDataSetRegistration( registration );
         }
         
-        if ( completeDate != null )
-        {
-            if ( completeAlready != null )
-            {
-                completeAlready.setStoredBy( username );
-                completeAlready.setDate( completeDate );
-                
-                registrationService.updateCompleteDataSetRegistration( completeAlready );
-            }        
-            else
-            {
-                CompleteDataSetRegistration registration = new CompleteDataSetRegistration( dataSet, period, orgUnit, completeDate, username );
-                
-                registrationService.saveCompleteDataSetRegistration( registration );
-            }
-            
-            summary.setDataSetComplete( DateUtils.getMediumDateString( completeDate ) );
-        }
+        summary.setDataSetComplete( DateUtils.getMediumDateString( completeDate ) );
     }
 }

=== added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/SpringDataValueSetStore.java	2012-04-01 12:04:14 +0000
@@ -0,0 +1,111 @@
+package org.hisp.dhis.dxf2.datavalueset;
+
+/*
+ * Copyright (c) 2011, 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 static org.hisp.dhis.system.util.ConversionUtils.getIdentifiers;
+import static org.hisp.dhis.system.util.DateUtils.getMediumDateString;
+import static org.hisp.dhis.system.util.TextUtils.getCommaDelimitedString;
+
+import java.io.OutputStream;
+import java.util.Collection;
+import java.util.Date;
+import java.util.Set;
+
+import org.amplecode.staxwax.factory.XMLFactory;
+import org.amplecode.staxwax.writer.XMLWriter;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dxf2.datavalue.DataValue;
+import org.hisp.dhis.dxf2.datavalue.StreamingDataValue;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.period.Period;
+import org.hisp.dhis.period.PeriodType;
+import org.hisp.dhis.system.util.TextUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.jdbc.core.JdbcTemplate;
+import org.springframework.jdbc.support.rowset.SqlRowSet;
+
+public class SpringDataValueSetStore
+    implements DataValueSetStore
+{
+    @Autowired
+    private JdbcTemplate jdbcTemplate;
+
+    public void writeDataValueSet( DataSet dataSet, Date completeDate, OrganisationUnit orgUnit, Period period, 
+        Set<DataElement> dataElements, Set<Period> periods, Set<OrganisationUnit> orgUnits, OutputStream out )
+    {
+        XMLWriter writer = XMLFactory.getXMLWriter( out );
+        
+        SqlRowSet rowSet = jdbcTemplate.queryForRowSet( getDataValueSql( dataElements, periods, orgUnits ) );
+
+        DataValueSet dataValueSet = new StreamingDataValueSet( writer );
+        dataValueSet.setDataSet( dataSet.getUid() );
+        dataValueSet.setCompleteDate( getMediumDateString( completeDate ) );
+        dataValueSet.setPeriod( period.getIsoDate() );
+        dataValueSet.setOrgUnit( orgUnit.getUid() );
+        
+        while ( rowSet.next() )
+        {
+            DataValue dataValue = new StreamingDataValue( writer );
+            
+            String periodType = rowSet.getString( "name" );
+            Date startDate = rowSet.getDate( "startdate" );
+            Period isoPeriod = PeriodType.getPeriodTypeByName( periodType ).createPeriod( startDate );
+            
+            dataValue.setDataElement( rowSet.getString( "deuid" ) );
+            dataValue.setPeriod( isoPeriod.getIsoDate() );
+            dataValue.setOrgUnit( rowSet.getString( "ouuid" ) );
+            dataValue.setCategoryOptionCombo( rowSet.getString( "cocuid" ) );
+            dataValue.setValue( rowSet.getString( "value" ) );
+            dataValue.setStoredBy( rowSet.getString( "storedby" ) );
+            dataValue.setTimestamp( getMediumDateString( rowSet.getDate( "lastupdated" ) ) );
+            dataValue.setComment( rowSet.getString( "comment" ) );
+            dataValue.setFollowup( TextUtils.valueOf( "followup" ) );
+            
+            writer.closeElement();
+        }
+        
+        writer.closeElement();
+        writer.closeDocument();
+    }
+    
+    private String getDataValueSql( Collection<DataElement> dataElements, Collection<Period> periods, Collection<OrganisationUnit> orgUnits )
+    {
+        return
+            "select de.uid as deuid, pe.startdate, pt.name, ou.uid as ouuid, coc.uid as cocuid, dv.value, dv.storedby, dv.lastupdated, dv.comment, dv.followup " +
+            "from datavalue dv " +
+            "join dataelement de on (dv.dataelementid=de.dataelementid) " +
+            "join period pe on (dv.periodid=pe.periodid) " +
+            "join periodtype pt on (pe.periodtypeid=pt.periodtypeid) " +
+            "join organisationunit ou on (dv.sourceid=ou.organisationunitid) " +
+            "join categoryoptioncombo coc on (dv.categoryoptioncomboid=coc.categoryoptioncomboid) " +
+            "where dv.dataelementid in (" + getCommaDelimitedString( getIdentifiers( DataElement.class, dataElements ) ) + ") " +
+            "and dv.periodid in (" + getCommaDelimitedString( getIdentifiers( Period.class, periods ) ) + ") " +
+            "and dv.sourceid in (" + getCommaDelimitedString( getIdentifiers( OrganisationUnit.class, orgUnits ) ) + ")";
+    }
+}

=== added file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingDataValueSet.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingDataValueSet.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/StreamingDataValueSet.java	2012-04-01 12:04:14 +0000
@@ -0,0 +1,162 @@
+package org.hisp.dhis.dxf2.datavalueset;
+
+/*
+ * Copyright (c) 2011, 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 org.amplecode.staxwax.reader.XMLReader;
+import org.amplecode.staxwax.writer.XMLWriter;
+import org.hisp.dhis.dxf2.datavalue.DataValue;
+import org.hisp.dhis.dxf2.datavalue.StreamingDataValue;
+
+public class StreamingDataValueSet
+    extends DataValueSet
+{
+    private static final String XMLNS = "xmlns";
+    private static final String NS = "http://dhis2.org/schema/dxf/2.0";;
+
+    private static final String FIELD_DATAELEMENTIDSCHEME = "dataElementIdScheme";
+    private static final String FIELD_ORGUNITIDSCHEME = "orgUnitIdScheme";
+
+    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_PERIOD = "period";
+    private static final String FIELD_ORGUNIT = "orgUnit";
+    
+    private XMLWriter writer;
+    
+    private XMLReader reader;
+    
+    //--------------------------------------------------------------------------
+    // Constructor
+    //--------------------------------------------------------------------------
+
+    public StreamingDataValueSet( XMLWriter writer )
+    {
+        this.writer = writer;
+        
+        this.writer.openDocument();
+        this.writer.openElement( FIELD_DATAVALUESET );
+        this.writer.writeAttribute( XMLNS, NS );
+    }
+
+    public StreamingDataValueSet( XMLReader reader )
+    {
+        this.reader = reader;
+        
+        this.reader.moveToStartElement( FIELD_DATAVALUESET );        
+    }
+    
+    //--------------------------------------------------------------------------
+    // Getters
+    //--------------------------------------------------------------------------
+
+    @Override
+    public String getDataElementIdScheme()
+    {
+        return dataElementIdScheme = dataElementIdScheme == null ? reader.getAttributeValue( FIELD_DATAELEMENTIDSCHEME ) : dataElementIdScheme;
+    }
+
+    @Override
+    public String getOrgUnitIdScheme()
+    {
+        return orgUnitIdScheme = orgUnitIdScheme == null ? reader.getAttributeValue( FIELD_ORGUNITIDSCHEME ) : orgUnitIdScheme;
+    }
+
+    @Override
+    public String getDataSet()
+    {
+        return dataSet = dataSet == null ? reader.getAttributeValue( FIELD_DATASET ) : dataSet;
+    }
+
+    @Override
+    public String getCompleteDate()
+    {
+        return completeDate = completeDate == null ? reader.getAttributeValue( FIELD_COMPLETEDATE ) : completeDate; 
+    }
+
+    @Override
+    public String getPeriod()
+    {
+        return period = period == null ? reader.getAttributeValue( FIELD_PERIOD ) : period;
+    }
+
+    @Override
+    public String getOrgUnit()
+    {
+        return orgUnit = orgUnit == null ? reader.getAttributeValue( FIELD_ORGUNIT ) : orgUnit;
+    }
+
+    @Override
+    public DataValue getNextDataValue()
+    {
+        boolean hasNext = reader.moveToStartElement( FIELD_DATAVALUE, FIELD_DATAVALUESET );
+        
+        return hasNext ? new StreamingDataValue( reader ) : null;
+    }
+    
+    //--------------------------------------------------------------------------
+    // Setters
+    //--------------------------------------------------------------------------
+
+    @Override
+    public void setDataElementIdScheme( String dataElementIdScheme )
+    {
+        writer.writeAttribute( FIELD_DATAELEMENTIDSCHEME, dataElementIdScheme );
+    }
+
+    @Override
+    public void setOrgUnitIdScheme( String orgUnitIdScheme )
+    {
+        writer.writeAttribute( FIELD_ORGUNITIDSCHEME, orgUnitIdScheme );
+    }
+
+    @Override
+    public void setDataSet( String dataSet )
+    {
+        writer.writeAttribute( FIELD_DATASET, dataSet );
+    }
+
+    @Override
+    public void setCompleteDate( String completeDate )
+    {
+        writer.writeAttribute( FIELD_COMPLETEDATE, completeDate );
+    }
+
+    @Override
+    public void setPeriod( String period )
+    {
+        writer.writeAttribute( FIELD_PERIOD, period );
+    }
+
+    @Override
+    public void setOrgUnit( String orgUnit )
+    {
+        writer.writeAttribute( FIELD_ORGUNIT, orgUnit );
+    } 
+}

=== removed 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	2012-03-30 11:04:07 +0000
+++ dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/utils/DataValueSetMapper.java	1970-01-01 00:00:00 +0000
@@ -1,136 +0,0 @@
-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";;
-
-    //--------------------------------------------------------------------------
-    // Options
-    //--------------------------------------------------------------------------
-
-    private static final String FIELD_DATAELEMENTIDSCHEME = "dataElementIdScheme";
-    private static final String FIELD_ORGUNITIDSCHEME = "orgUnitIdScheme";
-
-    //--------------------------------------------------------------------------
-    // Properties
-    //--------------------------------------------------------------------------
-
-    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.setDataElementIdScheme( reader.getAttributeValue( FIELD_DATAELEMENTIDSCHEME ) );
-        dataValueSet.setOrgUnitIdScheme( reader.getAttributeValue( FIELD_ORGUNITIDSCHEME ) );
-        
-        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-dxf2/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml	2012-03-30 10:53:18 +0000
+++ dhis-2/dhis-dxf2/src/main/resources/META-INF/dhis/beans.xml	2012-04-01 12:04:14 +0000
@@ -8,4 +8,7 @@
   <bean id="org.hisp.dhis.dxf2.datavalueset.DataValueSetService"
       class="org.hisp.dhis.dxf2.datavalueset.DefaultDataValueSetService" />
 
+  <bean id="org.hisp.dhis.dxf2.datavalueset.DataValueSetStore"
+	  class="org.hisp.dhis.dxf2.datavalueset.SpringDataValueSetStore" />
+
 </beans>

=== modified file 'dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.java'
--- dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.java	2011-12-26 10:07:59 +0000
+++ dhis-2/dhis-support/dhis-support-system/src/main/java/org/hisp/dhis/system/util/ConversionUtils.java	2012-04-01 12:04:14 +0000
@@ -268,4 +268,17 @@
         
         return null;
     }
+    
+    /**
+     * Wraps an object in a set.
+     * 
+     * @param object the object to wrap.
+     * @return a set with the given object as element.
+     */
+    public static <T> Set<T> wrap( T object )
+    {
+        Set<T> set = new HashSet<T>();
+        set.add( object );
+        return set;
+    }
 }

=== 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	2012-03-29 21:52:27 +0000
+++ dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/DefaultXMLStreamWriter.java	2012-04-01 12:04:14 +0000
@@ -92,7 +92,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 ] );
+                    }
                 }
             }
         }
@@ -102,6 +105,21 @@
         }
     }
     
+    public void writeAttribute( String name, String value )
+    {
+        try
+        {
+            if ( value != null )
+            {
+                writer.writeAttribute( verifyNotNull( name ), value ); 
+            }
+        }
+        catch ( XMLStreamException ex )
+        {
+            throw new RuntimeException( "Failed to write attribute: " + name, ex );
+        }
+    }
+    
     public void writeElement( String name, String value )
     {
         try

=== 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	2012-03-29 21:52:27 +0000
+++ dhis-2/dhis-support/dhis-support-xml/src/main/java/org/amplecode/staxwax/writer/XMLWriter.java	2012-04-01 12:04:14 +0000
@@ -39,7 +39,7 @@
 public interface XMLWriter
 {
     /**
-     * Writes the XML declaration to ouput.
+     * Writes the XML declaration to output.
      * 
      * @param encoding the encoding the XML file.
      * @param version the version of the XML file.
@@ -47,7 +47,7 @@
     void openDocument();
     
     /**
-     * Writes the XML declaration to ouput.
+     * Writes the XML declaration to output.
      * 
      * @param encoding the encoding the XML file.
      * @param version the version of the XML file.
@@ -70,7 +70,15 @@
     void openElement( String name, String... attributeNameValuePairs );
     
     /**
-     * Writes an XML start tag, value, and end tag to ouput.
+     * Writes an XML attribute to output.
+     * 
+     * @param name the attribute name.
+     * @param value the attribute value.
+     */
+    void writeAttribute( String name, String value );
+    
+    /**
+     * Writes an XML start tag, value, and end tag to output.
      * 
      * @param name the name of the XML element.
      * @param value the value of the XML element.
@@ -94,14 +102,14 @@
     void writeCharacters( String characters );
     
     /**
-     * Writes non-parsed character data to ouput.
+     * Writes non-parsed character data to output.
      * 
      * @param cData character data to write.
      */
     void writeCData( String cData );
 
     /**
-     * Writes non-parsed character data to ouput.
+     * Writes non-parsed character data to output.
      * 
      * @param name the name of the XML element.
      * @param cData character data to write.

=== 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-30 11:04:07 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataValueSetController.java	2012-04-01 12:04:14 +0000
@@ -36,10 +36,10 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.hisp.dhis.api.webdomain.DataValueSets;
 import org.hisp.dhis.common.IdentifiableObject.IdentifiableProperty;
 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;
@@ -63,9 +63,9 @@
 
     @Autowired
     private DataValueSetService dataValueSetService;
-
+    
     @RequestMapping( method = RequestMethod.GET )
-    public String getDataValueSet( Model model ) throws Exception
+    public String getDataValueSets( Model model ) throws Exception
     {
         DataValueSets dataValueSets = new DataValueSets();
         dataValueSets.getDataValueSets().add( new DataValueSet() );
@@ -74,6 +74,18 @@
 
         return "dataValueSets";
     }
+
+    @RequestMapping( method = RequestMethod.GET, headers = {"Accept=application/xml"} )
+    public void getDataValueSet( @RequestParam String dataSet,
+                                 @RequestParam String period,
+                                 @RequestParam String orgUnit,
+                                 HttpServletResponse response ) throws IOException
+    {
+        log.info( "Get data value set for data set: " + dataSet + ", period: " + period + ", org unit: " + orgUnit );
+        
+        response.setContentType( CONTENT_TYPE_XML );
+        dataValueSetService.writeDataValueSet( dataSet, period, orgUnit, response.getOutputStream() );
+    }
     
     @RequestMapping( method = RequestMethod.POST, headers = {"Content-Type=application/xml"} )
     @PreAuthorize( "hasRole('ALL') or hasRole('F_DATAVALUE_ADD')" )

=== renamed file 'dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSets.java' => 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/DataValueSets.java'
--- dhis-2/dhis-dxf2/src/main/java/org/hisp/dhis/dxf2/datavalueset/DataValueSets.java	2012-03-28 16:04:53 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/DataValueSets.java	2012-04-01 12:04:14 +0000
@@ -1,4 +1,4 @@
-package org.hisp.dhis.dxf2.datavalueset;
+package org.hisp.dhis.api.webdomain;
 
 /*
 * Copyright (c) 2004-2012, University of Oslo
@@ -32,6 +32,7 @@
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlProperty;
 import com.fasterxml.jackson.dataformat.xml.annotation.JacksonXmlRootElement;
 import org.hisp.dhis.common.Dxf2Namespace;
+import org.hisp.dhis.dxf2.datavalueset.DataValueSet;
 
 import java.util.ArrayList;
 import java.util.List;

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/Resources.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/Resources.java	2012-03-28 16:04:53 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/webdomain/Resources.java	2012-04-01 12:04:14 +0000
@@ -39,7 +39,6 @@
 import org.hisp.dhis.dataelement.*;
 import org.hisp.dhis.dataset.DataSets;
 import org.hisp.dhis.document.Documents;
-import org.hisp.dhis.dxf2.datavalueset.DataValueSets;
 import org.hisp.dhis.indicator.IndicatorGroupSets;
 import org.hisp.dhis.indicator.IndicatorGroups;
 import org.hisp.dhis.indicator.IndicatorTypes;