← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4500: Work in progress:

 

Merge authors:
  Bob Jolliffe bobjolliffe@xxxxxxxxx
------------------------------------------------------------
revno: 4500 [merge]
committer: Bob Jolliffe bobjolliffe@xxxxxxxxx
branch nick: dhis2
timestamp: Fri 2011-09-02 10:50:17 +0100
message:
  Work in progress:
  Implemented arbitrary attributes on datavalue and id scheme attributes on datavalueset.  See testJaxbDimensions. No underlying logic yet :-)
  Ignore storedBy attribute.  Its not illegal - no attribute is illegal - it just isn't used.  storedBy is determined by currentUserService. 
modified:
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValue.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValueSet.java
  dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetService.java
  dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetServiceTest.java
  dhis-2/dhis-services/dhis-service-importexport/src/test/resources/dxf2/dataValueSet.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
=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValue.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValue.java	2011-02-18 20:17:34 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValue.java	2011-09-02 09:16:34 +0000
@@ -27,44 +27,62 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import java.util.HashMap;
+import java.util.Map;
 import javax.xml.bind.annotation.XmlAccessType;
 import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAnyAttribute;
 import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.namespace.QName;
 
 @XmlAccessorType( XmlAccessType.FIELD )
 public class DataValue
 {
 
     @XmlAttribute( name = "dataElement", required = true )
-    private String dataElementUuid;
+    private String dataElementIdentifier;
 
     @XmlAttribute( name = "categoryOptionCombo" )
-    private String categoryOptionComboUuid;
+    private String categoryOptionComboIdentifier;
 
-    @XmlAttribute
-    private String storedBy;
+    @XmlAnyAttribute
+    Map<QName,Object> dimensions;
 
     @XmlAttribute
     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 getDataElementIdentifier()
+    {
+        return dataElementIdentifier;
+    }
+
+    public void setDataElementIdentifier( String dataElementId )
+    {
+        this.dataElementIdentifier = dataElementId;
+    }
+
+    public String getCategoryOptionComboIdentifier()
+    {
+        return categoryOptionComboIdentifier;
+    }
+
+    public void setCategoryOptionComboIdentifier( String categoryOptionComboId )
+    {
+        this.categoryOptionComboIdentifier = categoryOptionComboId;
+    }
+
+    public Map<QName, Object> getDimensions()
+    {
+        if ( dimensions == null )
+        {
+            dimensions = new HashMap<QName,Object>();
+        }
+        return dimensions;
+    }
+
+    public void setDimensions( Map<QName, Object> dimensions )
+    {
+        this.dimensions = dimensions;
     }
 
     public String getValue()
@@ -77,14 +95,4 @@
         this.value = value;
     }
 
-    public String getStoredBy()
-    {
-        return storedBy;
-    }
-
-    public void setStoredBy( String storedBy )
-    {
-        this.storedBy = storedBy;
-    }
-
 }
\ No newline at end of file

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValueSet.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValueSet.java	2011-02-21 10:32:35 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValueSet.java	2011-09-02 09:16:34 +0000
@@ -41,10 +41,10 @@
 {
 
     @XmlAttribute( name = "dataSet" )
-    private String dataSetUuid;
+    private String dataSetIdentifier;
 
     @XmlAttribute( name = "orgUnit", required = true )
-    private String organisationUnitUuid;
+    private String organisationUnitIdentifier;
 
     @XmlAttribute( name = "period", required = true )
     private String periodIsoDate;
@@ -52,28 +52,53 @@
     @XmlAttribute( name = "complete" )
     private String completeDate;
 
+    @XmlAttribute( name = "orgUnitIdScheme" )
+    private String orgUnitIdScheme;
+
+    @XmlAttribute( name = "dataElementIdScheme" )
+    private String dataElementIdScheme;
+
     @XmlElement( name = "dataValue" )
     private List<DataValue> dataValues;
 
+    public String getDataElementIdScheme()
+    {
+        return dataElementIdScheme;
+    }
+
+    public void setDataElementIdScheme( String dataElementIdScheme )
+    {
+        this.dataElementIdScheme = dataElementIdScheme;
+    }
+
+    public String getOrgUnitIdScheme()
+    {
+        return orgUnitIdScheme;
+    }
+
+    public void setOrgUnitIdScheme( String orgUnitIdScheme )
+    {
+        this.orgUnitIdScheme = orgUnitIdScheme;
+    }
     
-    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 getDataSetIdentifier()
+    {
+        return dataSetIdentifier;
+    }
+
+    public void setDataSetIdentifier( String dataSetId )
+    {
+        this.dataSetIdentifier = dataSetId;
+    }
+
+    public String getOrganisationUnitIdentifier()
+    {
+        return organisationUnitIdentifier;
+    }
+
+    public void setOrganisationUnitIdentifier( String organisationUnitId )
+    {
+        this.organisationUnitIdentifier = organisationUnitId;
     }
 
     public String getPeriodIsoDate()

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetService.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetService.java	2011-02-25 18:08:38 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetService.java	2011-09-02 09:16:34 +0000
@@ -124,7 +124,7 @@
 
         DataSet dataSet = getDataSet( dataValueSet );
 
-        OrganisationUnit unit = getOrgUnit( dataValueSet.getOrganisationUnitUuid() );
+        OrganisationUnit unit = getOrgUnit( dataValueSet.getOrganisationUnitIdentifier() );
 
         if ( !dataSet.getSources().contains( unit ) )
         {
@@ -147,7 +147,7 @@
     {
         DataSet dataSet = null;
 
-        String uuid = dataValueSet.getDataSetUuid();
+        String uuid = dataValueSet.getDataSetIdentifier();
         if ( uuid != null )
         {
             dataSet = dataSetService.getDataSet( uuid );
@@ -176,7 +176,7 @@
 
         for ( org.hisp.dhis.importexport.dxf2.model.DataValue value : dataValueSet.getDataValues() )
         {
-            DataElement dataElement = getDataElement( value.getDataElementUuid() );
+            DataElement dataElement = getDataElement( value.getDataElementIdentifier() );
             Set<DataSet> dataSets = dataElement.getDataSets();
 
             if ( dataSets == null || dataSets.isEmpty() )
@@ -224,7 +224,7 @@
     private void saveDataValue( Date timestamp, DataSet dataSet, OrganisationUnit unit, Period period,
         org.hisp.dhis.importexport.dxf2.model.DataValue dxfValue )
     {
-        DataElement dataElement = getDataElement( dxfValue.getDataElementUuid() );
+        DataElement dataElement = getDataElement( dxfValue.getDataElementIdentifier() );
 
         if ( !dataSet.getDataElements().contains( dataElement ) )
         {
@@ -232,7 +232,7 @@
                 + dataSet.getUuid() );
         }
 
-        DataElementCategoryOptionCombo combo = getOptionCombo( dxfValue.getCategoryOptionComboUuid(), dataElement );
+        DataElementCategoryOptionCombo combo = getOptionCombo( dxfValue.getCategoryOptionComboIdentifier(), dataElement );
 
         DataValue dv = dataValueService.getDataValue( unit, dataElement, period, combo );
 
@@ -240,7 +240,8 @@
 
         // dataElement.isValidValue(value);
 
-        String storedBy = getStoredBy( dxfValue );
+        String storedBy = currentUserService.getCurrentUsername();
+
 
         if ( dv == null )
         {
@@ -285,17 +286,6 @@
         }
     }
 
-    private String getStoredBy( org.hisp.dhis.importexport.dxf2.model.DataValue dxfValue )
-    {
-        String storedBy = dxfValue.getStoredBy();
-
-        if ( storedBy == null || storedBy.trim().equals( "" ) )
-        {
-            storedBy = currentUserService.getCurrentUsername();
-        }
-        return storedBy;
-    }
-
     private CompleteDataSetRegistration getComplete( DataSet dataSet, OrganisationUnit unit, Period period,
         String completeDateString, CompleteDataSetRegistration complete )
     {

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetServiceTest.java'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetServiceTest.java	2011-03-16 20:50:40 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetServiceTest.java	2011-09-02 09:16:34 +0000
@@ -37,10 +37,13 @@
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
+import java.util.HashMap;
+import java.util.Map;
 
 import javax.xml.bind.JAXBContext;
 import javax.xml.bind.JAXBException;
 import javax.xml.bind.Unmarshaller;
+import javax.xml.namespace.QName;
 
 import org.hisp.dhis.DhisTest;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
@@ -114,14 +117,13 @@
         is.close();
 
         dataValueSet = new DataValueSet();
-        dataValueSet.setDataSetUuid( DATA_SET_UUID );
+        dataValueSet.setDataSetIdentifier( DATA_SET_UUID );
         dataValueSet.setPeriodIsoDate( "2011W5" );
-        dataValueSet.setOrganisationUnitUuid( ORGANISATION_UNIT_UUID );
+        dataValueSet.setOrganisationUnitIdentifier( ORGANISATION_UNIT_UUID );
 
         final org.hisp.dhis.importexport.dxf2.model.DataValue dv = new org.hisp.dhis.importexport.dxf2.model.DataValue();
-        dv.setDataElementUuid( DATA_ELEMENT_UUID );
+        dv.setDataElementIdentifier( DATA_ELEMENT_UUID );
         dv.setValue( "11" );
-        dv.setStoredBy( "misterindia" );
 
         dataValueSet.setDataValues( new ArrayList<org.hisp.dhis.importexport.dxf2.model.DataValue>()
         {
@@ -151,19 +153,51 @@
         DataValueSet dxfDataValueSet = (DataValueSet) u.unmarshal( is );
         is.close();
 
-        assertEquals( dataValueSet.getDataSetUuid(), dxfDataValueSet.getDataSetUuid() );
+        assertEquals( dataValueSet.getDataSetIdentifier(), dxfDataValueSet.getDataSetIdentifier() );
         assertEquals( dataValueSet.getPeriodIsoDate(), dxfDataValueSet.getPeriodIsoDate() );
-        assertEquals( dataValueSet.getOrganisationUnitUuid(), dxfDataValueSet.getOrganisationUnitUuid() );
+        assertEquals( dataValueSet.getOrganisationUnitIdentifier(), dxfDataValueSet.getOrganisationUnitIdentifier() );
 
         assertEquals( 1, dxfDataValueSet.getDataValues().size() );
 
         org.hisp.dhis.importexport.dxf2.model.DataValue dv = dxfDataValueSet.getDataValues().get( 0 );
         org.hisp.dhis.importexport.dxf2.model.DataValue dataValue = dataValueSet.getDataValues().get( 0 );
 
-        assertEquals( dataValue.getDataElementUuid(), dv.getDataElementUuid() );
-        assertEquals( dataValue.getStoredBy(), dv.getStoredBy() );
-
-        assertNull( dv.getCategoryOptionComboUuid() );
+        assertEquals( dataValue.getDataElementIdentifier(), dv.getDataElementIdentifier() );
+
+        assertNull( dv.getCategoryOptionComboIdentifier() );
+
+    }
+
+    @Test
+    public void testJaxbDimensions()
+        throws JAXBException, IOException
+    {
+        JAXBContext jc = JAXBContext.newInstance( DataValueSet.class,
+            org.hisp.dhis.importexport.dxf2.model.DataValue.class );
+        Unmarshaller u = jc.createUnmarshaller();
+        InputStream is = classLoader.getResourceAsStream( "dxf2/dataValueSet_dim.xml" );
+
+        DataValueSet dxfDataValueSet = (DataValueSet) u.unmarshal( is );
+        is.close();
+
+        assertEquals( "internal", dxfDataValueSet.getDataElementIdScheme() );
+        assertEquals( "code", dxfDataValueSet.getOrgUnitIdScheme() );
+
+        assertEquals( 1, dxfDataValueSet.getDataValues().size() );
+
+        org.hisp.dhis.importexport.dxf2.model.DataValue dv = dxfDataValueSet.getDataValues().get( 0 );
+
+        Map<QName,Object> dimensions = dv.getDimensions();
+        assertEquals( 2, dimensions.size() );
+
+        QName sex = new QName("sex");
+        QName age = new QName("age");
+
+        assertTrue(dimensions.containsKey( sex ));
+        assertTrue(dimensions.containsKey( age));
+        assertEquals("1", dimensions.get( sex ));
+        assertEquals("2", dimensions.get( age ));
+
     }
 
     @Test
@@ -239,7 +273,7 @@
     @Test
     public void dataSetMissing()
     {
-        dataValueSet.setDataSetUuid( null );
+        dataValueSet.setDataSetIdentifier( null );
         setValue( "999" );
         
         testSave( "999" );
@@ -249,7 +283,7 @@
     @Test
     public void orgunitMissingOrNotInSet()
     {
-        dataValueSet.setOrganisationUnitUuid( "ladlalad" );
+        dataValueSet.setOrganisationUnitIdentifier( "ladlalad" );
         try
         {
             service.saveDataValueSet( dataValueSet );
@@ -261,7 +295,7 @@
             // Expected
         }
 
-        dataValueSet.setOrganisationUnitUuid( ORGANISATION_UNIT_NOT_IN_SET_UUID );
+        dataValueSet.setOrganisationUnitIdentifier( ORGANISATION_UNIT_NOT_IN_SET_UUID );
 
         try
         {
@@ -372,7 +406,7 @@
     {
 
         org.hisp.dhis.importexport.dxf2.model.DataValue dv = new org.hisp.dhis.importexport.dxf2.model.DataValue();
-        dv.setDataElementUuid( "ladida" );
+        dv.setDataElementIdentifier( "ladida" );
         dv.setValue( "11" );
         dataValueSet.getDataValues().add( dv );
 
@@ -386,7 +420,7 @@
             // Expected
         }
 
-        dv.setDataElementUuid( DATA_ELEMENT_NOT_IN_SET_UUID );
+        dv.setDataElementIdentifier( DATA_ELEMENT_NOT_IN_SET_UUID );
 
         try
         {
@@ -403,11 +437,11 @@
     public void optionComboExistsAndInDataElement()
     {
 
-        dataValueSet.getDataValues().get( 0 ).setCategoryOptionComboUuid( DEFAULT_COMBO_UUID );
+        dataValueSet.getDataValues().get( 0 ).setCategoryOptionComboIdentifier( DEFAULT_COMBO_UUID );
 
         service.saveDataValueSet( dataValueSet );
 
-        dataValueSet.getDataValues().get( 0 ).setCategoryOptionComboUuid( "AAB2299E-ECD6-46CF-A61F-817D350" );
+        dataValueSet.getDataValues().get( 0 ).setCategoryOptionComboIdentifier( "AAB2299E-ECD6-46CF-A61F-817D350" );
 
         try
         {
@@ -467,7 +501,6 @@
         assertEquals( DATA_ELEMENT_UUID, dv.getDataElement().getUuid() );
         assertEquals( ORGANISATION_UNIT_UUID, dv.getSource().getUuid() );
         assertEquals( new WeeklyPeriodType().createPeriod( "2011W5" ), dv.getPeriod() );
-        assertEquals( "misterindia", dv.getStoredBy() );
         assertEquals( value, dv.getValue() );
 
         long time = dv.getTimestamp().getTime();
@@ -475,6 +508,7 @@
         assertTrue( time <= after );
 
         assertEquals( defaultCombo, dv.getOptionCombo() );
+
     }
 
     @Override

=== modified file 'dhis-2/dhis-services/dhis-service-importexport/src/test/resources/dxf2/dataValueSet.xml'
--- dhis-2/dhis-services/dhis-service-importexport/src/test/resources/dxf2/dataValueSet.xml	2011-02-18 20:17:34 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/test/resources/dxf2/dataValueSet.xml	2011-09-02 09:16:34 +0000
@@ -2,8 +2,8 @@
 
 <dataValueSet xmlns="http://dhis2.org/schema/dxf/2.0-SNAPSHOT";
   dataSet="16B2299E-ECD6-46CF-A61F-817D350C180D" period="2011W5"
-  orgUnit="9C1B1B5E-3D65-48F2-8D1D-D36C60DD7344">
+  orgUnit="9C1B1B5E-3D65-48F2-8D1D-D36C60DD7344" >
 
- <dataValue dataElement="56B2299E-ECD6-46CF-A61F-817D350C180D" storedBy="misterindia" value="11" />
+ <dataValue dataElement="56B2299E-ECD6-46CF-A61F-817D350C180D" value="11" />
 
 </dataValueSet>