← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17286: Centralized boiler-plate code for exception handling

 

------------------------------------------------------------
revno: 17286
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-10-25 23:36:41 +0200
message:
  Centralized boiler-plate code for exception handling
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.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/webapi/controller/CrudControllerAdvice.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.java	2014-10-25 10:38:05 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.java	2014-10-25 21:36:41 +0000
@@ -28,6 +28,7 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import javax.servlet.http.HttpServletResponse;
 import javax.validation.ConstraintViolationException;
 
 import org.hisp.dhis.common.DeleteNotAllowedException;
@@ -36,6 +37,7 @@
 import org.hisp.dhis.dataapproval.exceptions.DataApprovalException;
 import org.hisp.dhis.webapi.controller.exception.NotAuthenticatedException;
 import org.hisp.dhis.webapi.controller.exception.NotFoundException;
+import org.hisp.dhis.webapi.utils.ContextUtils;
 import org.springframework.http.HttpHeaders;
 import org.springframework.http.HttpStatus;
 import org.springframework.http.MediaType;
@@ -101,9 +103,9 @@
     }
     
     @ExceptionHandler( DataApprovalException.class )
-    public ResponseEntity<String> dataApprovalExceptionHandler( DataApprovalException ex )
+    public void dataApprovalExceptionHandler( DataApprovalException ex, HttpServletResponse response )
     {
-        return new ResponseEntity<>( ex.getMessage(), getHeaders(), HttpStatus.CONFLICT );
+        ContextUtils.conflictResponse( response, ex.getClass().getName() ); //TODO fix message
     }
     
     private HttpHeaders getHeaders()

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java	2014-10-25 21:20:14 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java	2014-10-25 21:36:41 +0000
@@ -58,7 +58,6 @@
 import org.hisp.dhis.dataapproval.DataApprovalStateResponse;
 import org.hisp.dhis.dataapproval.DataApprovalStateResponses;
 import org.hisp.dhis.dataapproval.DataApprovalStatus;
-import org.hisp.dhis.dataapproval.exceptions.DataApprovalException;
 import org.hisp.dhis.dataelement.DataElementCategoryOptionCombo;
 import org.hisp.dhis.dataelement.DataElementCategoryService;
 import org.hisp.dhis.dataset.DataSet;
@@ -356,14 +355,7 @@
             ContextUtils.conflictResponse( response, "Approval must have data sets, periods and category option combos" );
         }
 
-        try
-        {
-            dataApprovalService.approveData( getDataApprovalList( dataApproval ) );
-        }
-        catch ( DataApprovalException ex )
-        {
-            ContextUtils.conflictResponse( response, ex.getClass().getName() );
-        }
+        dataApprovalService.approveData( getDataApprovalList( dataApproval ) );
     }
 
     @RequestMapping( value = APPROVALS_PATH + "/unapprovals", method = RequestMethod.POST )
@@ -375,14 +367,7 @@
             ContextUtils.conflictResponse( response, "Approval must have data sets, periods and category option combos" );
         }
 
-        try
-        {
-            dataApprovalService.unapproveData( getDataApprovalList( dataApproval ) );
-        }
-        catch ( DataApprovalException ex )
-        {
-            ContextUtils.conflictResponse( response, ex.getClass().getName() );
-        }
+        dataApprovalService.unapproveData( getDataApprovalList( dataApproval ) );
     }
 
     @PreAuthorize( "hasRole('ALL') or hasRole('F_APPROVE_DATA') or hasRole('F_APPROVE_DATA_LOWER_LEVELS')" )
@@ -501,15 +486,8 @@
         {
             ContextUtils.conflictResponse( response, "Acceptance must have data sets, periods and category option combos" );
         }
-
-        try
-        {
-            dataApprovalService.acceptData( getDataApprovalList( dataApproval ) );
-        }
-        catch ( DataApprovalException ex )
-        {
-            ContextUtils.conflictResponse( response, ex.getClass().getName() );
-        }
+        
+        dataApprovalService.acceptData( getDataApprovalList( dataApproval ) );
     }
 
     @RequestMapping( value = ACCEPTANCES_PATH + "/unacceptances", method = RequestMethod.POST )
@@ -520,15 +498,8 @@
         {
             ContextUtils.conflictResponse( response, "Acceptance must have data sets, periods and category option combos" );
         }
-
-        try
-        {
-            dataApprovalService.unacceptData( getDataApprovalList( dataApproval ) );
-        }
-        catch ( DataApprovalException ex )
-        {
-            ContextUtils.conflictResponse( response, ex.getClass().getName() );
-        }        
+        
+        dataApprovalService.unacceptData( getDataApprovalList( dataApproval ) );
     }
 
     @PreAuthorize( "hasRole('ALL') or hasRole('F_ACCEPT_DATA_LOWER_LEVELS')" )