← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 14982: jsr-303 support, wip (not enabled yet)

 

------------------------------------------------------------
revno: 14982
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2014-04-25 16:29:39 +0545
message:
  jsr-303 support, wip (not enabled yet)
modified:
  dhis-2/dhis-api/pom.xml
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalStoreTest.java
  dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryServiceTest.java
  dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/CrudControllerAdvice.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-api/pom.xml'
--- dhis-2/dhis-api/pom.xml	2014-04-24 15:46:24 +0000
+++ dhis-2/dhis-api/pom.xml	2014-04-25 10:44:39 +0000
@@ -75,6 +75,14 @@
       <groupId>joda-time</groupId>
       <artifactId>joda-time</artifactId>
     </dependency>
+    <dependency>
+      <groupId>javax.validation</groupId>
+      <artifactId>validation-api</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>org.hibernate</groupId>
+      <artifactId>hibernate-validator</artifactId>
+    </dependency>
 
   </dependencies>
 

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java	2014-04-25 09:34:23 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/user/UserCredentials.java	2014-04-25 10:44:39 +0000
@@ -141,6 +141,7 @@
     public UserCredentials()
     {
         setAutoFields();
+        this.name = this.getClass().getSimpleName(); // Used to avoid JSR-303 issues
         this.lastLogin = new Date();
         this.passwordLastUpdated = new Date();
     }

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalStoreTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalStoreTest.java	2014-04-07 04:27:17 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataapproval/DataApprovalStoreTest.java	2014-04-25 10:44:39 +0000
@@ -123,10 +123,10 @@
         // Add supporting data
         // ---------------------------------------------------------------------
 
-        level1 = new DataApprovalLevel( "1", 1, null );
-        level2 = new DataApprovalLevel( "2", 2, null );
-        level3 = new DataApprovalLevel( "3", 3, null );
-        level4 = new DataApprovalLevel( "4", 4, null );
+        level1 = new DataApprovalLevel( "01", 1, null );
+        level2 = new DataApprovalLevel( "02", 2, null );
+        level3 = new DataApprovalLevel( "03", 3, null );
+        level4 = new DataApprovalLevel( "04", 4, null );
 
         PeriodType periodType = PeriodType.getPeriodTypeByName( "Monthly" );
 

=== modified file 'dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryServiceTest.java'
--- dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryServiceTest.java	2014-03-25 11:32:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/test/java/org/hisp/dhis/dataelement/DataElementCategoryServiceTest.java	2014-04-25 10:44:39 +0000
@@ -28,17 +28,14 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
+import org.hisp.dhis.DhisSpringTest;
+import org.junit.Test;
 
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
 
