dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #27359
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13612: support app install by posting a file to /api/apps
------------------------------------------------------------
revno: 13612
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-01-07 13:49:31 +0100
message:
support app install by posting a file to /api/apps
modified:
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/appmanager/DefaultAppManager.java
dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AppController.java
dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml
--
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-core/src/main/java/org/hisp/dhis/appmanager/DefaultAppManager.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/appmanager/DefaultAppManager.java 2014-01-07 11:47:11 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/appmanager/DefaultAppManager.java 2014-01-07 12:49:31 +0000
@@ -38,6 +38,8 @@
import org.hisp.dhis.datavalue.DefaultDataValueService;
import org.hisp.dhis.setting.SystemSettingManager;
import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.util.FileCopyUtils;
+import org.springframework.util.StreamUtils;
import javax.annotation.PostConstruct;
import java.io.File;
@@ -47,6 +49,7 @@
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
+import java.util.zip.ZipInputStream;
/**
* @author Saptarshi Purkayastha
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AppController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AppController.java 2014-01-07 11:47:11 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AppController.java 2014-01-07 12:49:31 +0000
@@ -46,10 +46,13 @@
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.RequestParam;
import org.springframework.web.bind.annotation.ResponseStatus;
+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.HashMap;
import java.util.List;
@@ -78,6 +81,20 @@
return "apps";
}
+ @RequestMapping( value = RESOURCE_PATH, method = RequestMethod.POST )
+ @ResponseStatus( HttpStatus.NO_CONTENT )
+ public void installApp( @RequestParam( "file" ) MultipartFile file, HttpServletRequest request ) throws IOException
+ {
+ File tempFile = File.createTempFile( "IMPORT_", "_ZIP" );
+ file.transferTo( tempFile );
+
+ StringBuffer fullUrl = request.getRequestURL();
+ String baseUrl = org.hisp.dhis.util.ContextUtils.getBaseUrl( request );
+ String rootPath = fullUrl.substring( 0, fullUrl.indexOf( "/", baseUrl.length() ) );
+
+ appManager.installApp( tempFile, file.getOriginalFilename(), rootPath );
+ }
+
@RequestMapping( value = RESOURCE_PATH, method = RequestMethod.PUT )
@ResponseStatus( HttpStatus.NO_CONTENT )
public void reloadApps()
=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml'
--- dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml 2013-10-21 17:13:28 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/resources/META-INF/dhis/servlet.xml 2014-01-07 12:49:31 +0000
@@ -11,6 +11,8 @@
<sec:global-method-security pre-post-annotations="enabled" />
+ <bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver" />
+
<mvc:annotation-driven>
<mvc:message-converters>
<bean class="org.hisp.dhis.api.mobile.support.DataStreamSerializableMessageConverter" />