← Back to team overview

dhis2-devs team mailing list archive

[Branch ~dhis2-devs-core/dhis2/trunk] Rev 11096: Added baseUrl to allow hosting apps outside DHIS

 

------------------------------------------------------------
revno: 11096
committer: Saptarshi <sunbiz@xxxxxxxxx>
branch nick: dhis2
timestamp: Wed 2013-05-29 23:29:34 +0200
message:
  Added baseUrl to allow hosting apps outside DHIS
added:
  dhis-2/dhis-web/dhis-web-appmanager/src/test/
  dhis-2/dhis-web/dhis-web-appmanager/src/test/java/
modified:
  dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppManagerService.java
  dhis-2/dhis-api/src/test/java/org/hisp/dhis/appmanager/AppTest.java
  dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/appmanager/DefaultAppManagerService.java
  dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AppListAction.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/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/index.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-api/src/main/java/org/hisp/dhis/appmanager/AppManagerService.java'
--- dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppManagerService.java	2013-05-23 00:18:55 +0000
+++ dhis-2/dhis-api/src/main/java/org/hisp/dhis/appmanager/AppManagerService.java	2013-05-29 21:29:34 +0000
@@ -38,9 +38,17 @@
     String ID = AppManagerService.class.getName();
 
     final String KEY_APP_FOLDER_PATH = "appFolderPath";
+    
+    final String KEY_APP_BASE_URL = "appBaseUrl";
 
     final String KEY_APP_STORE_URL = "appStoreUrl";
-
+    
+    /**
+     * Gets the Base URL for accessing the apps
+     * @return the apps baseurl
+     */
+    String getAppBaseUrl();
+    
     /**
      * Returns the full path to the folder where apps are extracted
      * @return app folder path 
@@ -68,12 +76,20 @@
 
     /**
      * Saves the folder in which apps will be expanded 
+     * @param appFolderPath
      */
     void setAppFolderPath( String appFolderPath );
 
     /**
      * Saves the URL of the apps repository
+     * @param appStoreUrl
      */
     void setAppStoreUrl( String appStoreUrl );
+    
+    /**
+     * Saves the base URL where apps are installed
+     * @param appBaseUrl 
+     */
+    void setAppBaseUrl( String appBaseUrl );
 
 }

=== modified file 'dhis-2/dhis-api/src/test/java/org/hisp/dhis/appmanager/AppTest.java'
--- dhis-2/dhis-api/src/test/java/org/hisp/dhis/appmanager/AppTest.java	2013-05-26 15:07:15 +0000
+++ dhis-2/dhis-api/src/test/java/org/hisp/dhis/appmanager/AppTest.java	2013-05-29 21:29:34 +0000
@@ -65,33 +65,33 @@
     @Test
     public void testRequiredProperties()
     {
-        Assert.assertEquals( app.getVersion(), "0.1" );
-        Assert.assertEquals( app.getName(), "Test App" );
-        Assert.assertEquals( app.getLaunchPath(), "/index.html" );
-        Assert.assertEquals( app.getInstallsAllowedFrom()[0], "*" );
-        Assert.assertEquals( app.getDefaultLocale(), "en" );
+        Assert.assertEquals( "0.1", app.getVersion() );
+        Assert.assertEquals( "Test App", app.getName() );
+        Assert.assertEquals( "/index.html", app.getLaunchPath() );
+        Assert.assertEquals( "*", app.getInstallsAllowedFrom()[0] );
+        Assert.assertEquals( "en", app.getDefaultLocale() );
     }
 
     // TODO: Complete test for skipped optional properties 
     @Test
     public void testOptionalProperties()
     {
-        Assert.assertEquals( app.getDescription(), "Test Description" );
+        Assert.assertEquals( "Test Description", app.getDescription() );
     }
 
     @Test
     public void testIcons()
     {
-        Assert.assertEquals( app.getIcons().getIcon16(), "/img/icons/mortar-16.png" );
-        Assert.assertEquals( app.getIcons().getIcon48(), "/img/icons/mortar-48.png" );
-        Assert.assertEquals( app.getIcons().getIcon128(), "/img/icons/mortar-128.png" );
+        Assert.assertEquals( "/img/icons/mortar-16.png", app.getIcons().getIcon16() );
+        Assert.assertEquals( "/img/icons/mortar-48.png", app.getIcons().getIcon48() );
+        Assert.assertEquals( "/img/icons/mortar-128.png", app.getIcons().getIcon128() );
     }
 
     @Test
     public void testDeveloper()
     {
-        Assert.assertEquals( app.getDeveloper().getName(), "Test Developer" );
-        Assert.assertEquals( app.getDeveloper().getUrl(), "http://test"; );
+        Assert.assertEquals( "Test Developer", app.getDeveloper().getName() );
+        Assert.assertEquals( "http://test";, app.getDeveloper().getUrl() );
         Assert.assertNull( app.getDeveloper().getEmail() );
         Assert.assertNull( app.getDeveloper().getCompany() );
     }