-import org.hisp.dhis.DhisSpringTest;
-import org.junit.Test;
+import static org.junit.Assert.*;
 
 /**
  * @author Lars Helge Overland
@@ -49,11 +46,11 @@
     private DataElementCategoryOption categoryOptionA;
     private DataElementCategoryOption categoryOptionB;
     private DataElementCategoryOption categoryOptionC;
-    
+
     private DataElementCategory categoryA;
     private DataElementCategory categoryB;
     private DataElementCategory categoryC;
-    
+
     private List<DataElementCategoryOption> categoryOptions;
 
     // -------------------------------------------------------------------------
@@ -65,19 +62,19 @@
     {
         categoryService = (DataElementCategoryService) getBean( DataElementCategoryService.ID );
 
-        categoryOptionA = new DataElementCategoryOption( "CategoryOptionA" );
-        categoryOptionB = new DataElementCategoryOption( "CategoryOptionB" );
-        categoryOptionC = new DataElementCategoryOption( "CategoryOptionC" );
-        
+        categoryOptionA = createCategoryOption( 'A' );
+        categoryOptionB = createCategoryOption( 'B' );
+        categoryOptionC = createCategoryOption( 'C' );
+
         categoryService.addDataElementCategoryOption( categoryOptionA );
         categoryService.addDataElementCategoryOption( categoryOptionB );
         categoryService.addDataElementCategoryOption( categoryOptionC );
-        
+
         categoryOptions = new ArrayList<DataElementCategoryOption>();
-        
+
         categoryOptions.add( categoryOptionA );
         categoryOptions.add( categoryOptionB );
-        categoryOptions.add( categoryOptionC );         
+        categoryOptions.add( categoryOptionC );
     }
 
     // -------------------------------------------------------------------------
@@ -87,21 +84,21 @@
     @Test
     public void testAddGet()
     {
-        categoryA = new DataElementCategory( "CategoryA", categoryOptions );
-        categoryB = new DataElementCategory( "CategoryB", categoryOptions );
-        categoryC = new DataElementCategory( "CategoryC", categoryOptions );
-        
+        categoryA = createDataElementCategory( 'A' );
+        categoryB = createDataElementCategory( 'B' );
+        categoryC = createDataElementCategory( 'C' );
+
         int idA = categoryService.addDataElementCategory( categoryA );
         int idB = categoryService.addDataElementCategory( categoryB );
         int idC = categoryService.addDataElementCategory( categoryC );
-        
+
         assertEquals( categoryA, categoryService.getDataElementCategory( idA ) );
         assertEquals( categoryB, categoryService.getDataElementCategory( idB ) );
         assertEquals( categoryC, categoryService.getDataElementCategory( idC ) );
-        
+
         assertEquals( categoryOptions, categoryService.getDataElementCategory( idA ).getCategoryOptions() );
         assertEquals( categoryOptions, categoryService.getDataElementCategory( idB ).getCategoryOptions() );
-        assertEquals( categoryOptions, categoryService.getDataElementCategory( idC ).getCategoryOptions() );        
+        assertEquals( categoryOptions, categoryService.getDataElementCategory( idC ).getCategoryOptions() );
     }
 
     @Test
@@ -110,15 +107,15 @@
         categoryA = new DataElementCategory( "CategoryA", categoryOptions );
         categoryB = new DataElementCategory( "CategoryB", categoryOptions );
         categoryC = new DataElementCategory( "CategoryC", categoryOptions );
-        
+
         int idA = categoryService.addDataElementCategory( categoryA );
         int idB = categoryService.addDataElementCategory( categoryB );
         int idC = categoryService.addDataElementCategory( categoryC );
-        
+
         assertNotNull( categoryService.getDataElementCategory( idA ) );
         assertNotNull( categoryService.getDataElementCategory( idB ) );
         assertNotNull( categoryService.getDataElementCategory( idC ) );
-        
+
         categoryService.deleteDataElementCategory( categoryA );
 
         assertNull( categoryService.getDataElementCategory( idA ) );
@@ -129,26 +126,26 @@
 
         assertNull( categoryService.getDataElementCategory( idA ) );
         assertNull( categoryService.getDataElementCategory( idB ) );
-        assertNotNull( categoryService.getDataElementCategory( idC ) );        
+        assertNotNull( categoryService.getDataElementCategory( idC ) );
     }
 
     @Test
     public void testGetAll()
     {
-        categoryA = new DataElementCategory( "CategoryA", categoryOptions );
-        categoryB = new DataElementCategory( "CategoryB", categoryOptions );
-        categoryC = new DataElementCategory( "CategoryC", categoryOptions );
+        categoryA = createDataElementCategory( 'A' );
+        categoryB = createDataElementCategory( 'B' );
+        categoryC = createDataElementCategory( 'C' );
 
         categoryService.addDataElementCategory( categoryA );
         categoryService.addDataElementCategory( categoryB );
         categoryService.addDataElementCategory( categoryC );
-        
+
         Collection<DataElementCategory> categories = categoryService.getAllDataElementCategories();
-        
+
         assertEquals( 4, categories.size() ); // Including default
         assertTrue( categories.contains( categoryA ) );
         assertTrue( categories.contains( categoryB ) );
-        assertTrue( categories.contains( categoryC ) );        
+        assertTrue( categories.contains( categoryC ) );
     }
 
     // -------------------------------------------------------------------------
@@ -158,18 +155,18 @@
     @Test
     public void testAddGetCategoryGroup()
     {
-        CategoryOptionGroup groupA = new CategoryOptionGroup( "A" );
-        CategoryOptionGroup groupB = new CategoryOptionGroup( "B" );
-        CategoryOptionGroup groupC = new CategoryOptionGroup( "C" );
-        
+        CategoryOptionGroup groupA = createCategoryOptionGroup( 'A' );
+        CategoryOptionGroup groupB = createCategoryOptionGroup( 'B' );
+        CategoryOptionGroup groupC = createCategoryOptionGroup( 'C' );
+
         groupA.getMembers().add( categoryOptionA );
         groupA.getMembers().add( categoryOptionB );
         groupB.getMembers().add( categoryOptionC );
-        
+
         int idA = categoryService.saveCategoryOptionGroup( groupA );
         int idB = categoryService.saveCategoryOptionGroup( groupB );
         int idC = categoryService.saveCategoryOptionGroup( groupC );
-        
+
         assertEquals( groupA, categoryService.getCategoryOptionGroup( idA ) );
         assertEquals( groupB, categoryService.getCategoryOptionGroup( idB ) );
         assertEquals( groupC, categoryService.getCategoryOptionGroup( idC ) );
@@ -178,7 +175,7 @@
         assertEquals( 1, categoryService.getCategoryOptionGroup( idB ).getMembers().size() );
         assertEquals( 0, categoryService.getCategoryOptionGroup( idC ).getMembers().size() );
     }
-    
+
     // -------------------------------------------------------------------------
     // CategoryOptionGroupSet
     // -------------------------------------------------------------------------
@@ -186,30 +183,30 @@
     @Test
     public void testAddGetCategoryGroupSet()
     {
-        CategoryOptionGroup groupA = new CategoryOptionGroup( "A" );
-        CategoryOptionGroup groupB = new CategoryOptionGroup( "B" );
-        CategoryOptionGroup groupC = new CategoryOptionGroup( "C" );
-        
+        CategoryOptionGroup groupA = createCategoryOptionGroup( 'A' );
+        CategoryOptionGroup groupB = createCategoryOptionGroup( 'B' );
+        CategoryOptionGroup groupC = createCategoryOptionGroup( 'C' );
+
         groupA.getMembers().add( categoryOptionA );
         groupA.getMembers().add( categoryOptionB );
         groupB.getMembers().add( categoryOptionC );
-        
+
         categoryService.saveCategoryOptionGroup( groupA );
         categoryService.saveCategoryOptionGroup( groupB );
         categoryService.saveCategoryOptionGroup( groupC );
-        
-        CategoryOptionGroupSet groupSetA = new CategoryOptionGroupSet( "A" );
-        CategoryOptionGroupSet groupSetB = new CategoryOptionGroupSet( "B" );
-        CategoryOptionGroupSet groupSetC = new CategoryOptionGroupSet( "C" );
-        
+
+        CategoryOptionGroupSet groupSetA = createCategoryOptionGroupSet( 'A' );
+        CategoryOptionGroupSet groupSetB = createCategoryOptionGroupSet( 'B' );
+        CategoryOptionGroupSet groupSetC = createCategoryOptionGroupSet( 'C' );
+
         groupSetA.getMembers().add( groupA );
         groupSetA.getMembers().add( groupB );
         groupSetB.getMembers().add( groupC );
-        
+
         int idA = categoryService.saveCategoryOptionGroupSet( groupSetA );
         int idB = categoryService.saveCategoryOptionGroupSet( groupSetB );
         int idC = categoryService.saveCategoryOptionGroupSet( groupSetC );
-        
+
         assertEquals( groupSetA, categoryService.getCategoryOptionGroupSet( idA ) );
         assertEquals( groupSetB, categoryService.getCategoryOptionGroupSet( idB ) );
         assertEquals( groupSetC, categoryService.getCategoryOptionGroupSet( idC ) );

=== modified file 'dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java'
--- dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2014-04-13 20:43:32 +0000
+++ dhis-2/dhis-support/dhis-support-test/src/main/java/org/hisp/dhis/DhisConvenienceTest.java	2014-04-25 10:44:39 +0000
@@ -40,7 +40,17 @@
 import org.hisp.dhis.constant.ConstantService;
 import org.hisp.dhis.datadictionary.DataDictionary;
 import org.hisp.dhis.datadictionary.DataDictionaryService;
-import org.hisp.dhis.dataelement.*;
+import org.hisp.dhis.dataelement.CategoryOptionGroup;
+import org.hisp.dhis.dataelement.CategoryOptionGroupSet;
+import org.hisp.dhis.dataelement.DataElement;
+import org.hisp.dhis.dataelement.DataElementCategory;
+import org.hisp.dhis.dataelement.DataElementCategoryCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryOption;
+import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
+import org.hisp.dhis.dataelement.DataElementCategoryService;
+import org.hisp.dhis.dataelement.DataElementGroup;
+import org.hisp.dhis.dataelement.DataElementGroupSet;
+import org.hisp.dhis.dataelement.DataElementService;
 import org.hisp.dhis.dataentryform.DataEntryFormService;
 import org.hisp.dhis.dataset.CompleteDataSetRegistrationService;
 import org.hisp.dhis.dataset.DataSet;
@@ -462,16 +472,16 @@
 
     /**
      * @param categoryComboUniqueIdentifier A unique character to identify the
-     *        category option combo.
-     * @param categories the categories
-     *        category options.
+     *                                      category option combo.
+     * @param categories                    the categories
+     *                                      category options.
      * @return DataElementCategoryOptionCombo
      */
     public static DataElementCategoryCombo createCategoryCombo( char categoryComboUniqueIdentifier,
-                                                                            DataElementCategory... categories )
+        DataElementCategory... categories )
     {
         DataElementCategoryCombo categoryCombo = new DataElementCategoryCombo( "CategoryCombo" + categoryComboUniqueIdentifier,
-                new ArrayList<DataElementCategory>() );
+            new ArrayList<DataElementCategory>() );
 
         for ( DataElementCategory category : categories )
         {
@@ -489,17 +499,17 @@
      * @return DataElementCategoryOptionCombo
      */
     public static DataElementCategoryOptionCombo createCategoryOptionCombo( char categoryComboUniqueIdentifier,
-                                                                            char... categoryOptionUniqueIdentifiers )
+        char... categoryOptionUniqueIdentifiers )
     {
         DataElementCategoryOptionCombo categoryOptionCombo = new DataElementCategoryOptionCombo();
 
         categoryOptionCombo.setCategoryCombo( new DataElementCategoryCombo( "CategoryCombo"
-                + categoryComboUniqueIdentifier ) );
+            + categoryComboUniqueIdentifier ) );
 
         for ( char identifier : categoryOptionUniqueIdentifiers )
         {
             categoryOptionCombo.getCategoryOptions()
-                    .add( new DataElementCategoryOption( "CategoryOption" + identifier ) );
+                .add( new DataElementCategoryOption( "CategoryOption" + identifier ) );
         }
 
         return categoryOptionCombo;
