dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #33734
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 17275: Approval. Replaced try/catch boilerplate code with @ExceptionHandler
------------------------------------------------------------
revno: 17275
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2014-10-25 12:38:05 +0200
message:
Approval. Replaced try/catch boilerplate code with @ExceptionHandler
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/exceptions/DataMayNotBeApprovedException.java
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-api/src/main/java/org/hisp/dhis/dataapproval/exceptions/DataMayNotBeApprovedException.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/exceptions/DataMayNotBeApprovedException.java 2014-10-25 10:30:49 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/dataapproval/exceptions/DataMayNotBeApprovedException.java 2014-10-25 10:38:05 +0000
@@ -32,7 +32,7 @@
* @author Jim Grace
*/
public class DataMayNotBeApprovedException
- extends DataApprovalException
+ extends DataApprovalException
{
public DataMayNotBeApprovedException()
{
=== 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-07-15 13:54:20 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/CrudControllerAdvice.java 2014-10-25 10:38:05 +0000
@@ -33,6 +33,7 @@
import org.hisp.dhis.common.DeleteNotAllowedException;
import org.hisp.dhis.common.IllegalQueryException;
import org.hisp.dhis.common.MaintenanceModeException;
+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.springframework.http.HttpHeaders;
@@ -93,12 +94,18 @@
return new ResponseEntity<>( ex.getMessage(), getHeaders(), HttpStatus.CONFLICT );
}
- @ExceptionHandler( { MaintenanceModeException.class } )
+ @ExceptionHandler( MaintenanceModeException.class )
public ResponseEntity<String> maintenanceModeExceptionHandler( MaintenanceModeException ex )
{
return new ResponseEntity<>( ex.getMessage(), getHeaders(), HttpStatus.SERVICE_UNAVAILABLE );
}
+ @ExceptionHandler( DataApprovalException.class )
+ public ResponseEntity<String> dataApprovalExceptionHandler( DataApprovalException ex )
+ {
+ return new ResponseEntity<>( ex.getMessage(), getHeaders(), HttpStatus.CONFLICT );
+ }
+
private HttpHeaders getHeaders()
{
HttpHeaders headers = new HttpHeaders();
=== 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 10:28:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/DataApprovalController.java 2014-10-25 10:38:05 +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;
@@ -341,14 +340,7 @@
List<DataApproval> dataApprovalList = makeDataApprovalList( dataApprovalLevel, dataSet,
period, organisationUnit, false, new Date(), user ); //TODO fix category stuff
- try
- {
- dataApprovalService.approveData( dataApprovalList );
- }
- catch ( DataApprovalException ex )
- {
- ContextUtils.conflictResponse( response, ex.getClass().getName() );
- }
+ dataApprovalService.approveData( dataApprovalList );
}
@RequestMapping( method = RequestMethod.POST, value = "/batch" )
@@ -415,14 +407,7 @@
period, organisationUnit, false, approvalDate, user ) );
}
- try
- {
- dataApprovalService.approveData( dataApprovalList );
- }
- catch ( DataApprovalException ex )
- {
- ContextUtils.conflictResponse( response, ex.getClass().getName() );
- }
+ dataApprovalService.approveData( dataApprovalList );
}
// -------------------------------------------------------------------------
@@ -475,14 +460,7 @@
List<DataApproval> dataApprovalList = makeDataApprovalList( dataApprovalLevel, dataSet,
period, organisationUnit, false, new Date(), user );
- try
- {
- dataApprovalService.acceptData( dataApprovalList );
- }
- catch ( DataApprovalException ex )
- {
- ContextUtils.conflictResponse( response, ex.getClass().getName() );
- }
+ dataApprovalService.acceptData( dataApprovalList );
}
@RequestMapping( method = RequestMethod.POST, value = "/acceptances/batch" )
@@ -547,15 +525,8 @@
dataApprovalList.addAll( makeDataApprovalList( dataApprovalLevel, dataSet,
period, organisationUnit, false, approvalDate, user ) );
}
-
- try
- {
- dataApprovalService.acceptData( dataApprovalList );
- }
- catch ( DataApprovalException ex )
- {
- ContextUtils.conflictResponse( response, ex.getClass().getName() );
- }
+
+ dataApprovalService.acceptData( dataApprovalList );
}
// -------------------------------------------------------------------------
@@ -613,14 +584,7 @@
period, organisationUnit, false, new Date(), user ) );
}
- try
- {
- dataApprovalService.unapproveData( dataApprovalList );
- }
- catch ( DataApprovalException ex )
- {
- ContextUtils.conflictResponse( response, ex.getClass().getName() );
- }
+ dataApprovalService.unapproveData( dataApprovalList );
}
@RequestMapping( method = RequestMethod.DELETE, value = "/batch" )
@@ -685,14 +649,7 @@
List<DataApproval> dataApprovalList = makeDataApprovalList( dataApprovalLevel, dataSet,
period, organisationUnit, false, new Date(), user );
- try
- {
- dataApprovalService.unacceptData( dataApprovalList );
- }
- catch ( DataApprovalException ex )
- {
- ContextUtils.conflictResponse( response, ex.getClass().getName() );
- }
+ dataApprovalService.unacceptData( dataApprovalList );
}
@RequestMapping( method = RequestMethod.DELETE, value = "/acceptances/batch" )