← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 9268: FRED-API: added proper validation for id, name, code

 

------------------------------------------------------------
revno: 9268
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2012-12-11 16:34:09 +0300
message:
  FRED-API: added proper validation for id, name, code
removed:
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/IdentifiersValidator.java
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/UidReferenceValidator.java
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/annotation/ValidIdentifiers.java
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/annotation/ValidUidReference.java
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/controller/FacilityServiceController.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/MessageResponseUtils.java
  dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ValidationUtils.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/FacilityController.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2012-12-11 10:59:00 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityController.java	2012-12-11 13:34:09 +0000
@@ -218,12 +218,21 @@
 
         if ( constraintViolations.isEmpty() )
         {
-            if ( organisationUnitService.getOrganisationUnit( facility.getId() ) != null )
+            OrganisationUnit organisationUnit = conversionService.convert( facility, OrganisationUnit.class );
+
+            if ( organisationUnitService.getOrganisationUnit( organisationUnit.getUid() ) != null )
             {
                 return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "An object with that ID already exists." ), headers, HttpStatus.CONFLICT );
             }
+            else if ( organisationUnitService.getOrganisationUnitByName( organisationUnit.getName() ) != null )
+            {
+                return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "An object with that name already exists." ), headers, HttpStatus.CONFLICT );
+            }
+            else if ( organisationUnit.getCode() != null && organisationUnitService.getOrganisationUnitByCode( organisationUnit.getCode() ) != null )
+            {
+                return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "An object with that code already exists." ), headers, HttpStatus.CONFLICT );
+            }
 
-            OrganisationUnit organisationUnit = conversionService.convert( facility, OrganisationUnit.class );
             organisationUnitService.addOrganisationUnit( organisationUnit );
 
             for ( DataSet dataSet : organisationUnit.getDataSets() )
@@ -264,8 +273,35 @@
         {
             OrganisationUnit ou = organisationUnitService.getOrganisationUnit( facility.getId() );
 
+            if ( ou == null )
+            {
+                return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "No object with that identifier exists." ),
+                    headers, HttpStatus.NOT_FOUND );
+            }
+            else if ( !ou.getName().equals( organisationUnit.getName() ) )
+            {
+                OrganisationUnit ouByName = organisationUnitService.getOrganisationUnitByName( organisationUnit.getName() );
+
+                if ( ouByName != null && !ou.getUid().equals( ouByName.getUid() ) )
+                {
+                    return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "Another object with the same name already exists." ),
+                        headers, HttpStatus.CONFLICT );
+                }
+            }
+            else if ( organisationUnit.getCode() != null )
+            {
+                OrganisationUnit ouByCode = organisationUnitService.getOrganisationUnitByCode( organisationUnit.getCode() );
+
+                if ( ouByCode != null && !ou.getUid().equals( ouByCode.getUid() ) )
+                {
+                    return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "Another object with the same code already exists." ),
+                        headers, HttpStatus.CONFLICT );
+                }
+            }
+
             ou.setName( organisationUnit.getName() );
             ou.setShortName( organisationUnit.getShortName() );
+            ou.setCode( organisationUnit.getCode() );
 
             ou.setFeatureType( organisationUnit.getFeatureType() );
             ou.setCoordinates( organisationUnit.getCoordinates() );

=== 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-10 13:53:34 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/controller/FacilityServiceController.java	2012-12-11 13:34:09 +0000
@@ -30,10 +30,13 @@
 import org.hisp.dhis.organisationunit.OrganisationUnit;
 import org.hisp.dhis.organisationunit.OrganisationUnitService;
 import org.hisp.dhis.web.webapi.v1.domain.Facility;
+import org.hisp.dhis.web.webapi.v1.utils.MessageResponseUtils;
 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.springframework.beans.factory.annotation.Autowired;
+import org.springframework.core.convert.ConversionService;
+import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
 import org.springframework.http.ResponseEntity;