@@ -507,14 +517,14 @@
 
     /**
      * @param categoryComboUniqueIdentifier A unique character to identify the
-     *        category option combo.
-     * @param dataElementCategoryCombo The associated category combination.
-     * @param categoryOptions the category options.
+     *                                      category option combo.
+     * @param dataElementCategoryCombo      The associated category combination.
+     * @param categoryOptions               the category options.
      * @return DataElementCategoryOptionCombo
      */
     public static DataElementCategoryOptionCombo createCategoryOptionCombo( char categoryComboUniqueIdentifier,
-                                                                            DataElementCategoryCombo dataElementCategoryCombo,
-                                                                            DataElementCategoryOption... categoryOptions )
+        DataElementCategoryCombo dataElementCategoryCombo,
+        DataElementCategoryOption... categoryOptions )
     {
         DataElementCategoryOptionCombo categoryOptionCombo = new DataElementCategoryOptionCombo();
 
@@ -553,16 +563,17 @@
     }
 
     /**
-     * @param categoryUniqueIdentifier  A unique character to identify the
-     *        category.
-     * @param categoryOptions the category options.
+     * @param categoryUniqueIdentifier A unique character to identify the
+     *                                 category.
+     * @param categoryOptions          the category options.
      * @return DataElementCategory
      */
