Author: [email protected]
Date: Mon Nov 7 12:34:25 2011
New Revision: 1713
Log:
Added:
sandbox/ivol/tenant-management-gadget/src/main/resources/static/js/util.js
Modified:
sandbox/ivol/tenant-management-gadget/pom.xml
sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantGadgetImpl.java
sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
sandbox/ivol/tenant-management-gadget/src/main/resources/jsp/TenantGadget.jsp
sandbox/ivol/tenant-management-gadget/src/main/resources/static/css/tenant.css
sandbox/ivol/tenant-management-gadget/src/main/resources/static/js/tenant.js
sandbox/ivol/tenant-management-gadget/src/main/resources/static/labels/tenantmgmt_ALL_ALL.xml
Modified: sandbox/ivol/tenant-management-gadget/pom.xml
==============================================================================
--- sandbox/ivol/tenant-management-gadget/pom.xml (original)
+++ sandbox/ivol/tenant-management-gadget/pom.xml Mon Nov 7 12:34:25 2011
@@ -20,7 +20,7 @@
<parent>
<groupId>org.amdatu.opensocial</groupId>
<artifactId>org.amdatu.opensocial</artifactId>
- <version>0.2.0-SNAPSHOT</version>
+ <version>0.2.0</version>
</parent>
<artifactId>org.amdatu.opensocial.tenant.gadget</artifactId>
<packaging>bundle</packaging>
@@ -28,7 +28,7 @@
<description>Provides a tenant management gadget</description>
<properties>
- <amdatu.opensocial.version>0.2.0-SNAPSHOT</amdatu.opensocial.version>
+ <amdatu.opensocial.version>0.2.0</amdatu.opensocial.version>
</properties>
<dependencies>
@@ -94,6 +94,42 @@
</dependency>
</dependencies>
+ <repositories>
+ <repository>
+ <id>amdatu.releases</id>
+ <name>Amdatu Release Repository</name>
+ <url>http://repository.amdatu.org/releases</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>amdatu.snapshots</id>
+ <name>Amdatu Snapshot Repository</name>
+ <url>http://repository.amdatu.org/snapshots</url>
+ <releases>
+ <enabled>false</enabled>
+ </releases>
+ <snapshots>
+ <enabled>true</enabled>
+ </snapshots>
+ </repository>
+ <repository>
+ <id>riptano</id>
+ <name>Riptano Repository</name>
+ <url>http://mvn.riptano.com/content/repositories/riptano</url>
+ <releases>
+ <enabled>true</enabled>
+ </releases>
+ <snapshots>
+ <enabled>false</enabled>
+ </snapshots>
+ </repository>
+ </repositories>
+
<build>
<plugins>
<plugin>
Modified:
sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantGadgetImpl.java
==============================================================================
---
sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantGadgetImpl.java
(original)
+++
sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantGadgetImpl.java
Mon Nov 7 12:34:25 2011
@@ -13,38 +13,64 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.amdatu.opensocial.tenant.gadget.service;
-
+package org.amdatu.opensocial.tenant.gadget.service;
+
+import java.io.File;
+import java.net.MalformedURLException;
import java.net.URL;
import org.amdatu.opensocial.tenant.gadget.osgi.Activator;
import org.amdatu.web.httpcontext.ResourceProvider;
import org.osgi.framework.BundleContext;
import org.osgi.service.log.LogService;
-
-/**
- * This service provides the login gadget.
- *
- * @author ivol
- */
-public class TenantGadgetImpl implements ResourceProvider {
-
- // Service dependencies, injected by the Felix dependency manager
- private volatile LogService m_logService;
- private volatile BundleContext m_bundleContext;
-
- /**
- * The init() method is invoked by the Felix dependency manager.
- */
- public void start() {
- m_logService.log(LogService.LOG_INFO, getClass().getName() + " service
started");
- }
-
- public URL getResource(final String name) {
- final String pathPrefix = Activator.ALIAS + "/";
- if (name != null && name.startsWith(pathPrefix)) {
- return
m_bundleContext.getBundle().getResource(name.substring(pathPrefix.length()));
- }
- return null;
- }
-}
+
+/**
+ * This service provides the login gadget.
+ *
+ * @author ivol
+ */
+public class TenantGadgetImpl implements ResourceProvider {
+ private static final String LOCAL_DEV_DIR =
+
"D:/Amdatu-svn/sandbox/ivol/tenant-management-gadget/src/main/resources";
+
+ // Service dependencies, injected by the Felix dependency manager
+ private volatile LogService m_logService;
+ private volatile BundleContext m_bundleContext;
+
+ /**
+ * The init() method is invoked by the Felix dependency manager.
+ */
+ public void start() {
+ m_logService.log(LogService.LOG_INFO, getClass().getName() + " service
started");
+ }
+
+ public URL getResource(final String name) {
+ final String pathPrefix = Activator.ALIAS + "/";
+ if (name != null && name.startsWith(pathPrefix)) {
+ // START debug code
+ String fileName = null;
+ if (name.endsWith(".jsp")) {
+ fileName = name.substring(name.lastIndexOf("/jsp/"));
+ } else if (name.endsWith(".js")) {
+ fileName = "/static" +
name.substring(name.lastIndexOf("/js/"));
+ } else if (name.endsWith(".css")) {
+ fileName = "/static" +
name.substring(name.lastIndexOf("/css/"));
+ }
+
+ if (fileName != null) {
+ File file = new File(LOCAL_DEV_DIR + fileName);
+ try {
+ if (!file.exists()) {
+ m_logService.log(LogService.LOG_ERROR, "Could not find
file '" + file.getAbsolutePath() + "'");
+ } else {
+ return file.toURL();
+ }
+ }
+ catch (MalformedURLException e) {}
+ }
+
+ return
m_bundleContext.getBundle().getResource(name.substring(pathPrefix.length()));
+ }
+ return null;
+ }
+}
Modified:
sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
==============================================================================
---
sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
(original)
+++
sandbox/ivol/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
Mon Nov 7 12:34:25 2011
@@ -24,8 +24,11 @@
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
+import javax.ws.rs.FormParam;
import javax.ws.rs.GET;
+import javax.ws.rs.POST;
import javax.ws.rs.Path;
+import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.CacheControl;
@@ -42,6 +45,7 @@
import org.osgi.service.cm.ConfigurationAdmin;
import org.osgi.service.log.LogService;
+@SuppressWarnings({ "unchecked", "deprecation", "rawtypes" })
@Path("tenants")
public class TenantRESTServiceImpl implements RESTService {
// HTTP caching for this REST interface
@@ -63,15 +67,12 @@
public Response getTenants(@Context final HttpHeaders headers, @Context
final HttpServletRequest request) {
TenantsBean tenantsBean = new TenantsBean();
try {
- for (Tenant tenant : getTenants()) {
- TenantBean tenantBean = new TenantBean();
- tenantBean.setId(tenant.getId());
- tenantBean.setName(tenant.getName());
-
tenantBean.setHostname(tenant.getProperties().get(Tenant.HOSTNAME_PROPERTY));
- String href = request.getContextPath() + "/rest/tenant/" +
tenant.getId();
- tenantBean.setLink(new
AtomSyndicationLink().setHref(href).setRel("Alternate")
+ for (TenantBean tenant : getTenants()) {
+ String href = request.getContextPath() + "/rest/tenants/" +
tenant.getId();
+ tenant.setLink(new
AtomSyndicationLink().setHref(href).setRel("Alternate")
.setType("application/json"));
- tenantsBean.addTenant(tenantBean);
+
+ tenantsBean.addTenant(tenant);
}
}
catch (Exception e) {
@@ -79,23 +80,18 @@
}
return Response.ok(tenantsBean,
MediaType.APPLICATION_JSON_TYPE).cacheControl(NO_CACHE_CONTROL)
- .build();
+ .build();
}
@GET
@Path("/{id}")
@Produces({ MediaType.APPLICATION_JSON })
- public Response getTenant(@Context final HttpHeaders headers, @Context
final HttpServletRequest request) {
+ public Response getTenant(@PathParam("id") final String id, @Context final
HttpHeaders headers, @Context final HttpServletRequest request) {
TenantBean tenant = null;
try {
- Configuration config =
m_configAdmin.getConfiguration(TenantManagementService.PID);
- Dictionary properties = config.getProperties();
- Enumeration keys = properties.keys();
- while (keys.hasMoreElements()) {
- String key = keys.nextElement().toString();
- if (key.endsWith(".id")) {
- tenant = getTenant(key.substring(0,
key.lastIndexOf(".id")));
- }
+ String key = findTenantKey(id);
+ if (key != null) {
+ tenant = getTenant(key);
}
}
catch (Exception e) {
@@ -107,7 +103,33 @@
}
return Response.ok(tenant,
MediaType.APPLICATION_JSON_TYPE).cacheControl(NO_CACHE_CONTROL)
- .build();
+ .build();
+ }
+
+
+ @POST
+ @Path("/{id}")
+ public Response updateTenant(@PathParam("id") final String id,
@FormParam("name") final String name, @FormParam("hostname") final String
hostname) {
+ TenantBean tenant = null;
+ try {
+ Configuration config =
m_configAdmin.getConfiguration(TenantManagementService.PID);
+ Dictionary properties = config.getProperties();
+ String tenantKey = findTenantKey(id);
+ if (tenantKey == null) {
+ int newid = findLastTenantKey() + 1;
+ tenantKey = "tenant" + newid;
+ properties.put(tenantKey + ".id", id);
+ }
+ properties.put(tenantKey + ".name", name);
+ properties.put(tenantKey + ".properties.hostname", hostname);
+ config.update(properties);
+ }
+ catch (Exception e) {
+ throw new WebApplicationException(e,
Response.Status.INTERNAL_SERVER_ERROR);
+ }
+
+ return Response.ok(tenant,
MediaType.APPLICATION_JSON_TYPE).cacheControl(NO_CACHE_CONTROL)
+ .build();
}
private List<TenantBean> getTenants() throws IOException {
@@ -134,6 +156,39 @@
String hostname = properties.get(key +
".properties.hostname").toString();
Map<String, String> dic = new HashMap<String, String>();
dic.put(Tenant.HOSTNAME_PROPERTY, hostname);
+
return new TenantBean(id, name, hostname);
}
+
+ private String findTenantKey(String tenantId) throws IOException {
+ Configuration config =
m_configAdmin.getConfiguration(TenantManagementService.PID);
+ Dictionary properties = config.getProperties();
+ Enumeration keys = properties.keys();
+ while (keys.hasMoreElements()) {
+ String key = keys.nextElement().toString();
+ if (key.endsWith(".id")) {
+ if (tenantId.equals(properties.get(key))) {
+ return key.substring(0, key.indexOf(".id"));
+ }
+ }
+ }
+ return null;
+ }
+
+ private int findLastTenantKey() throws IOException {
+ int maxid = 1;
+ Configuration config =
m_configAdmin.getConfiguration(TenantManagementService.PID);
+ Dictionary properties = config.getProperties();
+ Enumeration keys = properties.keys();
+ while (keys.hasMoreElements()) {
+ String key = keys.nextElement().toString();
+ if (key.endsWith(".id")) {
+ String id = key.substring("tenant".length(), key.indexOf("."));
+ if (Integer.parseInt(id) > maxid) {
+ maxid = Integer.parseInt(id);
+ }
+ }
+ }
+ return maxid;
+ }
}
Modified:
sandbox/ivol/tenant-management-gadget/src/main/resources/jsp/TenantGadget.jsp
==============================================================================
---
sandbox/ivol/tenant-management-gadget/src/main/resources/jsp/TenantGadget.jsp
(original)
+++
sandbox/ivol/tenant-management-gadget/src/main/resources/jsp/TenantGadget.jsp
Mon Nov 7 12:34:25 2011
@@ -44,15 +44,33 @@
<script type="text/javascript"
src="${contextPath}/dashboard/static/js/lib/jquery-1.4.2.min.js"></script>
<script type="text/javascript"
src="${contextPath}/dashboard/static/js/lib/jquery-ui-1.8.2.custom.min.js"></script>
<script type="text/javascript"
src="${gadgetBaseUrl}/static/js/tenant.js"></script>
+ <script type="text/javascript"
src="${gadgetBaseUrl}/static/js/util.js"></script>
<fieldset id="tenants">
<legend id="tenants_legend">__MSG_tenants__</legend>
<div id="tenants"></div>
+ <div id="infobox"></div>
+ </fieldset>
+
+ <input type="button" id="new_tenant_button" value="__MSG_new_tenant__"
onclick="javascript:addTenant();"/>
+
+ <fieldset id="tenant_details" style="display:none;visibility:hidden">
+ <legend id="tenant_details_legend">__MSG_details__</legend>
+ <table width="95%">
+ <tr><td>__MSG_id__</td><td><input type="edit" id="tenant_id"
disabled="disabled"/></td></tr>
+ <tr><td>__MSG_name__</td><td><input type="edit" id="tenant_name"
value=""/></td></tr>
+ <tr><td>__MSG_hostname__</td><td><input type="edit"
id="tenant_hostname" value=""/></td></tr>
+ </table>
+ <input type="submit" id="tenant_save" value="__MSG_save__"
onclick="javascript:saveTenant();"/>
+ <input type="button" id="cancel" value="__MSG_cancel__"
onclick="javascript:cancelEdit();"/>
</fieldset>
<script type="text/javascript">
var contextPath = "${contextPath}";
+ var newTenantLabel = "__MSG_new_tenant__";
+ var updateTenantLabel = "__MSG_update_tenant__";
+
loadTenants();
</script>
]]>
Modified:
sandbox/ivol/tenant-management-gadget/src/main/resources/static/css/tenant.css
==============================================================================
---
sandbox/ivol/tenant-management-gadget/src/main/resources/static/css/tenant.css
(original)
+++
sandbox/ivol/tenant-management-gadget/src/main/resources/static/css/tenant.css
Mon Nov 7 12:34:25 2011
@@ -20,7 +20,7 @@
}
table td {
- vertical-align: top;
+
max-width: 280px;
_width: 280px; /* IE */
white-space: pre; /* CSS 2.0 */
Modified:
sandbox/ivol/tenant-management-gadget/src/main/resources/static/js/tenant.js
==============================================================================
---
sandbox/ivol/tenant-management-gadget/src/main/resources/static/js/tenant.js
(original)
+++
sandbox/ivol/tenant-management-gadget/src/main/resources/static/js/tenant.js
Mon Nov 7 12:34:25 2011
@@ -18,18 +18,16 @@
gadgets.io.makeRequest(url, callback, params);
}
-function addNoCache(url) {
- var ts = new Date().getTime();
- if (url.indexOf("?") == -1) {
- url += "?nocache=" + ts;
- } else {
- url += "&nocache=" + ts;
- }
- return url;
-}
-
-function getBaseUrl() {
- return window.location.protocol +"//" + window.location.hostname + ":" +
window.location.port;
+function doSaveTenant(url, callback) {
+ var params = {};
+ params[gadgets.io.RequestParameters.CONTENT_TYPE] =
gadgets.io.ContentType.JSON;
+ params[gadgets.io.RequestParameters.METHOD] = gadgets.io.MethodType.POST;
+ var name = document.getElementById('tenant_name').value;
+ var hostname = document.getElementById('tenant_hostname').value;
+ var postdata = {name : name, hostname : hostname};
+ params[gadgets.io.RequestParameters.POST_DATA] =
gadgets.io.encodeValues(postdata);
+ url = getBaseUrl() + addNoCache(unescape(url));
+ gadgets.io.makeRequest(url, callback, params);
}
function onTenantsLoaded(response) {
@@ -49,7 +47,7 @@
var editTenant = " onclick=\"javascript:editTenant('" + escape(link) +
"');\"";
var deleteTentant = " onclick=\"javascript:confirmDeleteTenant('" +
escape(link) + "', '" + escape(name) + "');\"";
- html += "<tr><td><a href='#'" + "" + ">" + name + " (" + hostname +
")</a></td>";
+ html += "<tr><td><a href='#'" + editTenant + ">" + name + " (" +
hostname + ")</a></td>";
html += "<td align='center'><a href='#'><img src='" + contextPath +
"/tenant/static/images/remove.gif'" + deleteTenant + "/></a></td></tr>";
}
html += "</table></center></p>";
@@ -65,30 +63,56 @@
gadgets.window.adjustHeight();
}
-
+function onTenantLoaded(response) {
+ if (response.rc == 200) {
+ var tenant = response.data["tenant"];
+ document.getElementById('tenant_id').value = tenant.id;
+ document.getElementById('tenant_name').value = tenant.name;
+ document.getElementById('tenant_hostname').value = tenant.hostname;
+ gadgets.window.adjustHeight();
+ } else if (response.rc == 404) {
+ showError(prefs.getMsg('role_not_found'));
+ } else if (response.rc == 401) {
+ showError(prefs.getMsg('accessdenied'));
+ } else {
+ showError(prefs.getMsg('unexpected_error') + response.errors);
+ }
+}
function editTenant(link) {
loadTenant(escape(unescape(link)), onTenantLoaded);
- showEditTenant();
+ hide('new_tenant_button');
+ document.getElementById('tenant_details_legend').innerHTML =
updateTenantLabel;
+ show('tenant_details');
}
-
function deleteTenant() {
}
+function saveTenant() {
+ var link = "/rest/tenants/" + document.getElementById('tenant_id').value;
+ doSaveTenant(escape(link), onTenantSaved);
+}
+
+function onTenantSaved() {
+ document.getElementById('infobox').innerHTML = "Tenant updated
successfully.";
+}
+
function confirmDeleteTenant(tenant) {
alert('confirm');
}
-function ensureArray(input) {
- // check if this result is an array
- if (jQuery.isArray(input)) {
- return input;
- }
- var result = [];
- if (input != null) {
- result.push(input);
- }
- return result;
+function cancelEdit() {
+ hide('tenant_details');
+ show('new_tenant_button');
+ gadgets.window.adjustHeight();
+}
+
+function addTenant() {
+ hide('new_tenant_button');
+ document.getElementById('tenant_details_legend').innerHTML = newTenantLabel;
+ document.getElementById('tenant_id').disabled = "";
+ show('tenant_details');
+ gadgets.window.adjustHeight();
}
\ No newline at end of file
Added:
sandbox/ivol/tenant-management-gadget/src/main/resources/static/js/util.js
==============================================================================
--- (empty file)
+++ sandbox/ivol/tenant-management-gadget/src/main/resources/static/js/util.js
Mon Nov 7 12:34:25 2011
@@ -0,0 +1,63 @@
+/*
+ Copyright (c) 2010, 2011 The Amdatu Foundation
+
+ Licensed under the Apache License, Version 2.0 (the "License");
+ you may not use this file except in compliance with the License.
+ You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.verning permissions and limitations
+ under the License.
+*/
+
+function ensureArray(input) {
+ // check if this result is an array
+ if (jQuery.isArray(input)) {
+ return input;
+ }
+ var result = [];
+ if (input != null) {
+ result.push(input);
+ }
+ return result;
+}
+
+function show(id) {
+ var obj = document.getElementById(id);
+ obj.style.visibility = "";
+ obj.style.display = "";
+}
+
+function hide(id) {
+ var obj = document.getElementById(id);
+ obj.style.visibility = "hidden";
+ obj.style.display = "none";
+}
+
+function getCookie(cookieName) {
+ var results = document.cookie.match ( '(^|;) ?' + cookieName +
'=([^;]*)(;|$)' );
+ if (results) {
+ return (unescape(results[2]));
+ } else {
+ return null;
+ }
+}
+
+function addNoCache(url) {
+ var ts = new Date().getTime();
+ if (url.indexOf("?") == -1) {
+ url += "?nocache=" + ts;
+ } else {
+ url += "&nocache=" + ts;
+ }
+ return url;
+}
+
+function getBaseUrl() {
+ return window.location.protocol +"//" + window.location.hostname + ":" +
window.location.port;
+}
\ No newline at end of file
Modified:
sandbox/ivol/tenant-management-gadget/src/main/resources/static/labels/tenantmgmt_ALL_ALL.xml
==============================================================================
---
sandbox/ivol/tenant-management-gadget/src/main/resources/static/labels/tenantmgmt_ALL_ALL.xml
(original)
+++
sandbox/ivol/tenant-management-gadget/src/main/resources/static/labels/tenantmgmt_ALL_ALL.xml
Mon Nov 7 12:34:25 2011
@@ -18,8 +18,12 @@
<messagebundle>
<msg name="tenants">Tenants</msg>
<msg name="tenant">Tenant</msg>
+ <msg name="id">Id</msg>
+ <msg name="name">Name</msg>
+ <msg name="hostname">Hostname</msg>
<msg name="new_tenant">New tenant</msg>
+ <msg name="update_tenant">Update tenant</msg>
<msg name="details">Details</msg>
<msg name="save">Save</msg>
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits