← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 4519: Minor modifications to DataValueSet. Set UUID id strategy as default.

 

------------------------------------------------------------
revno: 4519
committer: Bob Jolliffe bobjolliffe@xxxxxxxxx
branch nick: dhis2
timestamp: Mon 2011-09-05 12:56:56 +0100
message:
  Minor modifications to DataValueSet.  Set UUID id strategy as default.
  DataValueSetService currently only supports UUID strategy.
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


--
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-09-02 09:16:34 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValue.java	2011-09-05 11:56:56 +0000
@@ -42,15 +42,27 @@
     @XmlAttribute( name = "dataElement", required = true )
     private String dataElementIdentifier;
 
+    @XmlAttribute( name = "value", required = true)
+    private String value;
+
+    /**
+     * optional - defaults to default
+     */
     @XmlAttribute( name = "categoryOptionCombo" )
     private String categoryOptionComboIdentifier;
 
+    /**
+     * optional - defaults to orgUnit id from datavalueset
+     */
+    @XmlAttribute( name = "orgUnit" )
+    private String orgUnitIdentifier;
+
+    /**
+     * Arbitrary attributes identifying dimensions by concept name
+     */
     @XmlAnyAttribute
     Map<QName,Object> dimensions;
 
-    @XmlAttribute
-    private String value;
-
     public String getDataElementIdentifier()
     {
         return dataElementIdentifier;

=== 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-09-02 09:16:34 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/model/DataValueSet.java	2011-09-05 11:56:56 +0000
@@ -39,11 +39,17 @@
 @XmlAccessorType( XmlAccessType.FIELD )
 public class DataValueSet
 {
+    public enum IdentificationStrategy { INTERNAL, UUID, CODE  };
+
+    /**
+     *  A default strategy to use.
+     */
+    public static final IdentificationStrategy DEFAULT_STRATEGY = IdentificationStrategy.UUID;
 
     @XmlAttribute( name = "dataSet" )
     private String dataSetIdentifier;
 
-    @XmlAttribute( name = "orgUnit", required = true )
+    @XmlAttribute( name = "orgUnit" )
     private String organisationUnitIdentifier;
 
     @XmlAttribute( name = "period", required = true )
@@ -52,35 +58,22 @@
     @XmlAttribute( name = "complete" )
     private String completeDate;
 
-    @XmlAttribute( name = "orgUnitIdScheme" )
-    private String orgUnitIdScheme;
-
-    @XmlAttribute( name = "dataElementIdScheme" )
-    private String dataElementIdScheme;
+    @XmlAttribute( name = "idScheme" )
+    private IdentificationStrategy idScheme;
 
     @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 IdentificationStrategy getIdScheme()
+    {
+        return (idScheme != null) ? idScheme : DEFAULT_STRATEGY;
+    }
+
+    public void setIdScheme( IdentificationStrategy idScheme )
+    {
+        this.idScheme = idScheme;
+    }
+
     public String getDataSetIdentifier()
     {
         return dataSetIdentifier;

=== 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-09-02 09:16:34 +0000
+++ dhis-2/dhis-services/dhis-service-importexport/src/main/java/org/hisp/dhis/importexport/dxf2/service/DataValueSetService.java	2011-09-05 11:56:56 +0000
@@ -44,6 +44,7 @@
 import org.hisp.dhis.datavalue.DataValue;
 import org.hisp.dhis.datavalue.DataValueService;
 import org.hisp.dhis.importexport.dxf2.model.DataValueSet;
+import org.hisp.dhis.importexport.dxf2.model.DataValueSet.IdentificationStrategy;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.period.DailyPeriodType;
@@ -122,9 +123,14 @@
 
         Date timestamp = new Date();
 
+        IdentificationStrategy idStrategy = dataValueSet.getIdScheme();
+        if (idStrategy != DataValueSet.DEFAULT_STRATEGY) {
+            throw new IllegalArgumentException( "Onlu UUID id strategy supported currently." );
+        }
+
         DataSet dataSet = getDataSet( dataValueSet );
 
-        OrganisationUnit unit = getOrgUnit( dataValueSet.getOrganisationUnitIdentifier() );
+        OrganisationUnit unit = getOrgUnit( dataValueSet.getOrganisationUnitIdentifier());
 
         if ( !dataSet.getSources().contains( unit ) )
         {
@@ -318,24 +324,24 @@
         return period;
     }
 
-    private OrganisationUnit getOrgUnit( String uuid )
+    private OrganisationUnit getOrgUnit( String id)
     {
-        OrganisationUnit unit = organisationUnitService.getOrganisationUnit( uuid );
+        OrganisationUnit unit = organisationUnitService.getOrganisationUnit( id );
 
         if ( unit == null )
         {
-            throw new IllegalArgumentException( "Org unit with UUID " + uuid + " does not exist" );
+            throw new IllegalArgumentException( "Org unit with UUID " + id + " does not exist" );
         }
         return unit;
     }
 
-    private DataElement getDataElement( String uuid )
+    private DataElement getDataElement( String id )
     {
-        DataElement dataElement = dataElementService.getDataElement( uuid );
+        DataElement dataElement = dataElementService.getDataElement( id );
 
         if ( dataElement == null )
         {
-            throw new IllegalArgumentException( "Data element with UUID " + uuid + " does not exist" );
+            throw new IllegalArgumentException( "Data element with UUID " + id + " does not exist" );
         }
 
         return dataElement;