← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9669: FRED-API: fixed validation for PUT logic. updated to spring-hateoas 0.4.0.

 

------------------------------------------------------------
revno: 9669
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-01-31 10:22:50 +0700
message:
  FRED-API: fixed validation for PUT logic. updated to spring-hateoas 0.4.0.
modified:
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/domain/Facility.java
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/FacilityToOrganisationUnitConverter.java
  dhis-2/pom.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-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2013-01-31 02:31:35 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2013-01-31 03:22:50 +0000
@@ -449,8 +449,6 @@
     public ResponseEntity<String> updateFacility( @PathVariable String id, @RequestBody Facility facility ) throws IOException
     {
         facility.setId( id );
-        OrganisationUnit organisationUnit = conversionService.convert( facility, OrganisationUnit.class );
-
         Set<ConstraintViolation<Facility>> constraintViolations = validator.validate( facility, Default.class, Update.class );
 
         String json = ValidationUtils.constraintViolationsToJson( constraintViolations );
@@ -460,6 +458,7 @@
 
         if ( constraintViolations.isEmpty() )
         {
+            OrganisationUnit organisationUnit = conversionService.convert( facility, OrganisationUnit.class );
             OrganisationUnit ou = organisationUnitService.getOrganisationUnit( facility.getId() );
 
             if ( ou == null )

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/domain/Facility.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/domain/Facility.java	2012-12-11 13:34:09 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/domain/Facility.java	2013-01-31 03:22:50 +0000
@@ -34,7 +34,11 @@
 
 import javax.validation.constraints.NotNull;
 import javax.validation.constraints.Null;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
 
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
@@ -42,8 +46,8 @@
 public class Facility
 {
     // Internal system identifier
-    @Null( groups = Create.class )
-    @NotNull( groups = Update.class )
+    @Null(groups = Create.class)
+    @NotNull(groups = Update.class)
     @Length(min = 11, max = 11)
     private String id;
 

=== 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	2012-12-13 17:04:35 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/FacilityToOrganisationUnitConverter.java	2013-01-31 03:22:50 +0000
@@ -47,11 +47,11 @@
 public class FacilityToOrganisationUnitConverter implements Converter<Facility, OrganisationUnit>
 {
     @Autowired
-    @Qualifier( "org.hisp.dhis.organisationunit.OrganisationUnitService" )
+    @Qualifier("org.hisp.dhis.organisationunit.OrganisationUnitService")
     private OrganisationUnitService organisationUnitService;
 
     @Autowired
-    @Qualifier( "org.hisp.dhis.dataset.DataSetService" )
+    @Qualifier("org.hisp.dhis.dataset.DataSetService")
     private DataSetService dataSetService;
 
     @Override
@@ -62,7 +62,7 @@
         organisationUnit.setUid( facility.getId() );
         organisationUnit.setName( facility.getName() );
 
-        if ( facility.getName().length() > 49 )
+        if ( facility.getName() != null && facility.getName().length() > 49 )
         {
             organisationUnit.setShortName( facility.getName().substring( 0, 49 ) );
         }
@@ -72,18 +72,6 @@
         }
 
         organisationUnit.setActive( facility.getActive() );
-        organisationUnit.setParent( organisationUnitService.getOrganisationUnit( (String) facility.getProperties().get( "parent" ) ) );
-
-        Collection<String> dataSets = (Collection<String>) facility.getProperties().get( "dataSets" );
-
-        if ( dataSets != null )
-        {
-            for ( String uid : dataSets )
-            {
-                DataSet dataSet = dataSetService.getDataSet( uid );
-                organisationUnit.getDataSets().add( dataSet );
-            }
-        }
 
         if ( facility.getIdentifiers() != null )
         {
@@ -107,7 +95,23 @@
         }
         catch ( NumberFormatException err )
         {
-            organisationUnit.setCoordinates( "" );
+            organisationUnit.setCoordinates( null );
+        }
+
+        if ( facility.getProperties() != null )
+        {
+            organisationUnit.setParent( organisationUnitService.getOrganisationUnit( (String) facility.getProperties().get( "parent" ) ) );
+
+            Collection<String> dataSets = (Collection<String>) facility.getProperties().get( "dataSets" );
+
+            if ( dataSets != null )
+            {
+                for ( String uid : dataSets )
+                {
+                    DataSet dataSet = dataSetService.getDataSet( uid );
+                    organisationUnit.getDataSets().add( dataSet );
+                }
+            }
         }
 
         return organisationUnit;

=== modified file 'dhis-2/pom.xml'
--- dhis-2/pom.xml	2012-12-18 17:12:07 +0000
+++ dhis-2/pom.xml	2013-01-31 03:22:50 +0000
@@ -394,7 +394,7 @@
       <dependency>
         <groupId>org.springframework.hateoas</groupId>
         <artifactId>spring-hateoas</artifactId>
-        <version>0.3.0.RELEASE</version>
+        <version>0.4.0.RELEASE</version>
       </dependency>
       <dependency>
         <groupId>cglib</groupId>