← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18028: App controller. Fixed bug with removal of app in UI. Rendering get response as json only as we on...

 

------------------------------------------------------------
revno: 18028
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-01-16 17:44:06 +0100
message:
  App controller. Fixed bug with removal of app in UI. Rendering get response as json only as we only have json annotations on App.java. Introduced key property on app which can be used as reference for delete.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/App.java
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppController.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/webapp/dhis-web-maintenance-appmanager/appSettings.vm


--
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/appmanager/App.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/App.java	2014-05-29 18:58:33 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/App.java	2015-01-16 16:44:06 +0000
@@ -101,6 +101,19 @@
         return null;
     }
     
+    /**
+     * Alias for folder name.
+     */
+    @JsonProperty
+    public String getKey()
+    {
+        return folderName;
+    }
+
+    // -------------------------------------------------------------------------
+    // Get and set methods
+    // -------------------------------------------------------------------------
+    
     public String getVersion()
     {
         return version;

=== 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	2014-12-16 13:31:39 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppController.java	2015-01-16 16:44:06 +0000
@@ -28,9 +28,17 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.google.common.collect.Lists;
+import java.io.File;
+import java.io.IOException;
+import java.util.Date;
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import org.hisp.dhis.appmanager.App;
 import org.hisp.dhis.appmanager.AppManager;
+import org.hisp.dhis.dxf2.render.RenderService;
 import org.hisp.dhis.dxf2.utils.JacksonUtils;
 import org.hisp.dhis.hibernate.exception.ReadAccessDeniedException;
 import org.hisp.dhis.system.util.DateUtils;
@@ -42,7 +50,6 @@
 import org.springframework.http.HttpStatus;
 import org.springframework.security.access.prepost.PreAuthorize;
 import org.springframework.stereotype.Controller;
-import org.springframework.ui.Model;
 import org.springframework.util.StreamUtils;
 import org.springframework.web.bind.annotation.PathVariable;
 import org.springframework.web.bind.annotation.RequestMapping;
@@ -52,37 +59,35 @@
 import org.springframework.web.context.request.ServletWebRequest;
 import org.springframework.web.multipart.MultipartFile;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-import java.io.IOException;
-import java.util.Date;
-import java.util.List;
+import com.google.common.collect.Lists;
 
 /**
  * @author Lars Helge Overland
  */
 @Controller
+@RequestMapping( AppController.RESOURCE_PATH )
 public class AppController
 {
     public static final String RESOURCE_PATH = "/apps";
 
     @Autowired
     private AppManager appManager;
+    
+    @Autowired
+    private RenderService renderService;
 
     private ResourceLoader resourceLoader = new DefaultResourceLoader();
 
-    @RequestMapping( value = RESOURCE_PATH, method = RequestMethod.GET )
-    public String getApps( Model model )
+    @RequestMapping( method = RequestMethod.GET, produces = ContextUtils.CONTENT_TYPE_JSON )
+    public void getApps( HttpServletResponse response )
+        throws IOException
     {
         List<App> apps = appManager.getApps();
-
-        model.addAttribute( "model", apps );
-
-        return "apps";
+        
+        renderService.toJson( response.getOutputStream(), apps );
     }
 
-    @RequestMapping( value = RESOURCE_PATH, method = RequestMethod.POST )
+    @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
@@ -93,7 +98,7 @@
         appManager.installApp( tempFile, file.getOriginalFilename(), getBaseUrl( request ) );
     }
 
-    @RequestMapping( value = RESOURCE_PATH, method = RequestMethod.PUT )
+    @RequestMapping( method = RequestMethod.PUT )
     @ResponseStatus( HttpStatus.NO_CONTENT )
     @PreAuthorize( "hasRole('ALL') or hasRole('M_dhis-web-maintenance-appmanager')" )
     public void reloadApps()
@@ -101,7 +106,7 @@
         appManager.reloadApps();
     }
 
-    @RequestMapping( value = "/apps/{app}/**", method = RequestMethod.GET )
+    @RequestMapping( value = "/{app}/**", method = RequestMethod.GET )
     public void renderApp( @PathVariable( "app" ) String app, HttpServletRequest request, HttpServletResponse response ) throws IOException
     {
         Iterable<Resource> locations = Lists.newArrayList(
@@ -124,7 +129,7 @@
             throw new ReadAccessDeniedException( "You don't have access to application " + app + "." );
         }
 
-        String pageName = findPage( request.getPathInfo(), app );
+        String pageName = getUrl( request.getPathInfo(), app );
 
         // if request was for manifest.webapp, check for * and replace with host
         if ( "manifest.webapp".equals( pageName ) )
@@ -163,7 +168,7 @@
         StreamUtils.copy( resource.getInputStream(), response.getOutputStream() );
     }
 
-    @RequestMapping( value = "/apps/{app}", method = RequestMethod.DELETE )
+    @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 )
     {
@@ -197,7 +202,7 @@
         return null;
     }
 
-    private String findPage( String path, String app )
+    private String getUrl( String path, String app )
     {
         String prefix = RESOURCE_PATH + "/" + app + "/";
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/webapp/dhis-web-maintenance-appmanager/appSettings.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/webapp/dhis-web-maintenance-appmanager/appSettings.vm	2014-03-02 06:45:58 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/webapp/dhis-web-maintenance-appmanager/appSettings.vm	2015-01-16 16:44:06 +0000
@@ -52,7 +52,7 @@
         </thead>
         <tbody id="list">
             #foreach( $app in $appList )
-            <tr id="tr${app.name.replace(' ','_')}" data-id="${app.name.replace(' ','_')}" data-name="$encoder.jsEncode( $app.name )">
+            <tr id="tr${app.key}" data-id="${app.key}" data-name="$encoder.jsEncode( $app.name )">
                 <td>$encoder.jsEncode( $app.name )</td>
                 <td>$app.version</td>
             </tr>