@@ -53,7 +56,7 @@
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
-@Controller( value = "facility-service-controller-" + FredController.PREFIX )
+@Controller(value = "facility-service-controller-" + FredController.PREFIX)
 @RequestMapping(FacilityServiceController.RESOURCE_PATH)
 @PreAuthorize("hasRole('M_dhis-web-api-fred') or hasRole('ALL')")
 public class FacilityServiceController
@@ -66,11 +69,14 @@
     @Autowired
     private Validator validator;
 
+    @Autowired
+    private ConversionService conversionService;
+
     //--------------------------------------------------------------------------
     // EXTRA WEB METHODS
     //--------------------------------------------------------------------------
 
-    @RequestMapping( value = "/{id}/activate", method = RequestMethod.POST )
+    @RequestMapping(value = "/{id}/activate", method = RequestMethod.POST)
     @PreAuthorize("hasRole('F_FRED_UPDATE') or hasRole('ALL')")
     public ResponseEntity<Void> activateFacility( @PathVariable String id )
     {
@@ -87,7 +93,7 @@
         return new ResponseEntity<Void>( HttpStatus.NOT_FOUND );
     }
 
-    @RequestMapping( value = "/{id}/deactivate", method = RequestMethod.POST )
+    @RequestMapping(value = "/{id}/deactivate", method = RequestMethod.POST)
     @PreAuthorize("hasRole('F_FRED_UPDATE') or hasRole('ALL')")
     public ResponseEntity<Void> deactivateFacility( @PathVariable String id )
     {
@@ -111,13 +117,31 @@
 
         String json = ValidationUtils.constraintViolationsToJson( constraintViolations );
 
+        HttpHeaders headers = new HttpHeaders();
+        headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
+
         if ( constraintViolations.isEmpty() )
         {
-            return new ResponseEntity<String>( json, HttpStatus.OK );
+            OrganisationUnit organisationUnit = conversionService.convert( facility, OrganisationUnit.class );
+
+            if ( organisationUnitService.getOrganisationUnit( organisationUnit.getUid() ) != null )
+            {
+                return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "An object with that ID already exists." ), headers, HttpStatus.CONFLICT );
+            }
+            else if ( organisationUnitService.getOrganisationUnitByName( organisationUnit.getName() ) != null )
+            {
+                return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "An object with that name already exists." ), headers, HttpStatus.CONFLICT );
+            }
+            else if ( organisationUnit.getCode() != null && organisationUnitService.getOrganisationUnitByCode( organisationUnit.getCode() ) != null )
+            {
+                return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "An object with that code already exists." ), headers, HttpStatus.CONFLICT );
+            }
+
+            return new ResponseEntity<String>( json, headers, HttpStatus.OK );
         }
         else
         {
-            return new ResponseEntity<String>( json, HttpStatus.UNPROCESSABLE_ENTITY );
+            return new ResponseEntity<String>( json, headers, HttpStatus.UNPROCESSABLE_ENTITY );
         }
     }
 
@@ -128,13 +152,45 @@
 
         String json = ValidationUtils.constraintViolationsToJson( constraintViolations );
 
+        HttpHeaders headers = new HttpHeaders();
+        headers.add( "Content-Type", MediaType.APPLICATION_JSON_VALUE );
+
         if ( constraintViolations.isEmpty() )
         {
-            return new ResponseEntity<String>( json, HttpStatus.OK );
+            OrganisationUnit organisationUnit = conversionService.convert( facility, OrganisationUnit.class );
+            OrganisationUnit ou = organisationUnitService.getOrganisationUnit( facility.getId() );
+
+            if ( ou == null )
+            {
+                return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "No object with that identifier exists." ),
+                    headers, HttpStatus.NOT_FOUND );
+            }
+            else if ( !ou.getName().equals( organisationUnit.getName() ) )
+            {
+                OrganisationUnit ouByName = organisationUnitService.getOrganisationUnitByName( organisationUnit.getName() );
+
+                if ( ouByName != null && !ou.getUid().equals( ouByName.getUid() ) )
+                {
+                    return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "Another object with the same name already exists." ),
+                        headers, HttpStatus.CONFLICT );
+                }
+            }
+            else if ( organisationUnit.getCode() != null )
+            {
+                OrganisationUnit ouByCode = organisationUnitService.getOrganisationUnitByCode( organisationUnit.getCode() );
+
+                if ( ouByCode != null && !ou.getUid().equals( ouByCode.getUid() ) )
+                {
+                    return new ResponseEntity<String>( MessageResponseUtils.jsonMessage( "Another object with the same code already exists." ),
+                        headers, HttpStatus.CONFLICT );
+                }
+            }
+
+            return new ResponseEntity<String>( json, headers, HttpStatus.OK );
         }
         else
         {
-            return new ResponseEntity<String>( json, HttpStatus.UNPROCESSABLE_ENTITY );
+            return new ResponseEntity<String>( json, headers, HttpStatus.UNPROCESSABLE_ENTITY );
         }
     }
 }