@@ -100,9 +100,9 @@
     public void testActivities()
     {
         AppDhis dhisActivity = app.getActivities().getDhis();
-        Assert.assertEquals( dhisActivity.getHref(), "http://localhost:8080/dhis"; );
+        Assert.assertEquals( "http://localhost:8080/dhis";, dhisActivity.getHref() );
         dhisActivity.setHref("ALL TEST");
-        Assert.assertEquals( dhisActivity.getHref(), "ALL TEST" );
+        Assert.assertEquals( "ALL TEST", dhisActivity.getHref() );
     }
     
 }

=== 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-05-28 15:50:33 +0000
+++ dhis-2/dhis-services/dhis-service-core/src/main/java/org/hisp/dhis/appmanager/DefaultAppManagerService.java	2013-05-29 21:29:34 +0000
@@ -144,4 +144,14 @@
         
         return appFolderNames.get( app );
     }
+
+    @Override
+    public String getAppBaseUrl() {
+        return StringUtils.trimToNull( (String) appSettingManager.getSystemSetting( KEY_APP_BASE_URL ) );
+    }
+
+    @Override
+    public void setAppBaseUrl(String appBaseUrl) {
+        appSettingManager.saveSystemSetting( KEY_APP_BASE_URL, appBaseUrl );
+    }
 }

=== modified file 'dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AppListAction.java'
--- dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AppListAction.java	2013-05-28 15:50:33 +0000
+++ dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AppListAction.java	2013-05-29 21:29:34 +0000
@@ -35,9 +35,6 @@
 import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
