← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12980: allow properties.parent to be uuid in fred api

 

------------------------------------------------------------
revno: 12980
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2013-11-19 22:10:41 +0100
message:
  allow properties.parent to be uuid in fred api
modified:
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/FacilityToOrganisationUnitConverter.java
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/PropertiesValidator.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-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/FacilityToOrganisationUnitConverter.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/FacilityToOrganisationUnitConverter.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/FacilityToOrganisationUnitConverter.java	2013-11-19 21:10:41 +0000
@@ -106,7 +106,16 @@
 
         if ( facility.getProperties() != null )
         {
-            organisationUnit.setParent( organisationUnitService.getOrganisationUnit( (String) facility.getProperties().get( "parent" ) ) );
+            String parentId = (String) facility.getProperties().get( "parent" );
+
+            OrganisationUnit parent = organisationUnitService.getOrganisationUnit( parentId );
+
+            if ( parent == null )
+            {
+                parent = organisationUnitService.getOrganisationUnitByUuid( parentId );
+            }
+
+            organisationUnit.setParent( parent );
 
             Collection<String> dataSets = (Collection<String>) facility.getProperties().get( "dataSets" );
 

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/PropertiesValidator.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/PropertiesValidator.java	2013-08-23 16:05:01 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/PropertiesValidator.java	2013-11-19 21:10:41 +0000
@@ -31,6 +31,7 @@
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.dataset.DataSet;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
+import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.web.webapi.v1.validation.constraint.annotation.ValidProperties;
 import org.springframework.beans.factory.annotation.Autowired;
 
@@ -47,6 +48,9 @@
     @Autowired
     private IdentifiableObjectManager identifiableObjectManager;
 
+    @Autowired
+    private OrganisationUnitService organisationUnitService;
+
     @Override
     public void initialize( ValidProperties constraintAnnotation )
     {
@@ -90,20 +94,29 @@
     {
         String parentId = (String) values.get( "parent" );
 
-        if ( parentId != null )
-        {
-            OrganisationUnit organisationUnit = identifiableObjectManager.get( OrganisationUnit.class, parentId );
-
-            if ( organisationUnit == null )
-            {
-                return false;
-            }
-        }
-
-        return true;
+        if ( parentId == null )
+        {
+            return true;
+        }
+
+        OrganisationUnit organisationUnit = identifiableObjectManager.get( OrganisationUnit.class, parentId );
+
+        if ( organisationUnit != null )
+        {
+            return true;
+        }
+
+        organisationUnit = organisationUnitService.getOrganisationUnitByUuid( parentId );
+
+        if ( organisationUnit != null )
+        {
+            return true;
+        }
+
+        return false;
     }
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     private boolean validateDataSets( Map<String, Object> values )
     {
         Collection<String> dataSetIds = (Collection<String>) values.get( "dataSets" );