← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 2850: Added spike for importing dataValueSets based on jaxb.

 

------------------------------------------------------------
revno: 2850
committer: Jo Størset <storset@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2011-02-15 12:16:27 +0530
message:
  Added spike for importing dataValueSets based on jaxb.
added:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValue.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSet.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSetMapper.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/package-info.java
  dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/datavalueset/
  dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/datavalueset/DataValueSetMapperTest.java
  dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/
  dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/base.xml
  dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/dataValueSet.xml
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml


--
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
=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset'
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValue.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValue.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValue.java	2011-02-15 06:46:27 +0000
@@ -0,0 +1,78 @@
+package org.hisp.dhis.importexport.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 javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlValue;
+
+@XmlAccessorType( XmlAccessType.FIELD )
+public class DataValue
+{
+
+    @XmlAttribute( name = "dataElement", required = true )
+    private String dataElementUuid;
+
+    @XmlAttribute( name = "categoryOptionCombo" )
+    private String categoryOptionComboUuid;
+
+    @XmlValue
+    private String value;
+
+    public String getDataElementUuid()
+    {
+        return dataElementUuid;
+    }
+
+    public void setDataElementUuid( String dataElementUuid )
+    {
+        this.dataElementUuid = dataElementUuid;
+    }
+
+    public String getCategoryOptionComboUuid()
+    {
+        return categoryOptionComboUuid;
+    }
+
+    public void setCategoryOptionComboUuid( String categoryOptionComboUuid )
+    {
+        this.categoryOptionComboUuid = categoryOptionComboUuid;
+    }
+
+    public String getValue()
+    {
+        return value;
+    }
+
+    public void setValue( String value )
+    {
+        this.value = value;
+    }
+
+}
\ No newline at end of file

=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSet.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSet.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSet.java	2011-02-15 06:46:27 +0000
@@ -0,0 +1,108 @@
+package org.hisp.dhis.importexport.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 java.util.List;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlElement;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlAccessorType( XmlAccessType.FIELD )
+@XmlRootElement
+public class DataValueSet
+{
+
+    @XmlAttribute( name = "dataSet", required = true )
+    private String dataSetUuid;
+
+    @XmlAttribute( name = "orgUnit", required = true )
+    private String organisationUnitUuid;
+
+    @XmlAttribute( name = "period", required = true )
+    private String periodIsoDate;
+
+    @XmlAttribute
+    private String storedBy;
+
+    @XmlElement( name = "dataValue" )
+    private List<DataValue> dataValues;
+
+    public String getDataSetUuid()
+    {
+        return dataSetUuid;
+    }
+
+    public void setDataSetUuid( String dataSetUuid )
+    {
+        this.dataSetUuid = dataSetUuid;
+    }
+
+    public String getOrganisationUnitUuid()
+    {
+        return organisationUnitUuid;
+    }
+
+    public void setOrganisationUnitUuid( String organisationUnitUuid )
+    {
+        this.organisationUnitUuid = organisationUnitUuid;
+    }
+
+    public String getPeriodIsoDate()
+    {
+        return periodIsoDate;
+    }
+
+    public void setPeriodIsoDate( String periodIsoDate )
+    {
+        this.periodIsoDate = periodIsoDate;
+    }
+
+    public String getStoredBy()
+    {
+        return storedBy;
+    }
+
+    public void setStoredBy( String storedBy )
+    {
+        this.storedBy = storedBy;
+    }
+
+    public List<DataValue> getDataValues()
+    {
+        return dataValues;
+    }
+
+    public void setDataValues( List<DataValue> dataValues )
+    {
+        this.dataValues = dataValues;
+    }
+
+}