-import javax.servlet.http.HttpServletRequest;
-import org.apache.struts2.ServletActionContext;
-import org.hisp.dhis.util.ContextUtils;
 
 /**
  * @author Saptarshi Purkayastha
@@ -76,22 +73,7 @@
 
     public String getAppsRootUrl()
     {
-        HttpServletRequest request = ServletActionContext.getRequest();
-        String realPath = ServletActionContext.getServletContext().getRealPath( "/" );
-        String appFolderPath = appManagerService.getAppFolderPath();
-        String baseUrl = ContextUtils.getBaseUrl( request );
-        String contextPath = request.getContextPath();
-        if ( !contextPath.isEmpty() )
-        {
-            appsRootUrl = baseUrl.substring( 0, baseUrl.length() - 1 ) + request.getContextPath() + "/"
-                + ((appFolderPath.replace( "//", "/" )).replace( realPath, "" )).replace( '\\', '/' );
-        }
-        else
-        {
-            appsRootUrl = baseUrl.substring( 0, baseUrl.length() - 1 )
-                + ((appFolderPath.replace( "//", "/" )).replace( realPath, "" )).replace( '\\', '/' );
-        }
-        return appsRootUrl;
+        return appManagerService.getAppBaseUrl();
     }
 
     // -------------------------------------------------------------------------

=== 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-28 15:50:33 +0000
+++ dhis-2/dhis-web/dhis-web-appmanager/src/main/java/org/hisp/dhis/appmanager/action/AppSettingsAction.java	2013-05-29 21:29:34 +0000
@@ -37,6 +37,8 @@
 import org.springframework.beans.factory.annotation.Autowired;
 
 import com.opensymphony.xwork2.Action;
+import javax.servlet.http.HttpServletRequest;
+import org.hisp.dhis.util.ContextUtils;
 
 /**
  * @author Saptarshi Purkayastha
@@ -86,6 +88,42 @@
         appManagerService.setAppFolderPath( appFolderPath );
     }
 
+    private String appBaseUrl;
+
+    public String getAppBaseUrl()
+    {
+        appBaseUrl = appManagerService.getAppBaseUrl();
+
+        if ( null == appBaseUrl || appBaseUrl.isEmpty() )
+        {
+            HttpServletRequest request = ServletActionContext.getRequest();
+            String realPath = ServletActionContext.getServletContext().getRealPath( "/" );
+            String appsPath = appManagerService.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( '\\', '/' );
+            }
+
+            appManagerService.setAppBaseUrl( appBaseUrl );
+        }
+
+        return appBaseUrl;
+    }
+
+    public void setAppBaseUrl( String appBaseUrl )
+    {
+        appManagerService.setAppBaseUrl( appBaseUrl );
+    }
+
     private String appStoreUrl;
 
     public String getAppStoreUrl()

=== 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-28 08:27:16 +0000
+++ dhis-2/dhis-web/dhis-web-appmanager/src/main/resources/org/hisp/dhis/appmanager/i18n_module.properties	2013-05-29 21:29:34 +0000
@@ -3,6 +3,7 @@
 appmanager_go=Get New Apps
 appmanager_saved_settings=Saved Settings 
 appmanager_installation_folder=App Installation Folder:
+appmanager_baseurl=App Base URL:
 appmanager_store_url=AppStore URL:
 appmanager_upload_app_package=Upload App Package (zip)
 appmanager_install_success=App Installed Successfully

=== 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-25 16:25:22 +0000
+++ dhis-2/dhis-web/dhis-web-appmanager/src/main/webapp/dhis-web-appmanager/appSettings.vm	2013-05-29 21:29:34 +0000
@@ -19,6 +19,10 @@
       <td><input type="text" id="appFolderPath" name="appFolderPath" style="width:40em" value="$!appFolderPath"/> </td>
     </tr>
     <tr>
+      <td>$i18n.getString( "appmanager_baseurl" )</td>
+      <td><input type="text" id="appBaseUrl" name="appBaseUrl" style="width:40em" value="$!appBaseUrl"/> </td>
+    </tr>
+    <tr>
       <td>$i18n.getString( "appmanager_store_url" )</td>
       <td><input type="text" id="appStoreUrl" name="appStoreUrl" style="width:40em" value="$!appStoreUrl"/> </td>
     </tr>

=== modified file 'dhis-2/dhis-web/dhis-web-appmanager/src/main/webapp/dhis-web-appmanager/index.vm'
--- dhis-2/dhis-web/dhis-web-appmanager/src/main/webapp/dhis-web-appmanager/index.vm	2013-05-28 15:50:33 +0000
+++ dhis-2/dhis-web/dhis-web-appmanager/src/main/webapp/dhis-web-appmanager/index.vm	2013-05-29 21:29:34 +0000
@@ -15,10 +15,10 @@
     <li class="introItem" onclick="window.location.href='$appsRootUrl/$appFolderNames.get($foreach.index)/$app.launchPath'">
         <span class="introItemHeader">
             <img style="float:left; margin-right:15px" src="$appsRootUrl/$appFolderNames.get($foreach.index)/$app.icons.icon48">
-            ${app.name}
+            ${app.name}&nbsp;&nbsp;(version ${app.version})
         </span>
         <br>
-        ${app.developer.name}
+        by ${app.developer.name}
     </li>
     #end
 #end

=== added directory 'dhis-2/dhis-web/dhis-web-appmanager/src/test'
=== added directory 'dhis-2/dhis-web/dhis-web-appmanager/src/test/java'