dhis2-devs team mailing list archive
-
dhis2-devs team
-
Mailing list archive
-
Message #27350
[Branch ~dhis2-devs-core/dhis2/trunk] Rev 13606: allow deletion of app with DELETE /api/apps/<app-name>
------------------------------------------------------------
revno: 13606
committer: Morten Olav Hansen <mortenoh@xxxxxxxxx>
branch nick: dhis2
timestamp: Tue 2014-01-07 12:00:46 +0100
message:
allow deletion of app with DELETE /api/apps/<app-name>
modified:
dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppManager.java
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
--
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/AppManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppManager.java 2014-01-07 10:21:09 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppManager.java 2014-01-07 11:00:46 +0000
@@ -84,6 +84,14 @@
throws IOException;
/**
+ * Does the app with name appName exist?
+ *
+ * @param appName
+ * @return
+ */
+ boolean exists( String appName );
+
+ /**
* Deletes the app with the given name.
*
* @param name the app name.
=== 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 10:21:09 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/appmanager/DefaultAppManager.java 2014-01-07 11:00:46 +0000
@@ -28,16 +28,8 @@
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-import java.io.File;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.List;
-import java.util.zip.ZipEntry;
-import java.util.zip.ZipFile;
-
-import javax.annotation.PostConstruct;
-
+import com.fasterxml.jackson.databind.DeserializationFeature;
+import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.ant.compress.taskdefs.Unzip;
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
@@ -47,8 +39,14 @@
import org.hisp.dhis.setting.SystemSettingManager;
import org.springframework.beans.factory.annotation.Autowired;
-import com.fasterxml.jackson.databind.DeserializationFeature;
-import com.fasterxml.jackson.databind.ObjectMapper;
+import javax.annotation.PostConstruct;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipFile;
/**
* @author Saptarshi Purkayastha
@@ -67,10 +65,10 @@
private void init()
{
reloadApps();
-
+
log.info( "Detecting apps: " + apps );
}
-
+
@Autowired
private SystemSettingManager appSettingManager;
@@ -94,15 +92,15 @@
public List<App> getApps()
{
String baseUrl = getAppBaseUrl();
-
+
for ( App app : apps )
{
app.setBaseUrl( baseUrl );
}
-
+
return apps;
}
-
+
@Override
public void installApp( File file, String fileName, String rootPath )
throws IOException
@@ -116,7 +114,7 @@
App app = mapper.readValue( inputStream, App.class );
// Delete if app is already installed
-
+
if ( getApps().contains( app ) )
{
String folderPath = getAppFolderPath() + File.separator + app.getFolderName();
@@ -130,7 +128,7 @@
unzip.execute();
// Updating dhis server location
-
+
File updateManifest = new File( dest + File.separator + "manifest.webapp" );
App installedApp = mapper.readValue( updateManifest, App.class );
@@ -141,20 +139,34 @@
}
zip.close();
-
+
reloadApps(); // Reload app state
}
@Override
+ public boolean exists( String appName )
+ {
+ for ( App app : getApps() )
+ {
+ if ( app.getName().equals( appName ) || app.getFolderName().equals( appName ) )
+ {
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ @Override
public boolean deleteApp( String name )
{
for ( App app : getApps() )
{
- if ( app.getName().equals( name ) )
+ if ( app.getName().equals( name ) || app.getFolderName().equals( name ) )
{
try
{
- String folderPath = getAppFolderPath() + File.separator + app.getFolderName();
+ String folderPath = getAppFolderPath() + File.separator + app.getFolderName();
FileUtils.forceDelete( new File( folderPath ) );
return true;
=== 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 09:55:49 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/api/controller/AppController.java 2014-01-07 11:00:46 +0000
@@ -31,6 +31,7 @@
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.common.collect.Lists;
import org.hisp.dhis.api.controller.exception.NotFoundException;
+import org.hisp.dhis.api.utils.ContextUtils;
import org.hisp.dhis.appmanager.App;
import org.hisp.dhis.appmanager.AppManager;
import org.hisp.dhis.dxf2.utils.JacksonUtils;
@@ -115,6 +116,24 @@
StreamUtils.copy( page.getInputStream(), response.getOutputStream() );
}
+ @RequestMapping( value = "/apps/{app}", method = RequestMethod.DELETE )
+ public void deleteApp( @PathVariable( "app" ) String app, HttpServletRequest request, HttpServletResponse response ) throws NotFoundException
+ {
+ if ( !appManager.exists( app ) )
+ {
+ ContextUtils.notFoundResponse( response, "App does not exist: " + app );
+ }
+
+ if ( !appManager.deleteApp( app ) )
+ {
+ ContextUtils.conflictResponse( response, "There was an error deleting app: " + app );
+ }
+ }
+
+ //--------------------------------------------------------------------------
+ // Helpers
+ //--------------------------------------------------------------------------
+
private Resource findResource( Iterable<Resource> locations, String resourceName ) throws IOException
{
for ( Resource location : locations )