=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSetMapper.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSetMapper.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/DataValueSetMapper.java	2011-02-15 06:46:27 +0000
@@ -0,0 +1,178 @@
+package org.hisp.dhis.importexport.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 java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSet;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.datavalue.DataValue;
+import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
+import org.hisp.dhis.period.Period;
+
+public class DataValueSetMapper
+{
+
+    private OrganisationUnitService organisationUnitService;
+
+    private DataSetService dataSetService;
+
+    private DataElementCategoryService categoryService;
+
+    private DataElementService dataElementService;
+
+    public List<DataValue> getDataValues( DataValueSet dataValueSet )
+    {
+        Date timestamp = new Date();
+
+        DataSet dataSet = dataSetService.getDataSet( dataValueSet.getDataSetUuid() );
+
+        if ( dataSet == null )
+        {
+            throw new IllegalArgumentException( "Data set with UUID " + dataValueSet.getDataSetUuid()
+                + " does not exist" );
+        }
+
+        OrganisationUnit unit = organisationUnitService.getOrganisationUnit( dataValueSet.getOrganisationUnitUuid() );
+
+        if ( unit == null )
+        {
+            throw new IllegalArgumentException( "Org unit with UUID " + dataValueSet.getOrganisationUnitUuid()
+                + " does not exist" );
+        }
+
+        if ( !dataSet.getSources().contains( unit ) )
+        {
+            throw new IllegalArgumentException( "Org unit with UUID " + dataValueSet.getOrganisationUnitUuid()
+                + " does not report data set with UUID " + dataSet.getUuid() );
+        }
+
+        Period period;
+
+        try
+        {
+            period = dataSet.getPeriodType().createPeriod( dataValueSet.getPeriodIsoDate() );
+        }
+        catch ( Exception e )
+        {
+            throw new IllegalArgumentException( "Period " + dataValueSet.getPeriodIsoDate()
+                + " is not valid period of type " + dataSet.getPeriodType().getName() );
+        }
+
+        List<org.hisp.dhis.importexport.datavalueset.DataValue> dxfDataValues = dataValueSet.getDataValues();
+        List<DataValue> dataValues = new ArrayList<DataValue>( dxfDataValues.size() );
+
+        for ( org.hisp.dhis.importexport.datavalueset.DataValue dxfValue : dxfDataValues )
+        {
+            DataValue dataValue = getDataValue( dxfValue, dataSet );
+            dataValue.setSource( unit );
+            dataValue.setTimestamp( timestamp );
+            dataValue.setStoredBy( dataValueSet.getStoredBy() );
+            dataValue.setPeriod( period );
+
+            dataValues.add( dataValue );
+
+        }
+
+        return dataValues;
+    }
+
+    public DataValue getDataValue( org.hisp.dhis.importexport.datavalueset.DataValue dxfValue, DataSet dataSet )
+    {
+        DataElement dataElement = dataElementService.getDataElement( dxfValue.getDataElementUuid() );
+
+        if ( dataElement == null )
+        {
+            throw new IllegalArgumentException( "Data value with UUID " + dxfValue.getDataElementUuid()
+                + " does not exist" );
+        }
+
+        if ( !dataSet.getDataElements().contains( dataElement ) )
+        {
+            throw new IllegalArgumentException( "Data element " + dataElement.getUuid() + " isn't in data set "
+                + dataSet.getUuid() );
+        }
+
+        DataValue dv = new DataValue();
+
+        dv.setDataElement( dataElement );
+
+        dv.setValue( dxfValue.getValue() );
+
+        DataElementCategoryOptionCombo combo;
+
+        String comboId = dxfValue.getCategoryOptionComboUuid();
+
+        if ( comboId != null )
+        {
+            combo = categoryService.getDataElementCategoryOptionCombo( Integer.parseInt( comboId ) );
+
+            if ( combo == null )
+            {
+                throw new IllegalArgumentException( "DataElementCategoryOptionCombo with UUID " + comboId
+                    + " does not exist" );
+            }
+        }
+        else
+        {
+            combo = categoryService.getDefaultDataElementCategoryOptionCombo();
+        }
+
+        dv.setOptionCombo( combo );
+
+        return dv;
+    }
+
+    public void setOrganisationUnitService( OrganisationUnitService organisationUnitService )
+    {
+        this.organisationUnitService = organisationUnitService;
+    }
+
+    public void setDataSetService( DataSetService dataSetService )
+    {
+        this.dataSetService = dataSetService;
+    }
+
+    public void setCategoryService( DataElementCategoryService categoryService )
+    {
+        this.categoryService = categoryService;
+    }
+
+    public void setDataElementService( DataElementService dataElementService )
+    {
+        this.dataElementService = dataElementService;
+    }
+
+}

