← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 18034: Apps. Made apps served by default by the web api resource. Added config method on apps resource.

 

------------------------------------------------------------
revno: 18034
committer: Lars Helge Overland <larshelge@xxxxxxxxx>
branch nick: dhis2
timestamp: Fri 2015-01-16 20:07:36 +0100
message:
  Apps. Made apps served by default by the web api resource. Added config method on apps resource.
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppManager.java
  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/user/UserController.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AppSettingsAction.java
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/resources/struts.xml
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/webapp/dhis-web-maintenance-appmanager/appSettings.vm
  dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/webapp/dhis-web-maintenance-appmanager/javascript/deleteApp.js


--
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-12-16 13:31:39 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppManager.java	2015-01-16 19:07:36 +0000
@@ -45,6 +45,8 @@
     final String KEY_APP_BASE_URL = "appBaseUrl";
     final String KEY_APP_STORE_URL = "appStoreUrl";
     final String DEFAULT_APP_STORE_URL = "http://www.dhis2.org/appstore";;
+    final String APPS_DIR = "/apps";
+    final String APPS_API_PATH = "/api/apps";
 
     /**
      * Returns a list of all the installed apps at @see getAppFolderPath

=== 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-01-16 17:19:19 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/AppController.java	2015-01-16 19:07:36 +0000
@@ -32,10 +32,12 @@
 import java.io.IOException;
 import java.util.Date;
 import java.util.List;
+import java.util.Map;
 
 import javax.servlet.http.HttpServletRequest;
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.hisp.dhis.appmanager.App;
@@ -205,6 +207,38 @@
         }
     }
 
+    @SuppressWarnings( "unchecked" )
+    @RequestMapping( value = "/config", method = RequestMethod.POST, consumes = ContextUtils.CONTENT_TYPE_JSON )
+    @PreAuthorize( "hasRole('ALL') or hasRole('M_dhis-web-maintenance-appmanager')" )
+    public void setConfig( HttpServletRequest request, HttpServletResponse response ) throws IOException
+    {
+        Map<String, String> config = renderService.fromJson( request.getInputStream(), Map.class );
+        
+        if ( config == null )
+        {
+            ContextUtils.conflictResponse( response, "No config specified" );
+        }
+        
+        String appBaseUrl = StringUtils.trimToNull( config.get( AppManager.KEY_APP_BASE_URL ) );
+        String appFolderPath = StringUtils.trimToNull( config.get( AppManager.KEY_APP_FOLDER_PATH ) );
+        String appStoreUrl = StringUtils.trimToNull( config.get( AppManager.KEY_APP_STORE_URL ) );
+        
+        if ( appBaseUrl != null )
+        {
+            appManager.setAppBaseUrl( appBaseUrl );
+        }
+        
+        if ( appFolderPath != null )
+        {
+            appManager.setAppFolderPath( appFolderPath );
+        }
+        
+        if ( appStoreUrl != null )
+        {
+            appManager.setAppStoreUrl( appStoreUrl );
+        }
+    }    
+
     //--------------------------------------------------------------------------
     // Helpers
     //--------------------------------------------------------------------------

=== modified file 'dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java'
--- dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java	2015-01-15 09:59:03 +0000
+++ dhis-2/dhis-web/dhis-web-api/src/main/java/org/hisp/dhis/webapi/controller/user/UserController.java	2015-01-16 19:07:36 +0000
@@ -261,7 +261,7 @@
         }
     }
 
-    @SuppressWarnings("unchecked")
+    @SuppressWarnings( "unchecked" )
     @PreAuthorize( "hasRole('ALL')" )
     @RequestMapping( value = "/{uid}/replica", method = RequestMethod.POST )
     public void replicateUser( @PathVariable String uid, 
@@ -280,7 +280,7 @@
             return;
         }
         
-        Map<String, String> auth = renderService.fromJson( request.getInputStream(),Map.class );
+        Map<String, String> auth = renderService.fromJson( request.getInputStream(), Map.class );
 
         String username = StringUtils.trimToNull( auth != null ? auth.get( KEY_USERNAME ) : null );
         String password = StringUtils.trimToNull( auth != null ? auth.get( KEY_PASSWORD ) : null );

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AppSettingsAction.java'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AppSettingsAction.java	2015-01-16 17:29:56 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AppSettingsAction.java	2015-01-16 19:07:36 +0000
@@ -28,19 +28,16 @@
  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  */
 
