← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18030: App controller, better feedback on installation

 

------------------------------------------------------------
revno: 18030
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-01-16 18:19:19 +0100
message:
  App controller, better feedback on installation
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-01-16 17:12:53 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppController.java	2015-01-16 17:19:19 +0000
@@ -36,6 +36,8 @@
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.appmanager.App;
 import org.hisp.dhis.appmanager.AppManager;
 import org.hisp.dhis.dxf2.render.RenderService;
@@ -59,6 +61,7 @@
 import org.springframework.web.context.request.ServletWebRequest;
 import org.springframework.web.multipart.MultipartFile;
 
+import com.fasterxml.jackson.core.JsonParseException;
 import com.google.common.collect.Lists;
 
 /**
@@ -68,6 +71,8 @@
 @RequestMapping( AppController.RESOURCE_PATH )
 public class AppController
 {
+    private static final Log log = LogFactory.getLog( AppController.class );
+    
     public static final String RESOURCE_PATH = "/apps";
 
     @Autowired
@@ -90,14 +95,27 @@
     @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 ) throws IOException
+    public void installApp( @RequestParam( "file" ) MultipartFile file, HttpServletRequest request, HttpServletResponse response ) throws IOException
     {
         File tempFile = File.createTempFile( "IMPORT_", "_ZIP" );
         file.transferTo( tempFile );
         
         String contextPath = ContextUtils.getContextPath( request );
         
-        appManager.installApp( tempFile, file.getOriginalFilename(), contextPath );
+        try
+        {
+            appManager.installApp( tempFile, file.getOriginalFilename(), contextPath );
+        }
+        catch ( JsonParseException ex )
+        {
+            ContextUtils.conflictResponse( response, "Invalid JSON in app manifest file" );            
+            log.error( ex );
+        }
+        catch ( IOException ex )
+        {
+            ContextUtils.conflictResponse( response, "App could not not be installed on file system, check permissions" );            
+            log.error( ex );
+        }
     }
 
     @RequestMapping( method = RequestMethod.PUT )