=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/package-info.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/package-info.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/datavalueset/package-info.java	2011-02-15 06:46:27 +0000
@@ -0,0 +1,32 @@
+@javax.xml.bind.annotation.XmlSchema( 
+    namespace = "http://dhis2.org/schema/dataValueSet/0.1";, 
+    xmlns = { @javax.xml.bind.annotation.XmlNs( prefix = "xs", namespaceURI = "http://www.w3.org/2001/XMLSchema"; ) }, 
+    elementFormDefault = javax.xml.bind.annotation.XmlNsForm.QUALIFIED )
+package org.hisp.dhis.importexport.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.
+ */

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml	2011-02-02 17:56:01 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/resources/META-INF/dhis/beans.xml	2011-02-15 06:46:27 +0000
@@ -405,4 +405,11 @@
 		<property name="dataSetLockService" ref="org.hisp.dhis.datalock.DataSetLockService" />
 	</bean>
 
+  <bean id="org.hisp.dhis.importexport.datavalueset.DataValueSetMapper" class="org.hisp.dhis.importexport.datavalueset.DataValueSetMapper">
+    <property name="categoryService" ref="org.hisp.dhis.dataelement.DataElementCategoryService" />
+    <property name="organisationUnitService" ref="org.hisp.dhis.organisationunit.OrganisationUnitService" />
+    <property name="dataElementService" ref="org.hisp.dhis.dataelement.DataElementService" />
+    <property name="dataSetService" ref="org.hisp.dhis.dataset.DataSetService" />
+  </bean>
+
 </beans>

