dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #24923
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 12262: Apps, moved installation code to service layer
------------------------------------------------------------
revno: 12262
committer: Lars Helge Øverland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Thu 2013-09-26 18:34:42 +0200
message:
Apps, moved installation code to service layer
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppManagerService.java
dhis-2/dhis-services/dhis-service-core/pom.xml
dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/appmanager/DefaultAppManagerService.java
dhis-2/dhis-web/dhis-web-appmanager/pom.xml
dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AddAppAction.java
dhis-2/pom.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-api/src/main/java/org/hisp/dhis/appmanager/AppManagerService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppManagerService.java 2013-09-26 15:30:50 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppManagerService.java 2013-09-26 16:34:42 +0000
@@ -28,6 +28,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
+import java.io.File;
+import java.io.IOException;
import java.util.List;
/**
@@ -69,6 +71,16 @@
List<App> getInstalledApps();
/**
+ * Installs the app.
+ * @param file the app file.
+ * @param fileName the name of the app file.
+ * @param rootPath the root path of the instance.
+ * @throws IOException if the app manifest file could not be read.
+ */
+ void installApp( File file, String fileName, String rootPath )
+ throws IOException;
+
+ /**
* Deletes the app with the given name.
* @param name the app name.
* @return true if the delete was successful, false if there is no app with
=== modified file 'dhis-2/dhis-services/dhis-service-core/pom.xml'
--- dhis-2/dhis-services/dhis-service-core/pom.xml 2013-09-04 09:35:03 +0000
+++ dhis-2/dhis-services/dhis-service-core/pom.xml 2013-09-26 16:34:42 +0000
@@ -81,6 +81,10 @@
<groupId>org.aspectj</groupId>
<artifactId>aspectjweaver</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.ant</groupId>
+ <artifactId>ant-compress</artifactId>
+ </dependency>
<!-- SMS -->
=== modified file 'dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/appmanager/DefaultAppManagerService.java'
--- dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/appmanager/DefaultAppManagerService.java 2013-09-26 15:30:50 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/appmanager/DefaultAppManagerService.java 2013-09-26 16:34:42 +0000
@@ -32,9 +32,14 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import java.io.File;
import java.io.IOException;
+import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
+
+import org.apache.ant.compress.taskdefs.Unzip;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
@@ -108,6 +113,46 @@
return appList;
}
+ public void installApp( File file, String fileName, String rootPath )
+ throws IOException
+ {
+ ZipFile zip = new ZipFile( file );
+ ZipEntry entry = zip.getEntry( "manifest.webapp" );
+
+ InputStream inputStream = zip.getInputStream( entry );
+ ObjectMapper mapper = new ObjectMapper();
+ mapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false );
+ App app = mapper.readValue( inputStream, App.class );
+
+ // Delete if app is already installed
+
+ if ( getInstalledApps().contains( app ) )
+ {
+ String folderPath = getAppFolderPath() + File.separator
+ + getAppFolderName( app );
+ FileUtils.forceDelete( new File( folderPath ) );
+ }
+
+ String dest = getAppFolderPath() + File.separator + fileName.substring( 0, fileName.lastIndexOf( '.' ) );
+ Unzip unzip = new Unzip();
+ unzip.setSrc( file );
+ unzip.setDest( new File( dest ) );
+ unzip.execute();
+
+ // Updating dhis server location
+
+ File updateManifest = new File( dest + File.separator + "manifest.webapp" );
+ App installedApp = mapper.readValue( updateManifest, App.class );
+
+ if ( installedApp.getActivities().getDhis().getHref().equals( "*" ) )
+ {
+ installedApp.getActivities().getDhis().setHref( rootPath );
+ mapper.writeValue( updateManifest, installedApp );
+ }
+
+ zip.close();
+ }
+
public boolean deleteApp( String name )
{
for ( App app : getInstalledApps() )
=== modified file 'dhis-2/dhis-web/dhis-web-appmanager/pom.xml'
--- dhis-2/dhis-web/dhis-web-appmanager/pom.xml 2013-09-19 14:01:30 +0000
+++ dhis-2/dhis-web/dhis-web-appmanager/pom.xml 2013-09-26 16:34:42 +0000
@@ -25,7 +25,6 @@
<dependency>
<groupId>org.apache.ant</groupId>
<artifactId>ant-compress</artifactId>
- <version>1.2</version>
</dependency>
<!-- DHIS -->
=== modified file 'dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AddAppAction.java'
--- dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AddAppAction.java 2013-09-26 16:21:22 +0000
+++ dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AddAppAction.java 2013-09-26 16:34:42 +0000
@@ -31,18 +31,14 @@
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
-import java.io.InputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
import javax.servlet.http.HttpServletRequest;
-import org.apache.ant.compress.taskdefs.Unzip;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.struts2.ServletActionContext;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-import org.hisp.dhis.appmanager.App;
import org.hisp.dhis.appmanager.AppManagerService;
import org.hisp.dhis.i18n.I18n;
import org.hisp.dhis.system.util.StreamUtils;
@@ -50,8 +46,6 @@
import org.springframework.beans.factory.annotation.Autowired;
import com.fasterxml.jackson.core.JsonParseException;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
import com.opensymphony.xwork2.Action;
/**
@@ -145,40 +139,8 @@
try
{
- InputStream inputStream = zip.getInputStream( entry );
- ObjectMapper mapper = new ObjectMapper();
- mapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false );
- App app = mapper.readValue( inputStream, App.class );
-
- // Delete if app is already installed
- if ( appManagerService.getInstalledApps().contains( app ) )
- {
- String folderPath = appManagerService.getAppFolderPath() + File.separator
- + appManagerService.getAppFolderName( app );
- FileUtils.forceDelete( new File( folderPath ) );
- }
-
- String dest = appManagerService.getAppFolderPath() + File.separator
- + fileName.substring( 0, fileName.lastIndexOf( '.' ) );
- Unzip unzip = new Unzip();
- unzip.setSrc( file );
- unzip.setDest( new File( dest ) );
- unzip.execute();
-
- // Updating dhis server location
- File updateManifest = new File( dest + File.separator + "manifest.webapp" );
- App installedApp = mapper.readValue( updateManifest, App.class );
-
- if ( installedApp.getActivities().getDhis().getHref().equals( "*" ) )
- {
- // TODO: Check why ContextUtils.getContextPath is not working
- String rootPath = getRootPath();
-
- installedApp.getActivities().getDhis().setHref( rootPath );
- mapper.writeValue( updateManifest, installedApp );
- }
-
- zip.close();
+ appManagerService.installApp( file, fileName, getRootPath() );
+
message = i18n.getString( "appmanager_install_success" );
}
catch ( JsonParseException ex )
=== modified file 'dhis-2/pom.xml'
--- dhis-2/pom.xml 2013-09-26 13:17:01 +0000
+++ dhis-2/pom.xml 2013-09-26 16:34:42 +0000
@@ -573,6 +573,11 @@
<version>2.4</version>
<classifier>jdk15</classifier>
</dependency>
+ <dependency>
+ <groupId>org.apache.ant</groupId>
+ <artifactId>ant-compress</artifactId>
+ <version>1.2</version>
+ </dependency>
<!-- Apache Commons -->
<dependency>
<groupId>commons-collections</groupId>