← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21511: Impl support for installing apps directly from app store at POST api/appStore/{version-id}

 

------------------------------------------------------------
revno: 21511
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2015-12-22 13:43:17 +0100
message:
  Impl support for installing apps directly from app store at POST api/appStore/{version-id}
added:
  dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppStoreController.java
modified:
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/appstore/DefaultAppStoreManager.java
  dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/appstore/WebAppVersion.java
  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-services/dhis-service-administration/src/main/java/org/hisp/dhis/appstore/DefaultAppStoreManager.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/appstore/DefaultAppStoreManager.java	2015-12-22 12:10:29 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/appstore/DefaultAppStoreManager.java	2015-12-22 12:43:17 +0000
@@ -67,6 +67,11 @@
     
     public AppStatus installAppFromAppStore( String id )
     {
+        if ( id == null )
+        {
+            return AppStatus.NOT_FOUND;
+        }
+        
         try
         {
             Optional<WebAppVersion> webAppVersion = getWebAppVersion( id );
@@ -77,7 +82,7 @@
                 
                 URL url = new URL( version.getDownloadUrl() );
                 
-                String filename = url.getFile();
+                String filename = version.getFilename();
                 
                 return appManager.installApp( getFile( url ), filename );
             }

=== modified file 'dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/appstore/WebAppVersion.java'
--- dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/appstore/WebAppVersion.java	2015-12-21 21:50:29 +0000
+++ dhis-2/dhis-services/dhis-service-administration/src/main/java/org/hisp/dhis/appstore/WebAppVersion.java	2015-12-22 12:43:17 +0000
@@ -1,5 +1,9 @@
 package org.hisp.dhis.appstore;
 
+import org.apache.commons.io.FilenameUtils;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+
 /*
  * Copyright (c) 2004-2015, University of Oslo
  * All rights reserved.
@@ -51,6 +55,12 @@
     {
     }
 
+    @JsonIgnore
+    public String getFilename()
+    {
+        return FilenameUtils.getName( downloadUrl );
+    }
+    
     @JsonProperty
     public String getId()
     {

=== 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-12-22 11:50:21 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppController.java	2015-12-22 12:43:17 +0000
@@ -34,8 +34,6 @@
 import org.hisp.dhis.appmanager.App;
 import org.hisp.dhis.appmanager.AppManager;
 import org.hisp.dhis.appmanager.AppStatus;
-import org.hisp.dhis.appstore.AppStore;
-import org.hisp.dhis.appstore.AppStoreManager;
 import org.hisp.dhis.dxf2.render.DefaultRenderService;
 import org.hisp.dhis.dxf2.render.RenderService;
 import org.hisp.dhis.dxf2.webmessage.WebMessageException;
@@ -79,9 +77,6 @@
     private AppManager appManager;
     
     @Autowired
-    private AppStoreManager appStoreManager;
-
-    @Autowired
     private RenderService renderService;
 
     @Autowired
@@ -275,13 +270,6 @@
         appManager.setAppBaseUrl( appBaseUrl );
     }
 
-    @RequestMapping( value = "/appStore", method = RequestMethod.GET, produces = "application/json" )
-    public @ResponseBody AppStore getAppStore( HttpServletResponse response )
-        throws IOException
-    {
-        return appStoreManager.getAppStore();
-    }
-    
     //--------------------------------------------------------------------------
     // Helpers
     //--------------------------------------------------------------------------

=== added file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppStoreController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppStoreController.java	1970-01-01 00:00:00 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppStoreController.java	2015-12-22 12:43:17 +0000
@@ -0,0 +1,72 @@
+package org.hisp.dhis.webapi.controller;
+
+/*
+ * Copyright (c) 2004-2015, University of Oslo
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ * Neither the name of the HISP project nor the names of its contributors may
+ * be used to endorse or promote products derived from this software without
+ * specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
+ * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
+ * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.PathVariable;
+import org.springframework.web.bind.annotation.RequestMapping;
+import org.springframework.web.bind.annotation.RequestMethod;
+import org.springframework.web.bind.annotation.ResponseBody;
+import org.springframework.web.bind.annotation.ResponseStatus;
+
+import java.io.IOException;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.hisp.dhis.appstore.AppStore;
+import org.hisp.dhis.appstore.AppStoreManager;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+
+/**
+ * @author Lars Helge Overland
+ */
+@Controller
+@RequestMapping( AppStoreController.RESOURCE_PATH )
+public class AppStoreController
+{
+    public static final String RESOURCE_PATH = "/appStore";
+    
+    @Autowired
+    private AppStoreManager appStoreManager;
+
+    @RequestMapping( method = RequestMethod.GET, produces = "application/json" )
+    public @ResponseBody AppStore getAppStore( HttpServletResponse response )
+        throws IOException
+    {
+        return appStoreManager.getAppStore();
+    }
+    
+    @ResponseStatus( value = HttpStatus.OK )
+    @RequestMapping( value = "/{versionId}", method = RequestMethod.POST )
+    public void installAppFromAppStore( @PathVariable String versionId )
+    {
+        appStoreManager.installAppFromAppStore( versionId );
+    } 
+}