=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/datavalueset'
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/datavalueset/DataValueSetMapperTest.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/datavalueset/DataValueSetMapperTest.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/datavalueset/DataValueSetMapperTest.java	2011-02-15 06:46:27 +0000
@@ -0,0 +1,238 @@
+package org.hisp.dhis.importexport.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 junit.framework.Assert.assertEquals;
+import static junit.framework.Assert.assertNull;
+import static junit.framework.Assert.assertTrue;
+import static junit.framework.Assert.fail;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+
+import javax.xml.bind.JAXBContext;
+import javax.xml.bind.JAXBException;
+import javax.xml.bind.Unmarshaller;
+
+import org.hisp.dhis.DhisTest;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.dataelement.DataElementService;
+import org.hisp.dhis.dataset.DataSetService;
+import org.hisp.dhis.datavalue.DataValue;
+import org.hisp.dhis.datavalue.DataValueService;
+import org.hisp.dhis.importexport.ImportException;
+import org.hisp.dhis.importexport.ImportParams;
+import org.hisp.dhis.importexport.ImportService;
+import org.hisp.dhis.importexport.ImportStrategy;
+import org.hisp.dhis.importexport.datavalueset.DataValueSet;
+import org.hisp.dhis.importexport.datavalueset.DataValueSetMapper;
+import org.hisp.dhis.importexport.util.ImportExportUtils;
+import org.junit.Test;
+
+/**
+ * Messy test class checking that jaxb produces the expected java @link{DataValueSet data value set} structure, that
+ * the set is converted into a correct list of {@link DataValues data values} and also checks that it is stored.. 
+ */
+public class DataValueSetMapperTest
+    extends DhisTest
+{
+
+    private static final String ORGANISATION_UNIT_UUID = "9C1B1B5E-3D65-48F2-8D1D-D36C60DD7344";
+
+    private static final String DATA_SET_UUID = "16B2299E-ECD6-46CF-A61F-817D350C180D";
+
+    private static final String DATA_ELEMENT_UUID = "56B2299E-ECD6-46CF-A61F-817D350C180D";
+
+    private static final String DATA_ELEMENT_NOT_IN_SET_UUID = "96B2299E-ECD6-46CF-A61F-817D350C180D";
+    
+    private DataValueSetMapper mapper;
+
+    private DataValueSet dataValueSet;
+
+    private ImportService importService;
+
+    private ClassLoader classLoader;
+
+    private DataElementCategoryOptionCombo defaultCombo;
+
+    // -------------------------------------------------------------------------
+    // Fixture
+    // -------------------------------------------------------------------------
+
+    @SuppressWarnings( "serial" )
+    @Override
+    public void setUpTest()
+        throws JAXBException, IOException, ImportException
+    {
+        importService = (ImportService) getBean( "org.hisp.dhis.importexport.ImportService" );
+        categoryService = (DataElementCategoryService) getBean( DataElementCategoryService.ID );
+        dataElementService = (DataElementService) getBean( DataElementService.ID );
+        dataSetService = (DataSetService) getBean( DataSetService.ID );
+        dataValueService = (DataValueService) getBean( DataValueService.ID );
+        
+        mapper = (DataValueSetMapper) getBean( "org.hisp.dhis.importexport.datavalueset.DataValueSetMapper" );
+
+        classLoader = Thread.currentThread().getContextClassLoader();
+
+        InputStream is = classLoader.getResourceAsStream( "datavalueset/base.xml" );
+        ImportParams importParams = ImportExportUtils.getImportParams( ImportStrategy.NEW_AND_UPDATES, false, false,
+            false );
+        importService.importData( importParams, is );
+        is.close();
+
+        dataValueSet = new DataValueSet();
+        dataValueSet.setDataSetUuid( DATA_SET_UUID );
+        dataValueSet.setPeriodIsoDate( "2011W5" );
+        dataValueSet.setOrganisationUnitUuid( ORGANISATION_UNIT_UUID );
+        dataValueSet.setStoredBy( "misterindia" );
+
+        final org.hisp.dhis.importexport.datavalueset.DataValue dv = new org.hisp.dhis.importexport.datavalueset.DataValue();
+        dv.setDataElementUuid( DATA_ELEMENT_UUID );
+        dv.setValue( "11" );
+
+        dataValueSet.setDataValues( new ArrayList<org.hisp.dhis.importexport.datavalueset.DataValue>() {{ add( dv ); }} );
+
+        defaultCombo = categoryService.getDefaultDataElementCategoryOptionCombo();
+
+    }
+
+    // -------------------------------------------------------------------------
+    // Tests
+    // -------------------------------------------------------------------------
+
+    @Test
+    public void testJaxb()
+        throws JAXBException, IOException
+    {
+        JAXBContext jc = JAXBContext.newInstance( DataValueSet.class, org.hisp.dhis.importexport.datavalueset.DataValue.class );
+        Unmarshaller u = jc.createUnmarshaller();
+        InputStream is = classLoader.getResourceAsStream( "datavalueset/dataValueSet.xml" );
+
+        DataValueSet dxfDataValueSet = (DataValueSet) u.unmarshal( is );
+        is.close();
+
+        assertEquals( dataValueSet.getDataSetUuid(), dxfDataValueSet.getDataSetUuid() );
+        assertEquals( dataValueSet.getPeriodIsoDate(), dxfDataValueSet.getPeriodIsoDate() );
+        assertEquals( dataValueSet.getOrganisationUnitUuid(), dxfDataValueSet.getOrganisationUnitUuid() );
+        assertEquals( dataValueSet.getStoredBy(), dxfDataValueSet.getStoredBy() );
+
+        assertEquals( 1, dxfDataValueSet.getDataValues().size() );
+
+        org.hisp.dhis.importexport.datavalueset.DataValue dv = dxfDataValueSet.getDataValues().get( 0 );
+
+        assertEquals( dataValueSet.getDataValues().get( 0 ).getDataElementUuid(), dv.getDataElementUuid() );
+
+        assertNull( dv.getCategoryOptionComboUuid() );
+    }
+
+    @Test
+    public void simpleMapping()
+        throws Exception
+    {
+        long before = new Date().getTime();
+
+        List<DataValue> dataValues = mapper.getDataValues( dataValueSet );
+
+        long after = new Date().getTime();
+
+        assertEquals( 1, dataValues.size() );
+
+        DataValue dv = dataValues.get( 0 );
+
+        verifyDataValue( before, after, dv );
+
+        dataValueService.addDataValue( dv );
+        Collection<DataValue> persistedDataValues = dataValueService.getAllDataValues();
+        assertEquals(1, persistedDataValues.size());
+        
+        DataValue persisted = persistedDataValues.iterator().next();
+        assertEquals( dv, persisted );
+        verifyDataValue( before, after, persisted );
+
+    }
+
+    @Test
+    public void missingThingsFromInput() {
+
+        dataValueSet.setDataSetUuid( null );
+        try {
+            mapper.getDataValues( dataValueSet );
+            fail("Should miss data set");
+        
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+
+        dataValueSet.setDataSetUuid( DATA_SET_UUID );
+        dataValueSet.setOrganisationUnitUuid( "ladlalad" );
+        try {
+            mapper.getDataValues( dataValueSet );
+            fail("Should miss org unit");
+        
+        } catch (IllegalArgumentException e) {
+            // Expected
+        }
+
+        dataValueSet.setOrganisationUnitUuid( ORGANISATION_UNIT_UUID );
+        
+        final org.hisp.dhis.importexport.datavalueset.DataValue dv = new org.hisp.dhis.importexport.datavalueset.DataValue();
+        dv.setDataElementUuid( DATA_ELEMENT_NOT_IN_SET_UUID );
+        dv.setValue( "11" );
+        dataValueSet.getDataValues().add( dv );
+        
+        try {
+            mapper.getDataValues( dataValueSet );
+            fail("Should not accept extra data value");
+        
+        } catch (IllegalArgumentException e) {
+            // Expected
+            System.out.println(e.getMessage());
+        }
+        
+    }
+
+    private void verifyDataValue( long before, long after, DataValue dv )
+    {
+        assertEquals( DATA_ELEMENT_UUID, dv.getDataElement().getUuid() );
+        assertEquals( ORGANISATION_UNIT_UUID, dv.getSource().getUuid() );
+        assertEquals( "misterindia", dv.getStoredBy() );
+        assertEquals( "11", dv.getValue() );
+
+        long time = dv.getTimestamp().getTime();
+        assertTrue( time >= before );
+        assertTrue( time <= after );
+
+        assertEquals( defaultCombo, dv.getOptionCombo() );
+    }
+
+}

=== added directory 'dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset'
=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/base.xml'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/base.xml	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/base.xml	2011-02-15 06:46:27 +0000
@@ -0,0 +1,158 @@
+<?xml version='1.0'?>
+<dxf xmlns="http://dhis2.org/schema/dxf/1.0"; minorVersion="1.2" exported="2011-02-14">
+  <concepts>
+    <concept>
+      <id>9</id>
+      <name>default</name>
+    </concept>
+  </concepts>
+
+  <categoryOptions>
+    <categoryOption>
+      <id>10</id>
+      <name>default</name>
+    </categoryOption>
+  </categoryOptions>
+
+  <categories>
+    <category>
+      <id>11</id>
+      <name>default</name>
+      <conceptid>9</conceptid>
+    </category>
+  </categories>
+
+  <categoryCombos>
+    <categoryCombo>
+      <id>12</id>
+      <name>default</name>
+    </categoryCombo>
+  </categoryCombos>
+
+  <categoryOptionCombos>
+    <categoryOptionCombo>
+      <id>13</id>
+      <categoryCombo>
+        <id>12</id>
+        <name>default</name>
+      </categoryCombo>
+      <categoryOptions>
+        <categoryOption>
+          <id>10</id>
+          <name>default</name>
+        </categoryOption>
+      </categoryOptions>
+    </categoryOptionCombo>
+  </categoryOptionCombos>
+
+  <categoryCategoryOptionAssociations>
+    <categoryCategoryOptionAssociation>
+      <category>11</category>
+      <categoryOption>10</categoryOption>
+      <sortOrder>1</sortOrder>
+    </categoryCategoryOptionAssociation>
+  </categoryCategoryOptionAssociations>
+
+  <categoryComboCategoryAssociations>
+    <categoryComboCategoryAssociation>
+      <categoryCombo>12</categoryCombo>
+      <category>11</category>
+      <sortOrder>1</sortOrder>
+    </categoryComboCategoryAssociation>
+  </categoryComboCategoryAssociations>
+
+  <dataElements>
+    <dataElement>
+      <id>21</id>
+      <uuid>56B2299E-ECD6-46CF-A61F-817D350C180D</uuid>
+      <name>Data element 1</name>
+      <alternativeName></alternativeName>
+      <shortName>data element 1</shortName>
+      <code>ELEM1</code>
+      <description></description>
+      <active>true</active>
+      <type>int</type>
+      <aggregationOperator>sum</aggregationOperator>
+      <categoryCombo>12</categoryCombo>
+      <lastUpdated>2011-02-14</lastUpdated>
+    </dataElement>
+    <dataElement>
+      <id>99</id>
+      <uuid>96B2299E-ECD6-46CF-A61F-817D350C180D</uuid>
+      <name>Not in data set</name>
+      <shortName>not in</shortName>
+      <code>ELEM2</code>
+      <description></description>
+      <active>true</active>
+      <type>int</type>
+      <aggregationOperator>sum</aggregationOperator>
+      <categoryCombo>12</categoryCombo>
+      <lastUpdated>2011-02-14</lastUpdated>
+    </dataElement>
+  </dataElements>
+
+  <dataSets>
+    <dataSet>
+      <id>20</id>
+      <uuid>16B2299E-ECD6-46CF-A61F-817D350C180D</uuid>
+      <name><![CDATA[DataSet1]]></name>
+      <shortName><![CDATA[shortname1]]></shortName>
+      <code>DATASET1</code>
+      <periodType>Weekly</periodType>
+    </dataSet>
+  </dataSets>
+
+  <dataSetMembers>
+  </dataSetMembers>
+
+  <organisationUnits>
+    <organisationUnit>
+      <id>22</id>
+      <uuid>9C1B1B5E-3D65-48F2-8D1D-D36C60DD7344</uuid>
+      <name>OrgUnit1</name>
+      <shortName>OrgUnit1</shortName>
+      <code>UNIT1</code>
+      <openingDate>1990-01-01</openingDate>
+      <closedDate></closedDate>
+      <active>true</active>
+      <comment></comment>
+      <geoCode></geoCode>
+      <feature type="">
+      </feature>
+      <lastUpdated>2011-02-14</lastUpdated>
+    </organisationUnit>
+  </organisationUnits>
+
+  <organisationUnitRelationships>
+  </organisationUnitRelationships>
+
+  <groupSets>
+    <groupSet>
+      <id>14</id>
+      <name>Type</name>
+      <description>Type of organisation unit, examples are PHU, chiefdom and district</description>
+      <compulsory>false</compulsory>
+    </groupSet>
+    <groupSet>
+      <id>15</id>
+      <name>Ownership</name>
+      <description>Ownership of organisation unit, examples are private and public</description>
+      <compulsory>false</compulsory>
+    </groupSet>
+  </groupSets>
+
+  <organisationUnitLevels>
+    <organisationUnitLevel>
+      <id>0</id>
+      <level>1</level>
+      <name>Level 1</name>
+    </organisationUnitLevel>
+  </organisationUnitLevels>
+
+  <dataSetSourceAssociations>
+    <dataSetSourceAssociation>
+      <dataSet>20</dataSet>
+      <source>22</source>
+    </dataSetSourceAssociation>
+  </dataSetSourceAssociations>
+</dxf>

=== added file 'dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/dataValueSet.xml'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/dataValueSet.xml	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/resources/datavalueset/dataValueSet.xml	2011-02-15 06:46:27 +0000
@@ -0,0 +1,8 @@
+<?xml version='1.0'?>
+
+<dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0.SNAPSHOT";
+  dataSet="16B2299E-ECD6-46CF-A61F-817D350C180D" period="2011W5"
+  orgUnit="9C1B1B5E-3D65-48F2-8D1D-D36C60DD7344" storedBy="misterindia">
+
+ <dataValue dataElement="56B2299E-ECD6-46CF-A61F-817D350C180D">11</dataValue>
+</dataValueSet>