← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11001: WIP: Upgrade app when re-installing

 

------------------------------------------------------------
revno: 11001
committer: Saptarshi <sunbiz@xxxxxxxxx>
branch nick: dhis2
timestamp: Sat 2013-05-25 18:25:22 +0200
message:
  WIP: Upgrade app when re-installing
modified:
  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/AppSettingsAction.java
  dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/DeleteAppAction.java
  dhis-2/dhis-web/dhis-web-appmanager/src/main/resources/org/hisp/dhis/appmanager/i18n_module.properties
  dhis-2/dhis-web/dhis-web-appmanager/src/main/webapp/dhis-web-appmanager/appSettings.vm
  dhis-2/dhis-web/dhis-web-appmanager/src/main/webapp/dhis-web-appmanager/getApps.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-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-05-24 12:05:28 +0000
+++ dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AddAppAction.java	2013-05-25 16:25:22 +0000
@@ -27,13 +27,18 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
 import com.opensymphony.xwork2.Action;
 import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipInputStream;
+import java.io.InputStream;
 import org.apache.ant.compress.taskdefs.Unzip;
+import org.apache.commons.io.FileUtils;
+import org.apache.tools.zip.ZipEntry;
+import org.apache.tools.zip.ZipFile;
+import org.hisp.dhis.appmanager.App;
 import org.hisp.dhis.appmanager.AppManagerService;
 import org.hisp.dhis.i18n.I18n;
 import org.hisp.dhis.security.authority.SystemAuthoritiesProvider;
@@ -49,7 +54,7 @@
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
-    
+
     @Autowired
     private AppManagerService appManagerService;
 
@@ -109,35 +114,41 @@
     {
         if ( null != file )
         {
+            // TODO: Move to AppManagerService
             if ( StreamUtils.isZip( new BufferedInputStream( new FileInputStream( file ) ) ) )
             {
-                boolean manifestFound = false;
-                ZipInputStream zis = new ZipInputStream( new FileInputStream( file ) );
-                ZipEntry ze;
-                
-                while ( (ze = zis.getNextEntry()) != null )
+                ZipFile zip = new ZipFile( file );
+                ZipEntry entry = zip.getEntry( "manifest.webapp" );
+                if ( null != entry )
                 {
-                    if ( ze.getName().equals( "manifest.webapp" ) )
+                    InputStream inputStream = zip.getInputStream( entry );
+                    String appManifest = StreamUtils.convertStreamToString( inputStream );
+                    ObjectMapper mapper = new ObjectMapper();
+                    mapper.configure( DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false );
+                    App app = mapper.readValue( appManifest, App.class );
+
+                    // Delete if app is already installed
+                    if ( appManagerService.getInstalledApps().contains( app ) )
                     {
-                        manifestFound = true;
-                        //TODO: Check duplicate app installation
-                        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();
-                        message = i18n.getString( "appmanager_install_success" );
+                        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();
+                    message = i18n.getString( "appmanager_install_success" );
                 }
-                
-                zis.close();
-                
-                if ( !manifestFound )
+                else
                 {
                     message = i18n.getString( "appmanager_invalid_package" );
                     return "failure";
                 }
+                zip.close();
             }
             else
             {
@@ -145,7 +156,7 @@
                 return "failure";
             }
         }
-        
+
         return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AppSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AppSettingsAction.java	2013-05-24 12:05:28 +0000
+++ dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AppSettingsAction.java	2013-05-25 16:25:22 +0000
@@ -60,13 +60,13 @@
     public String getAppFolderPath()
     {
         appFolderPath = appManagerService.getAppFolderPath();
-        
+
         if ( null == appFolderPath || appFolderPath.isEmpty() )
         {
             appFolderPath = ServletActionContext.getServletContext().getRealPath( "/" ) + File.separatorChar + "apps";
             appManagerService.setAppFolderPath( appFolderPath );
         }
-        
+
         return appFolderPath;
     }
 

=== modified file 'dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/DeleteAppAction.java'
--- dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/DeleteAppAction.java	2013-05-24 12:05:28 +0000
+++ dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/DeleteAppAction.java	2013-05-25 16:25:22 +0000
@@ -85,6 +85,7 @@
         String appName = ServletActionContext.getRequest().getParameter( "appName" );
         if ( null != appName )
         {
+            // TODO: Move to AppManagerService
             for ( App app : appManagerService.getInstalledApps() )
             {
                 if ( app.getName().equals( appName ) )

=== modified file 'dhis-2/dhis-web/dhis-web-appmanager/src/main/resources/org/hisp/dhis/appmanager/i18n_module.properties'
--- dhis-2/dhis-web/dhis-web-appmanager/src/main/resources/org/hisp/dhis/appmanager/i18n_module.properties	2013-05-24 12:05:28 +0000
+++ dhis-2/dhis-web/dhis-web-appmanager/src/main/resources/org/hisp/dhis/appmanager/i18n_module.properties	2013-05-25 16:25:22 +0000
@@ -12,6 +12,7 @@
 appmanager_confirm_delete=Are you sure to delete this App?
 appmanager_delete_success=App Deleted Successfully
 appmanager_management=Manage Installed Apps
+appmanager_appname=Application Name
 
 #-- See module privilegies ----------------------------------------------------#
 

=== modified file 'dhis-2/dhis-web/dhis-web-appmanager/src/main/webapp/dhis-web-appmanager/appSettings.vm'
--- dhis-2/dhis-web/dhis-web-appmanager/src/main/webapp/dhis-web-appmanager/appSettings.vm	2013-05-24 12:05:28 +0000
+++ dhis-2/dhis-web/dhis-web-appmanager/src/main/webapp/dhis-web-appmanager/appSettings.vm	2013-05-25 16:25:22 +0000
@@ -36,7 +36,7 @@
         <col/>				
         <thead>				
           <tr>
-            <th>$i18n.getString( "appname" )</th>
+            <th>$i18n.getString( "appmanager_appname" )</th>
             <th>$i18n.getString( "version" )</th>
             <th class="{sorter: false}" style="width:120px;">$i18n.getString( "operations" )</th>
           </tr>

=== modified file 'dhis-2/dhis-web/dhis-web-appmanager/src/main/webapp/dhis-web-appmanager/getApps.vm'
--- dhis-2/dhis-web/dhis-web-appmanager/src/main/webapp/dhis-web-appmanager/getApps.vm	2013-05-23 00:18:55 +0000
+++ dhis-2/dhis-web/dhis-web-appmanager/src/main/webapp/dhis-web-appmanager/getApps.vm	2013-05-25 16:25:22 +0000
@@ -14,4 +14,6 @@
         <div id="progressbar"></div>
     </div>
 </div>
-<iframe src="$appStoreUrl" seamless="true" style="width: 100%; height: 500px; border: none;"></iframe> 
\ No newline at end of file
+#if( $!appStoreUrl )
+<iframe src="$appStoreUrl" seamless="true" style="width: 100%; height: 500px; border: none;"></iframe> 
+#end
\ No newline at end of file