-import com.opensymphony.xwork2.Action;
+import java.util.List;
 
 import org.apache.struts2.ServletActionContext;
 import org.hisp.dhis.appmanager.App;
 import org.hisp.dhis.appmanager.AppManager;
-import org.hisp.dhis.i18n.I18n;
+import org.hisp.dhis.external.location.LocationManager;
 import org.hisp.dhis.webapi.utils.ContextUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 
-import javax.servlet.http.HttpServletRequest;
-
-import java.io.File;
-import java.util.List;
+import com.opensymphony.xwork2.Action;
 
 /**
  * @author Saptarshi Purkayastha
@@ -48,14 +45,15 @@
 public class AppSettingsAction
     implements Action
 {
-    boolean isSaved;
-
     // -------------------------------------------------------------------------
     // Dependencies
     // -------------------------------------------------------------------------
 
     @Autowired
     private AppManager appManager;
+    
+    @Autowired
+    private LocationManager locationManager;
 
     // -------------------------------------------------------------------------
     // Input & Output
@@ -65,88 +63,23 @@
 
     public String getAppFolderPath()
     {
-        appFolderPath = appManager.getAppFolderPath();
-
-        if ( appFolderPath == null || appFolderPath.isEmpty() )
-        {
-            String realPath = ServletActionContext.getServletContext().getRealPath( "/" );
-            
-            if ( realPath.endsWith( "/" ) || realPath.endsWith( "\\" ) )
-            {
-                appFolderPath = realPath + "apps";
-            }
-            else
-            {
-                appFolderPath = realPath + File.separatorChar + "apps";
-            }
-
-            appManager.setAppFolderPath( appFolderPath );
-        }
-
         return appFolderPath;
     }
 
-    public void setAppFolderPath( String appFolderPath )
-    {
-        isSaved = true;
-        appManager.setAppFolderPath( appFolderPath );
-    }
-
     private String appBaseUrl;
 
     public String getAppBaseUrl()
     {
-        appBaseUrl = appManager.getAppBaseUrl();
-
-        if ( appBaseUrl == null || appBaseUrl.isEmpty() )
-        {
-            HttpServletRequest request = ServletActionContext.getRequest();
-            String realPath = ServletActionContext.getServletContext().getRealPath( "/" );
-            String appsPath = appManager.getAppFolderPath();
-            String baseUrl = ContextUtils.getBaseUrl( request );
-            String contextPath = request.getContextPath();
-
-            if ( !contextPath.isEmpty() )
-            {
-                appBaseUrl = baseUrl.substring( 0, baseUrl.length() - 1 ) + request.getContextPath() + "/"
-                    + ( ( appsPath.replace( "//", "/" ) ).replace( realPath, "" ) ).replace( '\\', '/' );
-            }
-            else
-            {
-                appBaseUrl = baseUrl.substring( 0, baseUrl.length() - 1 )
-                    + ( ( appsPath.replace( "//", "/" ) ).replace( realPath, "" ) ).replace( '\\', '/' );
-            }
-
-            appManager.setAppBaseUrl( appBaseUrl );
-        }
-
         return appBaseUrl;
     }
 
-    public void setAppBaseUrl( String appBaseUrl )
-    {
-        appManager.setAppBaseUrl( appBaseUrl );
-    }
+    private List<App> appList;
 
     public List<App> getAppList()
     {
-        return appManager.getApps();
-    }
-
-    private I18n i18n;
-
-    public void setI18n( I18n i18n )
-    {
-        this.i18n = i18n;
-    }
-
-    private String message;
-
-    public String getMessage()
-    {
-        return message;
-    }
-
+        return appList;
+    }
+    
     // -------------------------------------------------------------------------
     // Action implementation
     // -------------------------------------------------------------------------
@@ -154,9 +87,27 @@
     @Override
     public String execute()
     {
-        message = i18n.getString( "appmanager_saved_settings" );
+        appFolderPath = appManager.getAppFolderPath();
+
+        if ( appFolderPath == null || appFolderPath.isEmpty() )
+        {
+            appFolderPath = locationManager.getExternalDirectoryPath() + AppManager.APPS_DIR;            
+            appManager.setAppFolderPath( appFolderPath );
+        }
+        
+        appBaseUrl = appManager.getAppBaseUrl();
+
+        if ( appBaseUrl == null || appBaseUrl.isEmpty() )
+        {
+            String contextPath = ContextUtils.getContextPath( ServletActionContext.getRequest() );
+            appBaseUrl = contextPath + AppManager.APPS_API_PATH;
+            appManager.setAppBaseUrl( appBaseUrl );
+        }
+                
         appManager.reloadApps();
 
-        return isSaved ? SUCCESS : "getSuccess";
+        appList = appManager.getApps();
+        
+        return SUCCESS;
     }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/resources/struts.xml'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/resources/struts.xml	2013-10-14 15:10:19 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/resources/struts.xml	2015-01-16 19:07:36 +0000
@@ -37,8 +37,7 @@
     </action>
     
     <action name="appSettings" class="org.hisp.dhis.appmanager.action.AppSettingsAction">
-      <result name="success" type="velocity-json">/dhis-web-commons/ajax/jsonResponseSuccess.vm</result>
-      <result name="getSuccess" type="velocity">/main.vm</result>
+      <result name="success" type="velocity">/main.vm</result>
       <param name="page">/dhis-web-maintenance-appmanager/appSettings.vm</param>
       <param name="menu">/dhis-web-maintenance-appmanager/menu.vm</param>
       <param name="onExceptionReturn">plainTextError</param>

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/webapp/dhis-web-maintenance-appmanager/appSettings.vm'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/webapp/dhis-web-maintenance-appmanager/appSettings.vm	2015-01-16 16:44:06 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/webapp/dhis-web-maintenance-appmanager/appSettings.vm	2015-01-16 19:07:36 +0000
@@ -28,13 +28,11 @@
   </ul>
 </div>
 
-<form id="appSettingsForm" action="appSettings.action" method="post">
 <div class="settingLabel">$i18n.getString( "appmanager_installation_folder" ) <span class="tipText">($i18n.getString( "appmanager_absolute_server_path" ))</span></div>
 <div class="setting"><input type="text" id="appFolderPath" name="appFolderPath" style="width:40em" value="$!appFolderPath"/></div>
 <div class="settingLabel">$i18n.getString( "appmanager_baseurl" ) <span class="tipText">($i18n.getString( "appmanager_where_apps_can_be_found" ))</span></div>
 <div class="setting"><input type="text" id="appBaseUrl" name="appBaseUrl" style="width:40em" value="$!appBaseUrl"/></div>
-<div><input type="submit" value="Save" style="width:120px" /></div>
-</form>
+<div><input type="button" value="Save" style="width:120px" onclick="setAppConfig()" /></div>
 
 <h3>$i18n.getString( "appmanager_management" )</h3>
 

=== modified file 'dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/webapp/dhis-web-maintenance-appmanager/javascript/deleteApp.js'
--- dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/webapp/dhis-web-maintenance-appmanager/javascript/deleteApp.js	2014-03-02 06:45:58 +0000
+++ dhis-2/dhis-web/dhis-web-maintenance/dhis-web-maintenance-appmanager/src/main/webapp/dhis-web-maintenance-appmanager/javascript/deleteApp.js	2015-01-16 19:07:36 +0000
@@ -2,3 +2,22 @@
 function deleteApp( appId, appName ) {
   removeItem(appId, appName, i18n_confirm_delete, "deleteApp.action?appName=" + appName);
 }
+
+function setAppConfig() {
+	
+	var config = {
+		appFolderPath: $( "#appFolderPath" ).val(),
+		appBaseUrl: $( "#appBaseUrl" ).val()
+	};
+	
+	$.ajax( {
+		url: "../api/apps/config",
+		type: "post",
+		contentType: "application/json",
+		data: JSON.stringify( config )
+	} ).done( function() {
+		setHeaderDelayMessage( "Settings updated" );
+	} ).fail( function( xhr, text, error ) {
+		setHeaderDelayMessage( xhr.responseText );
+	} );	
+}
\ No newline at end of file