← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9221: FRED-API: properly sequenced validations (do not talk to db unless its needed)

 

------------------------------------------------------------
revno: 9221
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2012-12-08 13:15:52 +0300
message:
  FRED-API: properly sequenced validations (do not talk to db unless its needed)
added:
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/group/CreateSequence.java
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/group/Standard.java
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/group/UpdateSequence.java
modified:
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityServiceController.java
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/domain/Facility.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/controller/FacilityServiceController.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityServiceController.java	2012-12-08 08:31:02 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityServiceController.java	2012-12-08 10:15:52 +0000
@@ -31,8 +31,8 @@
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.web.webapi.v1.domain.Facility;
 import org.hisp.dhis.web.webapi.v1.utils.ValidationUtils;
-import org.hisp.dhis.web.webapi.v1.validation.group.Create;
-import org.hisp.dhis.web.webapi.v1.validation.group.Update;
+import org.hisp.dhis.web.webapi.v1.validation.group.CreateSequence;
+import org.hisp.dhis.web.webapi.v1.validation.group.UpdateSequence;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.http.HttpStatus;
@@ -104,7 +104,7 @@
     @RequestMapping( value = "/validate", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE )
     public ResponseEntity<String> validateFacilityForCreate( @RequestBody Facility facility ) throws IOException
     {
-        Set<ConstraintViolation<Facility>> constraintViolations = validator.validate( facility, Create.class );
+        Set<ConstraintViolation<Facility>> constraintViolations = validator.validate( facility, CreateSequence.class );
 
         String json = ValidationUtils.constraintViolationsToJson( constraintViolations );
 
@@ -121,7 +121,7 @@
     @RequestMapping( value = "/validate", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE )
     public ResponseEntity<String> validateFacilityForUpdate( @RequestBody Facility facility ) throws IOException
     {
-        Set<ConstraintViolation<Facility>> constraintViolations = validator.validate( facility, Update.class );
+        Set<ConstraintViolation<Facility>> constraintViolations = validator.validate( facility, UpdateSequence.class );
 
         String json = ValidationUtils.constraintViolationsToJson( constraintViolations );
 

=== 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-08 08:34:07 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/domain/Facility.java	2012-12-08 10:15:52 +0000
@@ -30,7 +30,7 @@
 import org.hibernate.validator.constraints.Length;
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.web.webapi.v1.validation.constraint.annotation.IdentifiableObjectExists;
-import org.hisp.dhis.web.webapi.v1.validation.group.Create;
+import org.hisp.dhis.web.webapi.v1.validation.group.Standard;
 import org.hisp.dhis.web.webapi.v1.validation.group.Update;
 
 import javax.validation.constraints.NotNull;
@@ -43,34 +43,34 @@
 public class Facility
 {
     // Internal system identifier
-    @Length( min = 11, max = 11, groups = { Create.class, Update.class } )
-    @NotNull( groups = Update.class )
-    @Null( groups = Create.class )
+    @Length( min = 11, max = 11, groups = Standard.Length.class )
+    @NotNull( groups = Standard.NotNull.class )
+    @Null( groups = Standard.Null.class )
     @IdentifiableObjectExists( value = OrganisationUnit.class, groups = Update.class )
     private String id;
 
     // Name of the facility
-    @Length( min = 2, max = 160, groups = { Create.class, Update.class } )
-    @NotNull( groups = { Create.class, Update.class } )
+    @Length( min = 2, max = 160 )
+    @NotNull
     private String name;
 
     // Active = true/false indicates whether the facility is active or not
-    @NotNull( groups = { Create.class, Update.class } )
+    @NotNull
     private Boolean active;
 
     // URL link to the unique ID API resource for the facility
     private String url;
 
     // ISO 8601 timestamp, including timezone, of when the facility was created
-    @Null( groups = { Create.class, Update.class } )
+    @Null
     private Date createdAt;
 
     // ISO 8601 timestamp, including timezone, of when the facility was last updated
-    @Null( groups = { Create.class, Update.class } )
+    @Null
     private Date updatedAt;
 
     // Geo-location represented by latitude and longitude coordinates in that order
-    @NotNull( groups = { Create.class, Update.class } )
+    @NotNull
     private List<Double> coordinates = new ArrayList<Double>();
 
     // External Facility Identifiers

=== added file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/group/CreateSequence.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/group/CreateSequence.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/group/CreateSequence.java	2012-12-08 10:15:52 +0000
@@ -0,0 +1,39 @@
+package org.hisp.dhis.web.webapi.v1.validation.group;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import javax.validation.GroupSequence;
+import javax.validation.groups.Default;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@GroupSequence( { Standard.Null.class, Default.class } )
+public interface CreateSequence
+{
+}

=== added file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/group/Standard.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/group/Standard.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/group/Standard.java	2012-12-08 10:15:52 +0000
@@ -0,0 +1,27 @@
+package org.hisp.dhis.web.webapi.v1.validation.group;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+public class Standard
+{
+    public interface Length
+    {
+
+    }
+
+    public interface NotNull
+    {
+
+    }
+
+    public interface Null
+    {
+
+    }
+
+    public interface Size
+    {
+
+    }
+}

=== added file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/group/UpdateSequence.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/group/UpdateSequence.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/group/UpdateSequence.java	2012-12-08 10:15:52 +0000
@@ -0,0 +1,39 @@
+package org.hisp.dhis.web.webapi.v1.validation.group;
+
+/*
+ * Copyright (c) 2004-2012, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * * Redistributions of source code must retain the above copyright notice, this
+ *   list of conditions and the following disclaimer.
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ *   this list of conditions and the following disclaimer in the documentation
+ *   and/or other materials provided with the distribution.
+ * * Neither the name of the HISP project nor the names of its contributors may
+ *   be used to endorse or promote products derived from this software without
+ *   specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import javax.validation.GroupSequence;
+import javax.validation.groups.Default;
+
+/**
+ * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
+ */
+@GroupSequence( { Standard.NotNull.class, Standard.Length.class, Update.class, Default.class } )
+public interface UpdateSequence
+{
+}