=== 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 10:59:00 +0000
+++ 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
@@ -28,7 +28,6 @@
  */
 
 import org.hibernate.validator.constraints.Length;
-import org.hisp.dhis.web.webapi.v1.validation.constraint.annotation.ValidIdentifiers;
 import org.hisp.dhis.web.webapi.v1.validation.constraint.annotation.ValidProperties;
 import org.hisp.dhis.web.webapi.v1.validation.group.Create;
 import org.hisp.dhis.web.webapi.v1.validation.group.Update;
@@ -43,14 +42,14 @@
 public class Facility
 {
     // Internal system identifier
-    @NotNull( groups = Create.class )
-    @Null( groups = Update.class )
-    @Length( min = 11, max = 11 )
+    @Null( groups = Create.class )
+    @NotNull( groups = Update.class )
+    @Length(min = 11, max = 11)
     private String id;
 
     // Name of the facility
     @NotNull
-    @Length( min = 2, max = 160 )
+    @Length(min = 2, max = 160)
     private String name;
 
     // Active = true/false indicates whether the facility is active or not
@@ -58,15 +57,12 @@
     private Boolean active;
 
     // URL link to the unique ID API resource for the facility
-    @Null
     private String url;
 
     // ISO 8601 timestamp, including timezone, of when the facility was created
-    @Null
     private Date createdAt;
 
     // ISO 8601 timestamp, including timezone, of when the facility was last updated
-    @Null
     private Date updatedAt;
 
     // Geo-location represented by latitude and longitude coordinates in that order
@@ -74,7 +70,6 @@
     private List<Double> coordinates = new ArrayList<Double>();
 
     // External Facility Identifiers
-    @ValidIdentifiers( groups = Create.class )
     private List<Identifier> identifiers = new ArrayList<Identifier>();
 
     // Implementation specific custom properties

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/MessageResponseUtils.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/MessageResponseUtils.java	2012-12-11 10:59:00 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/MessageResponseUtils.java	2012-12-11 13:34:09 +0000
@@ -45,7 +45,7 @@
     {
         objectMapper = new ObjectMapper();
         objectMapper.configure( JsonGenerator.Feature.ESCAPE_NON_ASCII, true );
-        objectMapper.setSerializationInclusion( JsonSerialize.Inclusion.NON_NULL );
+        objectMapper.setSerializationInclusion( JsonSerialize.Inclusion.NON_EMPTY );
     }
 
     public static String jsonMessage( String message ) throws IOException

=== modified file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ValidationUtils.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/utils/ValidationUtils.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/utils/ValidationUtils.java	2012-12-11 13:34:09 +0000
@@ -27,7 +27,9 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import org.codehaus.jackson.JsonGenerator;
 import org.codehaus.jackson.map.ObjectMapper;
+import org.codehaus.jackson.map.annotate.JsonSerialize;
 
 import javax.validation.ConstraintViolation;
 import java.io.IOException;
@@ -40,6 +42,15 @@
  */
 public class ValidationUtils
 {
+    private static ObjectMapper objectMapper;
+
+    static
+    {
+        objectMapper = new ObjectMapper();
+        objectMapper.configure( JsonGenerator.Feature.ESCAPE_NON_ASCII, true );
+        objectMapper.setSerializationInclusion( JsonSerialize.Inclusion.NON_EMPTY );
+    }
+
     public static <T> String constraintViolationsToJson( Set<ConstraintViolation<T>> constraintViolations ) throws IOException
     {
         Map<String, String> constraintViolationsMap = new HashMap<String, String>();
@@ -49,6 +60,6 @@
             constraintViolationsMap.put( constraintViolation.getPropertyPath().toString(), constraintViolation.getMessage() );
         }
 
-        return new ObjectMapper().writeValueAsString( constraintViolationsMap );
+        return objectMapper.writeValueAsString( constraintViolationsMap );
     }
 }

