← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 19577: update AppController to use WebMessageException for error messages

 

------------------------------------------------------------
revno: 19577
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2015-07-08 12:29:54 +0700
message:
  update AppController to use WebMessageException for error messages
modified:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppController.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/AppController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppController.java	2015-03-23 09:54:57 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppController.java	2015-07-08 05:29:54 +0000
@@ -38,10 +38,12 @@
 import org.hisp.dhis.appmanager.AppManager;
 import org.hisp.dhis.dxf2.render.DefaultRenderService;
 import org.hisp.dhis.dxf2.render.RenderService;
+import org.hisp.dhis.dxf2.webmessage.WebMessageException;
 import org.hisp.dhis.external.location.LocationManager;
 import org.hisp.dhis.hibernate.exception.ReadAccessDeniedException;
 import org.hisp.dhis.system.util.DateUtils;
 import org.hisp.dhis.webapi.utils.ContextUtils;
+import org.hisp.dhis.webapi.utils.WebMessageUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.core.io.DefaultResourceLoader;
 import org.springframework.core.io.Resource;
@@ -100,7 +102,7 @@
     @RequestMapping( method = RequestMethod.POST )
     @ResponseStatus( HttpStatus.NO_CONTENT )
     @PreAuthorize( "hasRole('ALL') or hasRole('M_dhis-web-maintenance-appmanager')" )
-    public void installApp( @RequestParam( "file" ) MultipartFile file, HttpServletRequest request, HttpServletResponse response ) throws IOException
+    public void installApp( @RequestParam( "file" ) MultipartFile file, HttpServletRequest request, HttpServletResponse response ) throws IOException, WebMessageException
     {
         File tempFile = File.createTempFile( "IMPORT_", "_ZIP" );
         file.transferTo( tempFile );
@@ -113,13 +115,11 @@
         }
         catch ( JsonParseException ex )
         {
-            ContextUtils.conflictResponse( response, "Invalid JSON in app manifest file" );
-            log.error( ex );
+            throw new WebMessageException( WebMessageUtils.conflict( "Invalid JSON in app manifest file." ) );
         }
         catch ( IOException ex )
         {
-            ContextUtils.conflictResponse( response, "App could not not be installed on file system, check permissions" );
-            log.error( ex );
+            throw new WebMessageException( WebMessageUtils.conflict( "App could not not be installed on file system, check permissions" ) );
         }
     }
 
@@ -198,30 +198,29 @@
 
     @RequestMapping( value = "/{app}", method = RequestMethod.DELETE )
     @PreAuthorize( "hasRole('ALL') or hasRole('M_dhis-web-maintenance-appmanager')" )
-    public void deleteApp( @PathVariable( "app" ) String app, HttpServletRequest request, HttpServletResponse response )
+    public void deleteApp( @PathVariable( "app" ) String app, HttpServletRequest request, HttpServletResponse response ) throws WebMessageException
     {
         if ( !appManager.exists( app ) )
         {
-            ContextUtils.notFoundResponse( response, "App does not exist: " + app );
+            throw new WebMessageException( WebMessageUtils.notFound( "App does not exist: " + app ) );
         }
 
         if ( !appManager.deleteApp( app ) )
         {
-            ContextUtils.conflictResponse( response, "There was an error deleting app: " + app );
+            throw new WebMessageException( WebMessageUtils.conflict( "There was an error deleting app: " + app ) );
         }
     }
 
     @SuppressWarnings( "unchecked" )
     @RequestMapping( value = "/config", method = RequestMethod.POST, consumes = ContextUtils.CONTENT_TYPE_JSON )
     @PreAuthorize( "hasRole('ALL') or hasRole('M_dhis-web-maintenance-appmanager')" )
-    public void setConfig( HttpServletRequest request, HttpServletResponse response ) throws IOException
+    public void setConfig( HttpServletRequest request, HttpServletResponse response ) throws IOException, WebMessageException
     {
         Map<String, String> config = renderService.fromJson( request.getInputStream(), Map.class );
 
         if ( config == null )
         {
-            ContextUtils.conflictResponse( response, "No config specified" );
-            return;
+            throw new WebMessageException( WebMessageUtils.conflict( "No config specified" ) );
         }
 
         String appBaseUrl = StringUtils.trimToNull( config.get( AppManager.KEY_APP_BASE_URL ) );