← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14793: allow using orgUnitIdScheme in dvs template generator

 

------------------------------------------------------------
revno: 14793
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-04-11 15:24:37 +0700
message:
  allow using orgUnitIdScheme in dvs template generator
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataSetController.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-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataSetController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataSetController.java	2014-04-11 06:58:24 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/DataSetController.java	2014-04-11 08:24:37 +0000
@@ -34,6 +34,7 @@
 import org.hisp.dhis.api.view.ClassPathUriResolver;
 import org.hisp.dhis.api.webdomain.form.Form;
 import org.hisp.dhis.common.DxfNamespaces;
+import org.hisp.dhis.common.IdentifiableObject;
 import org.hisp.dhis.common.view.ExportView;
 import org.hisp.dhis.dataelement.DataElement;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
@@ -211,7 +212,7 @@
             {
                 for ( DataElement dataElement : dataSet.getDataElements() )
                 {
-                    writeDataValue( dataElement, "", period, comment, staxWriter );
+                    writeDataValue( dataElement, dataElementIdScheme, null, orgUnitIdScheme, period, comment, staxWriter );
                 }
             }
             else
@@ -227,12 +228,20 @@
 
                     if ( comment )
                     {
-                        staxWriter.writeComment( "OrgUnit: " + organisationUnit.getDisplayName() + " (" + organisationUnit.getUid() + ")" );
+                        if ( IdentifiableObject.IdentifiableProperty.CODE.toString().toLowerCase().equals( orgUnitIdScheme.toLowerCase() ) )
+                        {
+                            staxWriter.writeComment( "OrgUnit: " + organisationUnit.getDisplayName() + " (" + organisationUnit.getCode() + ")" );
+                        }
+                        else
+                        {
+                            staxWriter.writeComment( "OrgUnit: " + organisationUnit.getDisplayName() + " (" + organisationUnit.getUid() + ")" );
+                        }
+
                     }
 
                     for ( DataElement dataElement : dataSet.getDataElements() )
                     {
-                        writeDataValue( dataElement, orgUnit, period, comment, staxWriter );
+                        writeDataValue( dataElement, dataElementIdScheme, organisationUnit, orgUnitIdScheme, period, comment, staxWriter );
                     }
                 }
             }
@@ -246,7 +255,7 @@
         }
     }
 
-    private void writeDataValue( DataElement dataElement, String orgUnit, String period, boolean comment, XMLStreamWriter staxWriter ) throws XMLStreamException
+    private void writeDataValue( DataElement dataElement, String deScheme, OrganisationUnit organisationUnit, String ouScheme, String period, boolean comment, XMLStreamWriter staxWriter ) throws XMLStreamException
     {
         for ( DataElementCategoryOptionCombo categoryOptionCombo : dataElement.getCategoryCombo().getSortedOptionCombos() )
         {
@@ -263,10 +272,28 @@
             }
 
             staxWriter.writeStartElement( "", "dataValue", DxfNamespaces.DXF_2_0 );
-            staxWriter.writeAttribute( "dataElement", dataElement.getUid() );
+
+            if ( IdentifiableObject.IdentifiableProperty.CODE.toString().toLowerCase().equals( deScheme.toLowerCase() ) )
+            {
+                staxWriter.writeAttribute( "dataElement", dataElement.getCode() );
+            }
+            else
+            {
+                staxWriter.writeAttribute( "dataElement", dataElement.getUid() );
+            }
+
             staxWriter.writeAttribute( "categoryOptionCombo", categoryOptionCombo.getUid() );
             staxWriter.writeAttribute( "period", period );
-            staxWriter.writeAttribute( "orgUnit", orgUnit );
+
+            if ( IdentifiableObject.IdentifiableProperty.CODE.toString().toLowerCase().equals( ouScheme.toLowerCase() ) )
+            {
+                staxWriter.writeAttribute( "orgUnit", organisationUnit.getCode() == null ? "" : organisationUnit.getCode() );
+            }
+            else
+            {
+                staxWriter.writeAttribute( "orgUnit", organisationUnit.getUid() == null ? "" : organisationUnit.getUid() );
+            }
+
             staxWriter.writeAttribute( "value", "" );
             staxWriter.writeEndElement();
         }