=== removed file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/IdentifiersValidator.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/IdentifiersValidator.java	2012-12-10 12:34:13 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/IdentifiersValidator.java	1970-01-01 00:00:00 +0000
@@ -1,111 +0,0 @@
-package org.hisp.dhis.web.webapi.v1.validation.constraint;
-
-/*
- * 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 org.hisp.dhis.common.IdentifiableObjectManager;
-import org.hisp.dhis.organisationunit.OrganisationUnit;
-import org.hisp.dhis.web.webapi.v1.domain.Identifier;
-import org.hisp.dhis.web.webapi.v1.validation.constraint.annotation.ValidIdentifiers;
-import org.hisp.dhis.web.webapi.v1.validation.group.Create;
-import org.hisp.dhis.web.webapi.v1.validation.group.Update;
-import org.springframework.beans.factory.annotation.Autowired;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-import java.util.Arrays;
-import java.util.List;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class IdentifiersValidator implements ConstraintValidator<ValidIdentifiers, List<Identifier>>
-{
-    @Autowired
-    private IdentifiableObjectManager identifiableObjectManager;
-
-    private boolean isCreating = true;
-
-    @Override
-    public void initialize( ValidIdentifiers constraintAnnotation )
-    {
-        List<Class<?>> groups = Arrays.asList( constraintAnnotation.groups() );
-
-        if ( groups.contains( Create.class ) )
-        {
-            isCreating = true;
-        }
-        else if ( groups.contains( Update.class ) )
-        {
-            isCreating = false;
-        }
-    }
-
-    @Override
-    public boolean isValid( List<Identifier> value, ConstraintValidatorContext context )
-    {
-        boolean returnValue = true;
-
-        for ( Identifier identifier : value )
-        {
-            // only dhis2 codes are supported by this validator for now
-            if ( identifier.getAgency().equalsIgnoreCase( Identifier.DHIS2_AGENCY )
-                && identifier.getContext().equalsIgnoreCase( Identifier.DHIS2_CODE_CONTEXT ) )
-            {
-                OrganisationUnit organisationUnit = identifiableObjectManager.getByCode( OrganisationUnit.class, identifier.getId() );
-
-                if ( organisationUnit != null )
-                {
-                    if ( isCreating )
-                    {
-                        context.disableDefaultConstraintViolation();
-                        context.buildConstraintViolationWithTemplate( "An object already exists with that identifier." )
-                            .addNode( identifier.getContext() )
-                            .addConstraintViolation();
-
-                        returnValue = false;
-                    }
-                }
-                else
-                {
-                    // TODO for this to work properly, we would need to have access to the current object being validated.
-                    /*
-                    if ( !isCreating )
-                    {
-                        context.disableDefaultConstraintViolation();
-                        context.buildConstraintViolationWithTemplate( "An object already exists with that identifier." )
-                            .addNode( identifier.getContext() )
-                            .addConstraintViolation();
-                    }
-                    */
-                }
-            }
-        }
-
-        return returnValue;
-    }
-}

