← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12093: minor fix

 

------------------------------------------------------------
revno: 12093
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2013-09-16 09:06:31 +0200
message:
  minor fix
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.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/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java	2013-09-13 13:06:54 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/event/PersonController.java	2013-09-16 07:06:31 +0000
@@ -29,6 +29,7 @@
  */
 
 import org.hisp.dhis.api.controller.WebOptions;
+import org.hisp.dhis.api.controller.exception.NotFoundException;
 import org.hisp.dhis.api.utils.ContextUtils;
 import org.hisp.dhis.common.IdentifiableObjectManager;
 import org.hisp.dhis.dxf2.event.person.Gender;
@@ -135,18 +136,6 @@
         return "persons";
     }
 
-    private Program getProgram( String programUid )
-    {
-        Program program = manager.get( Program.class, programUid );
-
-        if ( program == null )
-        {
-            throw new HttpClientErrorException( HttpStatus.BAD_REQUEST, "program is not valid uid." );
-        }
-
-        return program;
-    }
-
     private OrganisationUnit getOrganisationUnit( String orgUnitUid )
     {
         OrganisationUnit organisationUnit = manager.get( OrganisationUnit.class, orgUnitUid );
@@ -244,9 +233,36 @@
 
     @RequestMapping( value = "/{id}", method = RequestMethod.DELETE )
     @ResponseStatus( value = HttpStatus.NO_CONTENT )
-    public void deletePerson( @PathVariable String id )
+    public void deletePerson( @PathVariable String id ) throws NotFoundException
     {
-        Person person = personService.getPerson( id );
+        Person person = getPerson( id );
         personService.deletePerson( person );
     }
+
+    // -------------------------------------------------------------------------
+    // HELPERS
+    // -------------------------------------------------------------------------
+
+    private Person getPerson( String id ) throws NotFoundException
+    {
+        Person person = personService.getPerson( id );
+
+        if ( person == null )
+        {
+            throw new NotFoundException( "Person", id );
+        }
+        return person;
+    }
+
+    private Program getProgram( String id ) throws NotFoundException
+    {
+        Program program = manager.get( Program.class, id );
+
+        if ( program == null )
+        {
+            throw new NotFoundException( "Person", id );
+        }
+
+        return program;
+    }
 }