mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged HEAD (5.2) to 5.2.N (5.2.1)
126573 jkaabimofrad: Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2) 124623 jkaabimofrad: SFS-405, RA-778: Added tests and as the result did some minor modifications. Also, removed the ability to set or remove a client via JMX (Read only). git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@126918 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
package org.alfresco.repo.quickshare;
|
||||
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -36,15 +37,15 @@ import java.util.concurrent.ConcurrentMap;
|
||||
|
||||
/**
|
||||
* This class picks up all the loaded properties passed to it and uses a naming
|
||||
* convention to isolate the client's name and related values.
|
||||
* So, if a new client (e.g. MyClientName) is required to send shared-link email, then the following
|
||||
* convention to isolate the client's name and the related values.
|
||||
* So, if a new client (e.g. MyClientName) is required to send a shared-link email, then the following
|
||||
* needs to be put into a properties file.
|
||||
* <ul>
|
||||
* <li>quickshare.client.MyClientName.sharedLinkBaseUrl=http://localhost:8080/MyClientName/s</li>
|
||||
* <li>quickshare.client.MyClientName.templateAssetsUrl=http://localhost:8080/MyClientName/assets</li>
|
||||
* </ul>
|
||||
* The default property file is <b>alfresco/quickshare/quickshare-clients.properties</b> which
|
||||
* could be overridden by <b>alfresco-global</b> properties file.
|
||||
* could be overridden (or add new clients) by <b>alfresco-global</b> properties file.
|
||||
*
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
*/
|
||||
@@ -75,10 +76,37 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
this.globalProperties = globalProperties;
|
||||
}
|
||||
|
||||
public void init()
|
||||
{
|
||||
PropertyCheck.mandatory(this, "defaultProperties", defaultProperties);
|
||||
PropertyCheck.mandatory(this, "globalProperties", globalProperties);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns an unmodifiable view of the clients map. Never null.
|
||||
*/
|
||||
public Map<String, ClientApp> getClients()
|
||||
{
|
||||
return Collections.unmodifiableMap(clients);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the named client or null if no client exists with the given name.
|
||||
*
|
||||
* @param name the name of the client to retrieve
|
||||
*/
|
||||
public ClientApp getClient(String name)
|
||||
{
|
||||
return clients.get(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onBootstrap(ApplicationEvent event)
|
||||
{
|
||||
load();
|
||||
Map<String, String> mergedProperties = getAndMergeProperties();
|
||||
Set<String> clientsNames = processPropertyKeys(mergedProperties);
|
||||
clients.putAll(processClients(clientsNames, mergedProperties));
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("All bootstrapped quickShare clients: " + clients);
|
||||
@@ -91,37 +119,12 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
// nothing to do
|
||||
}
|
||||
|
||||
public void load()
|
||||
{
|
||||
Map<String, String> mergedProperties = getAndMergeProperties();
|
||||
Set<String> clientsNames = processPropertyKeys(mergedProperties);
|
||||
clients.putAll(processClients(clientsNames, mergedProperties));
|
||||
}
|
||||
|
||||
public Map<String, ClientApp> getClients()
|
||||
{
|
||||
return Collections.unmodifiableMap(clients);
|
||||
}
|
||||
|
||||
public ClientApp getClient(String name)
|
||||
{
|
||||
return clients.get(name);
|
||||
}
|
||||
|
||||
public void setClient(ClientApp client)
|
||||
{
|
||||
if (client != null)
|
||||
{
|
||||
clients.put(client.getName(), client);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean removeClient(String name)
|
||||
{
|
||||
ClientApp client = clients.remove(name);
|
||||
return (client != null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the property's key and extracts the clients' names.
|
||||
*
|
||||
* @param allProps the merged properties
|
||||
* @return a set of clients' names
|
||||
*/
|
||||
protected Set<String> processPropertyKeys(Map<String, String> allProps)
|
||||
{
|
||||
Set<String> clientsNames = new HashSet<>();
|
||||
@@ -164,6 +167,14 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
return clientsNames;
|
||||
}
|
||||
|
||||
/**
|
||||
* Processes the given properties and if the properties' values are valid, creates
|
||||
* a map of {@code ClientApp} with the client's name as the key.
|
||||
*
|
||||
* @param clientsNames the processed clients' names
|
||||
* @param allProps the merged properties
|
||||
* @return a map of {@code ClientApp} with the client's name as the key.
|
||||
*/
|
||||
protected Map<String, ClientApp> processClients(Set<String> clientsNames, Map<String, String> allProps)
|
||||
{
|
||||
Map<String, ClientApp> clientApps = new HashMap<>(clientsNames.size());
|
||||
@@ -171,7 +182,7 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
{
|
||||
String propKey = getPropertyKey(name, PROP_SHARED_LINK_BASE_URL);
|
||||
String sharedLinkBaseUrl = allProps.get(propKey);
|
||||
if (StringUtils.isEmpty(sharedLinkBaseUrl))
|
||||
if (isValidString(sharedLinkBaseUrl))
|
||||
{
|
||||
logInvalidPropertyValue(propKey, sharedLinkBaseUrl);
|
||||
continue;
|
||||
@@ -179,33 +190,42 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
|
||||
propKey = getPropertyKey(name, PROP_TEMPLATE_ASSETS_URL);
|
||||
String templateAssetsUrl = allProps.get(propKey);
|
||||
if (StringUtils.isEmpty(templateAssetsUrl))
|
||||
if (isValidString(templateAssetsUrl))
|
||||
{
|
||||
logInvalidPropertyValue(propKey, templateAssetsUrl);
|
||||
continue;
|
||||
}
|
||||
// Create the client data
|
||||
// As the required values are valid, create the client data
|
||||
ClientApp client = new ClientApp(name, sharedLinkBaseUrl, templateAssetsUrl);
|
||||
clientApps.put(name, client);
|
||||
}
|
||||
return clientApps;
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts and merges the given Java properties into a {@code java.util.Map}.
|
||||
*/
|
||||
protected Map<String, String> getAndMergeProperties()
|
||||
{
|
||||
Map<String, String> allProperties = new HashMap<>();
|
||||
for (String propKey : defaultProperties.stringPropertyNames())
|
||||
{
|
||||
allProperties.put(propKey, defaultProperties.getProperty(propKey));
|
||||
|
||||
}
|
||||
|
||||
//override default values from other property files
|
||||
// Add new clients or override the default values from other properties files
|
||||
for (String propKey : globalProperties.stringPropertyNames())
|
||||
{
|
||||
if (propKey.startsWith(PREFIX))
|
||||
{
|
||||
allProperties.put(propKey, globalProperties.getProperty(propKey));
|
||||
String value = globalProperties.getProperty(propKey);
|
||||
// before overriding the key, validate the property value
|
||||
if (isValidString(value))
|
||||
{
|
||||
logInvalidPropertyValue(propKey, value);
|
||||
continue;
|
||||
}
|
||||
allProperties.put(propKey, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -227,6 +247,11 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
return PREFIX + clientName + '.' + clientProp;
|
||||
}
|
||||
|
||||
private boolean isValidString(String str)
|
||||
{
|
||||
return StringUtils.isEmpty(str);
|
||||
}
|
||||
|
||||
public static class ClientApp
|
||||
{
|
||||
private final String name;
|
||||
|
Reference in New Issue
Block a user