=== removed file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/UidReferenceValidator.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/UidReferenceValidator.java	2012-12-09 19:49:26 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/UidReferenceValidator.java	1970-01-01 00:00:00 +0000
@@ -1,72 +0,0 @@
-package org.hisp.dhis.web.webapi.v1.validation.constraint;
-
-/*
- * 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 org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.common.IdentifiableObjectManager;
-import org.hisp.dhis.web.webapi.v1.validation.constraint.annotation.ValidUidReference;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.beans.factory.annotation.Qualifier;
-
-import javax.validation.ConstraintValidator;
-import javax.validation.ConstraintValidatorContext;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-public class UidReferenceValidator implements ConstraintValidator<ValidUidReference, String>
-{
-    @Autowired
-    @Qualifier( "org.hisp.dhis.common.IdentifiableObjectManager" )
-    private IdentifiableObjectManager identifiableObjectManager;
-
-    private Class<? extends IdentifiableObject> identifiableObjectClass;
-
-    @Override
-    public void initialize( ValidUidReference constraintAnnotation )
-    {
-        identifiableObjectClass = constraintAnnotation.value();
-    }
-
-    @Override
-    public boolean isValid( String value, ConstraintValidatorContext context )
-    {
-        IdentifiableObject identifiableObject = identifiableObjectManager.get( identifiableObjectClass, value );
-
-        boolean isValid = identifiableObject != null;
-
-        if ( !isValid )
-        {
-            context.disableDefaultConstraintViolation();
-            context.buildConstraintViolationWithTemplate( String.format( "No object found with ID %s.", value ) )
-                .addConstraintViolation();
-        }
-
-        return isValid;
-    }
-}

=== removed file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/annotation/ValidIdentifiers.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/annotation/ValidIdentifiers.java	2012-12-10 12:38:04 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/annotation/ValidIdentifiers.java	1970-01-01 00:00:00 +0000
@@ -1,59 +0,0 @@
-package org.hisp.dhis.web.webapi.v1.validation.constraint.annotation;
-
-/*
- * 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 org.hisp.dhis.web.webapi.v1.validation.constraint.IdentifiersValidator;
-
-import javax.validation.Constraint;
-import javax.validation.Payload;
-import java.lang.annotation.*;
-
-import static java.lang.annotation.RetentionPolicy.RUNTIME;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@Target( { ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE } )
-@Retention( RetentionPolicy.RUNTIME )
-@Constraint( validatedBy = IdentifiersValidator.class )
-public @interface ValidIdentifiers
-{
-    String message() default "Identifiers did not validate.";
-
-    Class<?>[] groups() default { };
-
-    Class<? extends Payload>[] payload() default { };
-
-    @Target( { ElementType.TYPE, ElementType.METHOD, ElementType.FIELD } )
-    @Retention( RUNTIME )
-    @Documented
-    public @interface List
-    {
-        ValidIdentifiers[] value();
-    }
-}

=== removed file 'dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/annotation/ValidUidReference.java'
--- dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/annotation/ValidUidReference.java	2012-12-09 19:49:26 +0000
+++ dhis-2/dhis-web/dhis-web-api-fred/src/main/java/org/hisp/dhis/web/webapi/v1/validation/constraint/annotation/ValidUidReference.java	1970-01-01 00:00:00 +0000
@@ -1,55 +0,0 @@
-package org.hisp.dhis.web.webapi.v1.validation.constraint.annotation;
-
-/*
- * 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 org.hisp.dhis.common.IdentifiableObject;
-import org.hisp.dhis.web.webapi.v1.validation.constraint.UidReferenceValidator;
-
-import javax.validation.Constraint;
-import javax.validation.Payload;
-import java.lang.annotation.ElementType;
-import java.lang.annotation.Retention;
-import java.lang.annotation.RetentionPolicy;
-import java.lang.annotation.Target;
-
-/**
- * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
- */
-@Target({ ElementType.METHOD, ElementType.FIELD, ElementType.ANNOTATION_TYPE })
-@Retention(RetentionPolicy.RUNTIME)
-@Constraint(validatedBy = UidReferenceValidator.class)
-public @interface ValidUidReference
-{
-    String message() default "No object found with that ID.";
-
-    Class<?>[] groups() default { };
-
-    Class<? extends Payload>[] payload() default { };
-
-    Class<? extends IdentifiableObject> value();
-}