Author: [email protected]
Date: Fri Nov 18 12:11:10 2011
New Revision: 1729
Log:
Modified:
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantConfigDAOImpl.java
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantGadgetImpl.java
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/resources/static/js/tenant.js
sandbox/ivol/amdatu-gadget-container/tenant-management-service/src/main/java/org/amdatu/core/tenant/service/TenantConfigServiceImpl.java
Modified:
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantConfigDAOImpl.java
==============================================================================
---
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantConfigDAOImpl.java
(original)
+++
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantConfigDAOImpl.java
Fri Nov 18 12:11:10 2011
@@ -42,7 +42,10 @@
String key = "tenant" + keyId;
boolean exists = properties.get(key + ".id") != null;
while (exists) {
- tenants.add(getTenantByKey(key));
+ TenantBean bean = getTenantByKey(key);
+ if (bean != null) {
+ tenants.add(bean);
+ }
keyId++;
key = "tenant" + keyId;
exists = properties.get(key + ".id") != null;
@@ -64,6 +67,9 @@
Configuration config =
m_configAdmin.getConfiguration(TenantManagementService.PID, null);
Dictionary properties = config.getProperties();
String id = properties.get(key + ".id").toString();
+ if (id == null || id.isEmpty()) {
+ return null;
+ }
String name = properties.get(key + ".name").toString();
String hostname = properties.get(key +
".properties.hostname").toString();
Map<String, String> dic = new HashMap<String, String>();
@@ -96,26 +102,14 @@
Dictionary properties = config.getProperties();
String tenantKey = findTenantKey(tenantId);
if (tenantKey != null) {
- properties.remove(tenantKey + ".id");
- properties.remove(tenantKey + ".name");
- properties.remove(tenantKey + ".properties.hostname");
+ // NB: remove properties from Config Admin does not work properly
in combination with
+ // Apache Felix fileinstall; fileinstall does not remove the
properties from .cfg file
+ // and so the tenant will be recreated automatically by
fileinstall. Therefore we just
+ // set the properties to ''
+ properties.put(tenantKey + ".id", "");
+ properties.put(tenantKey + ".name", "");
+ properties.put(tenantKey + ".properties.hostname", "");
-
- int removedId =
Integer.parseInt(tenantKey.substring("tenant".length()));
- int lastId = findLastTenantKey();
- if (lastId > removedId) {
- for (int i=removedId; i<lastId; i++) {
- properties.put("tenant" + i + ".id",
properties.get("tenant" + (i+1) + ".id"));
- properties.put("tenant" + i + ".name",
properties.get("tenant" + (i+1) + ".name"));
- properties.put("tenant" + i + ".properties.hostname",
properties.get("tenant" + (i+1) + ".properties.hostname"));
- }
- }
-
- properties.remove("tenant" + lastId + ".id");
- properties.remove("tenant" + lastId + ".name");
- properties.remove("tenant" + lastId + ".properties.hostname");
-
- config.
config.update(properties);
return true;
}
Modified:
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantGadgetImpl.java
==============================================================================
---
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantGadgetImpl.java
(original)
+++
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantGadgetImpl.java
Fri Nov 18 12:11:10 2011
@@ -44,6 +44,7 @@
m_logService.log(LogService.LOG_INFO, getClass().getName() + " service
started");
}
+ @SuppressWarnings("deprecation")
public URL getResource(final String name) {
final String pathPrefix = Activator.ALIAS + "/";
if (name != null && name.startsWith(pathPrefix)) {
Modified:
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
==============================================================================
---
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
(original)
+++
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/java/org/amdatu/opensocial/tenant/gadget/service/TenantRESTServiceImpl.java
Fri Nov 18 12:11:10 2011
@@ -15,6 +15,7 @@
*/
package org.amdatu.opensocial.tenant.gadget.service;
+import java.io.IOException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
@@ -43,6 +44,9 @@
public class TenantRESTServiceImpl implements RESTService {
// The base URL for this REST service
static String REST_URL = "/rest/tenants";
+
+ private static String VALID_HOSTNAME_REGEX =
"^(([a-zA-Z]|[a-zA-Z][a-zA-Z0-9\\-]*[a-zA-Z0-9])\\.)*([A-Za-z]|[A-Za-z][A-Za-z0-9\\-]*[A-Za-z0-9])$";
+
// HTTP caching for this REST interface
protected static CacheControl NO_CACHE_CONTROL;
@@ -128,7 +132,7 @@
public Response setTenant(@PathParam("id") final String id,
@FormParam("name") final String name,
@FormParam("hostname") final String hostname, @FormParam("email")
final String email) {
try {
- if (!validateEmail(email)) {
+ if (!validate(id, hostname, email)) {
return
Response.status(Status.BAD_REQUEST).cacheControl(NO_CACHE_CONTROL).build();
}
if (m_tenantDAO.setTenant(id, name, hostname)) {
@@ -155,6 +159,35 @@
return Response.ok().cacheControl(NO_CACHE_CONTROL).build();
}
+ private boolean validate(String id, String hostname, String email) throws
IOException {
+ boolean valid = validateHostname(hostname);
+ valid &= validateHostnameInUse(id, hostname);
+ valid &= validateEmail(email);
+ return valid;
+ }
+
+ private boolean validateHostname(String hostname) {
+ // Validate if another tenant exists that did already claim this
hostname
+ Pattern p = Pattern.compile(VALID_HOSTNAME_REGEX);
+ Matcher m = p.matcher(hostname);
+ if (!m.matches()) {
+ return false;
+ }
+ return true;
+ }
+
+ private boolean validateHostnameInUse(String id, String hostname) throws
IOException {
+ // Validate if another tenant exists that did already claim this
hostname
+ for (TenantBean tenant : m_tenantDAO.getTenants()) {
+ if (!tenant.getId().equals(id)) {
+ if (tenant.getHostname().equalsIgnoreCase(hostname)) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+
private boolean validateEmail(String email) {
if (email == null || email.isEmpty()) {
return true;
Modified:
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/resources/static/js/tenant.js
==============================================================================
---
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/resources/static/js/tenant.js
(original)
+++
sandbox/ivol/amdatu-gadget-container/tenant-management-gadget/src/main/resources/static/js/tenant.js
Fri Nov 18 12:11:10 2011
@@ -104,8 +104,6 @@
}
}
-
-
function showDeleteTenant(link, name) {
if (confirm('Are you sure you want to delete the Tenant "' + name + '"?')) {
deleteTenant(link);
Modified:
sandbox/ivol/amdatu-gadget-container/tenant-management-service/src/main/java/org/amdatu/core/tenant/service/TenantConfigServiceImpl.java
==============================================================================
---
sandbox/ivol/amdatu-gadget-container/tenant-management-service/src/main/java/org/amdatu/core/tenant/service/TenantConfigServiceImpl.java
(original)
+++
sandbox/ivol/amdatu-gadget-container/tenant-management-service/src/main/java/org/amdatu/core/tenant/service/TenantConfigServiceImpl.java
Fri Nov 18 12:11:10 2011
@@ -58,8 +58,14 @@
Enumeration<String> keys = properties.keys();
while (keys.hasMoreElements()) {
String key = keys.nextElement();
- if (key.endsWith(".id")) {
- m_newTenants.add(getTenant(properties, key));
+ if (key.endsWith(".id")) {
+ // NB: getTenant returns null in case a tenant with this
key existed, but was removed.
+ // In that case the configuration keys are not removed
(since this does not work properly
+ // in combination with Apache Felix fileinstall), but the
values are set to ''
+ TenantEntity tenant = getTenant(properties, key);
+ if (tenant != null) {
+ m_newTenants.add(tenant);
+ }
}
}
@@ -159,7 +165,10 @@
private TenantEntity getTenant(Dictionary dictionary, String idKey) {
String nameKey = idKey.substring(0, idKey.lastIndexOf(".id")) +
".name";
String propertiesKey = idKey.substring(0, idKey.lastIndexOf(".id")) +
".properties";
- String id = (String) dictionary.get(idKey);
+ String id = (String) dictionary.get(idKey);
+ if (id == null || id.isEmpty()) {
+ return null;
+ }
String name = (String) dictionary.get(nameKey);
Map<String, String> properties = new HashMap<String, String>();
Enumeration<String> keys = dictionary.keys();
_______________________________________________
Amdatu-commits mailing list
[email protected]
http://lists.amdatu.org/mailman/listinfo/amdatu-commits