-    public static DataElementCategory createDataElementCategory(  char categoryUniqueIdentifier,
-                                                                  DataElementCategoryOption... categoryOptions )
+    public static DataElementCategory createDataElementCategory( char categoryUniqueIdentifier,
+        DataElementCategoryOption... categoryOptions )
     {
         DataElementCategory dataElementCategory = new DataElementCategory( "DataElementCategory" + categoryUniqueIdentifier,
-                new ArrayList<DataElementCategoryOption>() );
+            new ArrayList<DataElementCategoryOption>() );
+        dataElementCategory.setAutoFields();
 
         for ( DataElementCategoryOption categoryOption : categoryOptions )
         {
@@ -572,16 +583,25 @@
         return dataElementCategory;
     }
 
+    public static DataElementCategoryOption createCategoryOption( char uniqueIdentifier )
+    {
+        DataElementCategoryOption categoryOption = new DataElementCategoryOption( "CategoryOption" + uniqueIdentifier );
+        categoryOption.setAutoFields();
+
+        return categoryOption;
+    }
+
     /**
-     * @param categoryGroupUniqueIdentifier  A unique character to identify the
-     *        category option group.
-     * @param categoryOptions the category options.
+     * @param categoryGroupUniqueIdentifier A unique character to identify the
+     *                                      category option group.
+     * @param categoryOptions               the category options.
      * @return CategoryOptionGroup
      */
-    public static CategoryOptionGroup createCategoryOptionGroup(  char categoryGroupUniqueIdentifier,
-                                                                  DataElementCategoryOption... categoryOptions )
+    public static CategoryOptionGroup createCategoryOptionGroup( char categoryGroupUniqueIdentifier,
+        DataElementCategoryOption... categoryOptions )
     {
         CategoryOptionGroup categoryOptionGroup = new CategoryOptionGroup( "CategoryOptionGroup" + categoryGroupUniqueIdentifier );
+        categoryOptionGroup.setAutoFields();
 
         categoryOptionGroup.setMembers( new HashSet<DataElementCategoryOption>() );
 
@@ -594,15 +614,16 @@
     }
 
     /**
-     * @param categoryGroupSetUniqueIdentifier  A unique character to identify the
-     *        category option group set.
-     * @param categoryOptionGroups the category option groups.
+     * @param categoryGroupSetUniqueIdentifier A unique character to identify the
+     *                                         category option group set.
+     * @param categoryOptionGroups             the category option groups.
      * @return CategoryOptionGroupSet
      */
