← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 21504: App store. Moved status messages to enum. Avoids switch clause.

 

------------------------------------------------------------
revno: 21504
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Mon 2015-12-21 21:17:43 +0100
message:
  App store. Moved status messages to enum. Avoids switch clause.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppManager.java
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppStatus.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-api/src/main/java/org/hisp/dhis/appmanager/AppManager.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppManager.java	2015-10-09 21:21:12 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppManager.java	2015-12-21 20:17:43 +0000
@@ -59,6 +59,11 @@
      */
     App getApp( String key );
 
+    /**
+     * Returns apps which are accessible to the current user.
+     * 
+     * @return apps which are accessible to the current user.
+     */
     List<App> getAccessibleApps();
 
     /**
@@ -138,8 +143,21 @@
      */
     void setAppStoreUrl( String appStoreUrl );
 
+    /**
+     * Indicates whether the given app is accessible to the current user.
+     * 
+     * @param app the app.
+     * @return true if app is accessible.
+     */
     boolean isAccessible( App app );
 
+    /**
+     * Indicates whether the given app is accessible to the given user.
+     * 
+     * @param app the app.
+     * @param user the user.
+     * @return true if app is accessible.
+     */
     boolean isAccessible( App app, User user );
 
     /**
@@ -148,5 +166,4 @@
      * @return App or null
      */
     App getAppByNamespace( String namespace);
-
 }

=== modified file 'dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppStatus.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppStatus.java	2015-10-14 04:44:58 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppStatus.java	2015-12-21 20:17:43 +0000
@@ -30,5 +30,26 @@
 
 public enum AppStatus
 {
-    OK, NAMESPACE_TAKEN, INVALID_ZIP_FORMAT, INVALID_MANIFEST_JSON, INSTALLATION_FAILED
+    OK( "OK" ), 
+    NAMESPACE_TAKEN( "Namespace defined in manifest is protected" ), 
+    INVALID_ZIP_FORMAT( "Zipfile could not be read" ), 
+    INVALID_MANIFEST_JSON( "Invalid JSON in app manifest file" ), 
+    INSTALLATION_FAILED( "App could not be installed on file system" );
+    
+    private String message;
+    
+    AppStatus( String message )
+    {
+        this.message = message;
+    }
+
+    public boolean ok()
+    {
+        return this == OK;
+    }
+    
+    public String getMessage()
+    {
+        return message;
+    }
 }

=== 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-08 19:33:06 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppController.java	2015-12-21 20:17:43 +0000
@@ -33,6 +33,7 @@
 import org.apache.commons.lang3.StringUtils;
 import org.hisp.dhis.appmanager.App;
 import org.hisp.dhis.appmanager.AppManager;
+import org.hisp.dhis.appmanager.AppStatus;
 import org.hisp.dhis.dxf2.render.DefaultRenderService;
 import org.hisp.dhis.dxf2.render.RenderService;
 import org.hisp.dhis.dxf2.webmessage.WebMessageException;
@@ -125,22 +126,11 @@
 
         String contextPath = ContextUtils.getContextPath( request );
 
-        switch ( appManager.installApp( tempFile, file.getOriginalFilename(), contextPath ) )
+        AppStatus status = appManager.installApp( tempFile, file.getOriginalFilename(), contextPath );
+        
+        if ( !status.ok() )
         {
-        case OK:
-            break;
-        case NAMESPACE_TAKEN:
-            throw new WebMessageException(
-                WebMessageUtils.conflict( "The namespace defined in manifest.webapp is already protected." ) );
-        case INVALID_ZIP_FORMAT:
-            throw new WebMessageException(
-                WebMessageUtils.unprocessableEntity( "Zip-file could not be read." ) );
-        case INVALID_MANIFEST_JSON:
-            throw new WebMessageException(
-                WebMessageUtils.conflict( "Invalid JSON in app manifest file." ) );
-        case INSTALLATION_FAILED:
-            throw new WebMessageException(
-                WebMessageUtils.conflict( "App could not be installed on file system, check permissions." ) );
+            throw new WebMessageException( WebMessageUtils.conflict( status.getMessage() ) );
         }
     }
 
@@ -283,7 +273,7 @@
     }
 
     @RequestMapping( value = "/appStore", method = RequestMethod.GET, produces = "application/json" )
-    public @ResponseBody String getAppStoreUrl()
+    public @ResponseBody String getAppStore()
     {
         return restTemplate.getForObject( SettingKey.APP_STORE_INDEX_URL.getDefaultValue().toString(), String.class );
     }