-    public static CategoryOptionGroupSet createCategoryOptionGroupSet(  char categoryGroupSetUniqueIdentifier,
-                                                                     CategoryOptionGroup... categoryOptionGroups )
+    public static CategoryOptionGroupSet createCategoryOptionGroupSet( char categoryGroupSetUniqueIdentifier,
+        CategoryOptionGroup... categoryOptionGroups )
     {
         CategoryOptionGroupSet categoryOptionGroupSet = new CategoryOptionGroupSet( "CategoryOptionGroupSet" + categoryGroupSetUniqueIdentifier );
+        categoryOptionGroupSet.setAutoFields();
 
         // categoryOptionGroupSet.setMembers( new ArrayList<CategoryOptionGroup>() );
 
@@ -1079,6 +1100,7 @@
     public static User createUser( char uniqueCharacter )
     {
         User user = new User();
+        user.setAutoFields();
 
         user.setFirstName( "FirstName" + uniqueCharacter );
         user.setSurname( "Surname" + uniqueCharacter );

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java	2014-04-02 11:36:07 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AbstractCrudController.java	2014-04-25 10:44:39 +0000
@@ -293,7 +293,7 @@
     // PUT
     //--------------------------------------------------------------------------
 
-    @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = { "application/xml", "text/xml" } )
+    @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = { MediaType.APPLICATION_XML_VALUE, MediaType.TEXT_XML_VALUE } )
     @ResponseStatus( value = HttpStatus.NO_CONTENT )
     public void putXmlObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream
         input ) throws Exception
@@ -318,7 +318,7 @@
         renderService.toJson( response.getOutputStream(), summary );
     }
 
-    @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = "application/json" )
+    @RequestMapping( value = "/{uid}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE )
     @ResponseStatus( value = HttpStatus.NO_CONTENT )
     public void putJsonObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid, InputStream
         input ) throws Exception
@@ -347,7 +347,7 @@
     // DELETE
     //--------------------------------------------------------------------------
 
-    @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE )
+    @RequestMapping( value = "/{uid}", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE )
     @ResponseStatus( value = HttpStatus.NO_CONTENT )
     public void deleteObject( HttpServletResponse response, HttpServletRequest request, @PathVariable( "uid" ) String uid ) throws
         Exception
@@ -366,7 +366,6 @@
     // Hooks
     //--------------------------------------------------------------------------
 
-
     /**
      * Override to process entities after it has been retrieved from
      * storage and before it is returned to the view. Entities is null-safe.

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/CrudControllerAdvice.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/CrudControllerAdvice.java	2014-03-18 08:10:10 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/CrudControllerAdvice.java	2014-04-25 10:44:39 +0000
@@ -41,6 +41,8 @@
 import org.springframework.web.client.HttpServerErrorException;
 import org.springframework.web.client.HttpStatusCodeException;
 
+import javax.validation.ConstraintViolationException;
+
 /**
  * @author Morten Olav Hansen <mortenoh@xxxxxxxxx>
  */
@@ -56,7 +58,7 @@
         return new ResponseEntity<String>( ex.getMessage(), headers, HttpStatus.UNAUTHORIZED );
     }
 
-    @ExceptionHandler({ NotFoundException.class, NotFoundForQueryException.class })
+    @ExceptionHandler( { NotFoundException.class, NotFoundForQueryException.class } )
     public ResponseEntity<String> notFoundExceptionHandler( Exception ex )
     {
         HttpHeaders headers = new HttpHeaders();
@@ -73,4 +75,13 @@
 
         return new ResponseEntity<String>( ex.getStatusText(), headers, ex.getStatusCode() );
     }
+
+    @ExceptionHandler( ConstraintViolationException.class )
+    public ResponseEntity<String> constraintViolationException( ConstraintViolationException ex )
+    {
+        HttpHeaders headers = new HttpHeaders();
+        headers.add( "Content-Type", MediaType.TEXT_PLAIN_VALUE );
+
+        return new ResponseEntity<String>( ex.getMessage(), headers, HttpStatus.UNPROCESSABLE_ENTITY );
+    }
 }