mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged WEBAPP-API (5.2.1) to 5.2.N (5.2.1)
135227 jkaabimofrad: APPSREPO-132: Make ClientAppConfig generic so it could be used by other V1 APIs. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/BRANCHES/DEV/5.2.N/root@135564 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -39,6 +39,7 @@
|
||||
<import resource="classpath*:alfresco/slingshot-context.xml" />
|
||||
<import resource="classpath*:alfresco/solr-facets-context.xml" />
|
||||
<import resource="classpath*:alfresco/custom-model-management-services-context.xml" />
|
||||
<import resource="classpath*:alfresco/repo-clients-apps-context.xml" />
|
||||
<import resource="classpath*:alfresco/domain/*-context.xml" />
|
||||
<import resource="classpath*:alfresco/smartfolder-context.xml" />
|
||||
</beans>
|
||||
|
@@ -0,0 +1,4 @@
|
||||
# registry of clients that are able to email
|
||||
|
||||
repo.client-app.sfs.templateAssetsUrl=http://localhost:8082/sfs
|
||||
repo.client-app.sfs.sharedLinkBaseUrl=http://localhost:8082/sfs/s
|
@@ -51,19 +51,6 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="quickShareDefaultProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<property name="locations">
|
||||
<list>
|
||||
<value>classpath*:alfresco/quickshare/quickshare-clients.properties</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="quickShareClientsConfig" class="org.alfresco.repo.quickshare.ClientAppConfig" init-method="init">
|
||||
<property name="defaultProperties" ref="quickShareDefaultProperties"/>
|
||||
<property name="globalProperties" ref="global-properties"/>
|
||||
</bean>
|
||||
|
||||
<!-- QuickShare Service base bean -->
|
||||
<bean id="quickShareService" class="org.alfresco.repo.quickshare.QuickShareServiceImpl" init-method="init">
|
||||
<property name="attributeService" ref="AttributeService"/>
|
||||
@@ -80,7 +67,7 @@
|
||||
<property name="actionService" ref="ActionService" />
|
||||
<property name="preferenceService" ref="PreferenceService" />
|
||||
<property name="defaultEmailSender" value="${system.quickshare.email.from.default}" />
|
||||
<property name="clientAppConfig" ref="quickShareClientsConfig" />
|
||||
<property name="clientAppConfig" ref="clientAppConfig" />
|
||||
<property name="searchService" ref="SearchService" />
|
||||
<property name="siteService" ref="SiteService" />
|
||||
<property name="authorityService" ref="AuthorityService" />
|
||||
|
@@ -1,4 +0,0 @@
|
||||
# registry of clients that are able to email shared links
|
||||
|
||||
quickshare.client.sfs.sharedLinkBaseUrl=http://localhost:8082/sfs/s
|
||||
quickshare.client.sfs.templateAssetsUrl=http://localhost:8082/sfs
|
18
config/alfresco/repo-clients-apps-context.xml
Normal file
18
config/alfresco/repo-clients-apps-context.xml
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<!DOCTYPE beans PUBLIC '-//SPRING//DTD BEAN//EN' 'http://www.springframework.org/dtd/spring-beans.dtd'>
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="clientAppDefaultProperties" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<property name="locations">
|
||||
<list>
|
||||
<value>classpath*:alfresco/client/config/repo-clients-apps.properties</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="clientAppConfig" class="org.alfresco.repo.client.config.ClientAppConfig" init-method="init">
|
||||
<property name="defaultProperties" ref="clientAppDefaultProperties"/>
|
||||
<property name="globalProperties" ref="global-properties"/>
|
||||
</bean>
|
||||
</beans>
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -24,7 +24,7 @@
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.quickshare;
|
||||
package org.alfresco.repo.client.config;
|
||||
|
||||
import org.alfresco.util.PropertyCheck;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
@@ -45,13 +45,24 @@ 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 the related values.
|
||||
* So, if a new client (e.g. MyClientName) is required to send a shared-link email, then the following
|
||||
* <p>
|
||||
* The naming convention must confirm to the following:
|
||||
* <p>
|
||||
* <i>repo.client-app.{@literal <client-name>.<propertyName>}</i>
|
||||
* <p>
|
||||
* Also, the client-name or property name ({@literal <propertyName>}) must not contain a dot {@literal ('.')}
|
||||
* <p>
|
||||
* Note also, that any property without a value is ignored and the client will not be registered
|
||||
* if all the properties of that client have no values.
|
||||
* <p>
|
||||
* So, if a new client (e.g. MyClientName) is required to send a shared-link email and the service or the API requires,
|
||||
* for example, <i>sharedLinkBaseUrl</i> and <i>templateAssetsUrl</i> properties, 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>
|
||||
* <li>repo.client-app.MyClientName.sharedLinkBaseUrl=http://localhost:8080/MyClientName/s</li>
|
||||
* <li>repo.client-app.MyClientName.templateAssetsUrl=http://localhost:8080/MyClientName/assets</li>
|
||||
* </ul>
|
||||
* The default property file is <b>alfresco/quickshare/quickshare-clients.properties</b> which
|
||||
* The default property file is <b>alfresco/client/config/repo-clients-apps.properties</b> which
|
||||
* could be overridden (or add new clients) by <b>alfresco-global</b> properties file.
|
||||
*
|
||||
* @author Jamal Kaabi-Mofrad
|
||||
@@ -60,8 +71,7 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
{
|
||||
private static final Log logger = LogFactory.getLog(ClientAppConfig.class);
|
||||
|
||||
public static final String PREFIX = "quickshare.client.";
|
||||
public static final String PROP_SHARED_LINK_BASE_URL = "sharedLinkBaseUrl";
|
||||
public static final String PREFIX = "repo.client-app.";
|
||||
public static final String PROP_TEMPLATE_ASSETS_URL = "templateAssetsUrl";
|
||||
|
||||
private Properties defaultProperties;
|
||||
@@ -111,12 +121,15 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
protected void onBootstrap(ApplicationEvent event)
|
||||
{
|
||||
Map<String, String> mergedProperties = getAndMergeProperties();
|
||||
Set<String> clientsNames = processPropertyKeys(mergedProperties);
|
||||
clients.putAll(processClients(clientsNames, mergedProperties));
|
||||
|
||||
Set<String> clientsNames = new HashSet<>();
|
||||
Set<String> propsNames = new HashSet<>();
|
||||
processPropertyKeys(mergedProperties, clientsNames, propsNames);
|
||||
clients.putAll(processClients(clientsNames, propsNames, mergedProperties));
|
||||
|
||||
if (logger.isDebugEnabled())
|
||||
{
|
||||
logger.debug("All bootstrapped quickShare clients: " + clients);
|
||||
logger.debug("All bootstrapped repo clients apps: " + clients);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,11 +143,11 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
* Processes the property's key and extracts the clients' names.
|
||||
*
|
||||
* @param allProps the merged properties
|
||||
* @return a set of clients' names
|
||||
* @param clientsNames a set of strings which will be populated with client names
|
||||
* @param propsNames a set of strings which will be populated with properties names (i.e.the property after the client name)
|
||||
*/
|
||||
protected Set<String> processPropertyKeys(Map<String, String> allProps)
|
||||
protected void processPropertyKeys(Map<String, String> allProps, Set<String> clientsNames, Set<String> propsNames)
|
||||
{
|
||||
Set<String> clientsNames = new HashSet<>();
|
||||
for (String key : allProps.keySet())
|
||||
{
|
||||
String propKey = key;
|
||||
@@ -157,13 +170,15 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
}
|
||||
String clientName = propKey.substring(0, clientNameControlDot);
|
||||
String propName = propKey.substring((clientNameControlDot + 1));
|
||||
if (PROP_SHARED_LINK_BASE_URL.equals(propName) || PROP_TEMPLATE_ASSETS_URL.equals(propName))
|
||||
// the property name (the property after the client name) must not contain a '.'
|
||||
if (propName.indexOf('.') == -1)
|
||||
{
|
||||
clientsNames.add(clientName);
|
||||
propsNames.add(propName);
|
||||
}
|
||||
else
|
||||
{
|
||||
logMalformedPropertyKey(key);
|
||||
logMalformedPropertyKey(key, "The property name " + propName + " must not contain a '.'");
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -171,7 +186,6 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
logMalformedPropertyKey(propKey);
|
||||
}
|
||||
}
|
||||
return clientsNames;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -179,32 +193,51 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
* a map of {@code ClientApp} with the client's name as the key.
|
||||
*
|
||||
* @param clientsNames the processed clients' names
|
||||
* @param propsNames the processed properties 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)
|
||||
protected Map<String, ClientApp> processClients(Set<String> clientsNames, Set<String> propsNames, Map<String, String> allProps)
|
||||
{
|
||||
Map<String, ClientApp> clientApps = new HashMap<>(clientsNames.size());
|
||||
for (String name : clientsNames)
|
||||
for (String clientName : clientsNames)
|
||||
{
|
||||
String propKey = getPropertyKey(name, PROP_SHARED_LINK_BASE_URL);
|
||||
String sharedLinkBaseUrl = allProps.get(propKey);
|
||||
if (isValidString(sharedLinkBaseUrl))
|
||||
Map<String, String> config = new HashMap<>();
|
||||
String templateAssetsUrl = null;
|
||||
for (String propName : propsNames)
|
||||
{
|
||||
logInvalidPropertyValue(propKey, sharedLinkBaseUrl);
|
||||
String propKey = getPropertyKey(clientName, propName);
|
||||
if (!allProps.containsKey(propKey))
|
||||
{
|
||||
// if the constructed property key does not exist, skip this iteration.
|
||||
continue;
|
||||
}
|
||||
|
||||
propKey = getPropertyKey(name, PROP_TEMPLATE_ASSETS_URL);
|
||||
String templateAssetsUrl = allProps.get(propKey);
|
||||
if (isValidString(templateAssetsUrl))
|
||||
String propValue = allProps.get(propKey);
|
||||
|
||||
if (StringUtils.isEmpty(propValue))
|
||||
{
|
||||
logInvalidPropertyValue(propKey, templateAssetsUrl);
|
||||
logInvalidPropertyValue(propKey, propValue);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (PROP_TEMPLATE_ASSETS_URL.equals(propName))
|
||||
{
|
||||
templateAssetsUrl = propValue;
|
||||
}
|
||||
else
|
||||
{
|
||||
config.put(propName, propValue);
|
||||
}
|
||||
}
|
||||
if (StringUtils.isEmpty(templateAssetsUrl) && config.isEmpty())
|
||||
{
|
||||
logger.warn("Client-app [" + clientName + "] can not be registered as it needs at least one property with a valid value.");
|
||||
continue;
|
||||
}
|
||||
// As the required values are valid, create the client data
|
||||
ClientApp client = new ClientApp(name, sharedLinkBaseUrl, templateAssetsUrl);
|
||||
clientApps.put(name, client);
|
||||
ClientApp client = new ClientApp(clientName, templateAssetsUrl, config);
|
||||
clientApps.put(clientName, client);
|
||||
}
|
||||
return clientApps;
|
||||
}
|
||||
@@ -227,7 +260,7 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
{
|
||||
String value = globalProperties.getProperty(propKey);
|
||||
// before overriding the key, validate the property value
|
||||
if (isValidString(value))
|
||||
if (StringUtils.isEmpty(value))
|
||||
{
|
||||
logInvalidPropertyValue(propKey, value);
|
||||
continue;
|
||||
@@ -239,14 +272,20 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
return allProperties;
|
||||
}
|
||||
|
||||
private void logMalformedPropertyKey(String propName, String reason)
|
||||
{
|
||||
reason = (StringUtils.isBlank(reason)) ? "" : " " + reason;
|
||||
logger.warn("Ignoring client app config (malformed property key) [" + propName + "]." + reason);
|
||||
}
|
||||
|
||||
private void logMalformedPropertyKey(String propName)
|
||||
{
|
||||
logger.warn("Ignoring quickShare client (malformed property key): " + propName);
|
||||
logMalformedPropertyKey(propName, null);
|
||||
}
|
||||
|
||||
private void logInvalidPropertyValue(String propName, String propValue)
|
||||
{
|
||||
logger.warn("Ignoring quickShare client (invalid value) [" + propValue + "] for the property:" + propName);
|
||||
logger.warn("Ignoring client app config (invalid value) [" + propValue + "] for the property:" + propName);
|
||||
}
|
||||
|
||||
private String getPropertyKey(String clientName, String clientProp)
|
||||
@@ -254,22 +293,17 @@ 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;
|
||||
private final String sharedLinkBaseUrl;
|
||||
private final String templateAssetsUrl;
|
||||
private final Map<String, String> properties;
|
||||
|
||||
public ClientApp(String name, String sharedLinkBaseUrl, String templateAssetsUrl)
|
||||
public ClientApp(String name, String templateAssetsUrl, Map<String, String> properties)
|
||||
{
|
||||
this.name = name;
|
||||
this.sharedLinkBaseUrl = sharedLinkBaseUrl;
|
||||
this.templateAssetsUrl = templateAssetsUrl;
|
||||
this.properties = new HashMap<>(properties);
|
||||
}
|
||||
|
||||
public String getName()
|
||||
@@ -277,16 +311,21 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
return name;
|
||||
}
|
||||
|
||||
public String getSharedLinkBaseUrl()
|
||||
{
|
||||
return sharedLinkBaseUrl;
|
||||
}
|
||||
|
||||
public String getTemplateAssetsUrl()
|
||||
{
|
||||
return templateAssetsUrl;
|
||||
}
|
||||
|
||||
public Map<String, String> getProperties()
|
||||
{
|
||||
return Collections.unmodifiableMap(properties);
|
||||
}
|
||||
|
||||
public String getProperty(String propName)
|
||||
{
|
||||
return properties.get(propName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
@@ -314,8 +353,8 @@ public class ClientAppConfig extends AbstractLifecycleBean
|
||||
{
|
||||
final StringBuilder sb = new StringBuilder(250);
|
||||
sb.append("ClientApp [name=").append(name)
|
||||
.append(", sharedLinkBaseUrl=").append(sharedLinkBaseUrl)
|
||||
.append(", templateAssetsUrl=").append(templateAssetsUrl)
|
||||
.append(", properties=").append(properties)
|
||||
.append(']');
|
||||
return sb.toString();
|
||||
}
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -44,6 +44,7 @@ import org.alfresco.model.QuickShareModel;
|
||||
import org.alfresco.repo.Client;
|
||||
import org.alfresco.repo.Client.ClientType;
|
||||
import org.alfresco.repo.action.executer.MailActionExecuter;
|
||||
import org.alfresco.repo.client.config.ClientAppConfig;
|
||||
import org.alfresco.repo.copy.CopyBehaviourCallback;
|
||||
import org.alfresco.repo.copy.CopyDetails;
|
||||
import org.alfresco.repo.copy.CopyServicePolicies;
|
||||
@@ -54,7 +55,7 @@ import org.alfresco.repo.node.NodeServicePolicies;
|
||||
import org.alfresco.repo.policy.BehaviourFilter;
|
||||
import org.alfresco.repo.policy.JavaBehaviour;
|
||||
import org.alfresco.repo.policy.PolicyComponent;
|
||||
import org.alfresco.repo.quickshare.ClientAppConfig.ClientApp;
|
||||
import org.alfresco.repo.client.config.ClientAppConfig.ClientApp;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
@@ -125,6 +126,7 @@ public class QuickShareServiceImpl implements QuickShareService,
|
||||
|
||||
static final String ATTR_KEY_SHAREDIDS_ROOT = ".sharedIds";
|
||||
|
||||
private static final String CONFIG_SHARED_LINK_BASE_URL = "sharedLinkBaseUrl";
|
||||
private static final String FTL_SHARED_NODE_URL = "shared_node_url";
|
||||
private static final String FTL_SHARED_NODE_NAME = "shared_node_name";
|
||||
private static final String FTL_SENDER_MESSAGE = "sender_message";
|
||||
@@ -914,11 +916,12 @@ public class QuickShareServiceImpl implements QuickShareService,
|
||||
Map<String, Serializable> templateModel = new HashMap<>(6);
|
||||
templateModel.put(FTL_SENDER_FIRST_NAME, senderFirstName);
|
||||
templateModel.put(FTL_SENDER_LAST_NAME, senderLastName);
|
||||
final String sharedNodeUrl = getUrl(clientApp.getSharedLinkBaseUrl()) + '/' + emailRequest.getSharedId();
|
||||
final String sharedNodeUrl = getUrl(clientApp.getProperty(CONFIG_SHARED_LINK_BASE_URL), CONFIG_SHARED_LINK_BASE_URL)
|
||||
+ '/' + emailRequest.getSharedId();
|
||||
templateModel.put(FTL_SHARED_NODE_URL, sharedNodeUrl);
|
||||
templateModel.put(FTL_SHARED_NODE_NAME, emailRequest.getSharedNodeName());
|
||||
templateModel.put(FTL_SENDER_MESSAGE, emailRequest.getSenderMessage());
|
||||
String templateAssetsUrl = getUrl(clientApp.getTemplateAssetsUrl());
|
||||
final String templateAssetsUrl = getUrl(clientApp.getTemplateAssetsUrl(), ClientAppConfig.PROP_TEMPLATE_ASSETS_URL);
|
||||
templateModel.put(FTL_TEMPLATE_ASSETS_URL, templateAssetsUrl);
|
||||
|
||||
// Set the email details
|
||||
@@ -999,8 +1002,13 @@ public class QuickShareServiceImpl implements QuickShareService,
|
||||
return nodeService.getProperty(parent, ContentModel.PROP_NAME).toString();
|
||||
}
|
||||
|
||||
private String getUrl(String url)
|
||||
private String getUrl(String url, String propName)
|
||||
{
|
||||
if (url == null)
|
||||
{
|
||||
logger.warn("URL for the property [" + propName + "] is not configured.");
|
||||
return "";
|
||||
}
|
||||
if (url.endsWith("/"))
|
||||
{
|
||||
return url.substring(0, url.length() - 1);
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -269,7 +269,7 @@ public class Repository01TestSuite extends TestSuite
|
||||
|
||||
static void tests40(TestSuite suite)
|
||||
{
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.quickshare.ClientAppConfigTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.client.config.ClientAppConfigTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.quickshare.QuickShareServiceIntegrationTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.rating.RatingServiceIntegrationTest.class));
|
||||
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.remotecredentials.RemoteCredentialsServicesTest.class));
|
||||
|
@@ -2,7 +2,7 @@
|
||||
* #%L
|
||||
* Alfresco Repository
|
||||
* %%
|
||||
* Copyright (C) 2005 - 2016 Alfresco Software Limited
|
||||
* Copyright (C) 2005 - 2017 Alfresco Software Limited
|
||||
* %%
|
||||
* This file is part of the Alfresco software.
|
||||
* If the software was purchased under a paid Alfresco license, the terms of
|
||||
@@ -24,18 +24,20 @@
|
||||
* #L%
|
||||
*/
|
||||
|
||||
package org.alfresco.repo.quickshare;
|
||||
package org.alfresco.repo.client.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import org.alfresco.repo.quickshare.ClientAppConfig.ClientApp;
|
||||
import org.alfresco.repo.client.config.ClientAppConfig.ClientApp;
|
||||
import org.alfresco.util.ApplicationContextHelper;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@@ -51,10 +53,10 @@ public class ClientAppConfigTest
|
||||
@BeforeClass
|
||||
public static void setUp() throws Exception
|
||||
{
|
||||
context = new ClassPathXmlApplicationContext(new String[] { "classpath:org/alfresco/repo/quickshare/test-quickshare-clients-context.xml" },
|
||||
context = new ClassPathXmlApplicationContext(new String[] { "classpath:org/alfresco/repo/client/config/test-repo-clients-apps-context.xml" },
|
||||
ApplicationContextHelper.getApplicationContext());
|
||||
|
||||
clientAppConfig = context.getBean("quickShareClientsConfigTest", ClientAppConfig.class);
|
||||
clientAppConfig = context.getBean("clientAppConfigTest", ClientAppConfig.class);
|
||||
|
||||
}
|
||||
|
||||
@@ -69,33 +71,54 @@ public class ClientAppConfigTest
|
||||
{
|
||||
Map<String, ClientApp> clients = clientAppConfig.getClients();
|
||||
assertNotNull(clients);
|
||||
assertEquals("Incorrect number of clients", 3, clients.size());
|
||||
assertEquals("Incorrect number of clients", 4, clients.size());
|
||||
|
||||
// loaded from org/alfresco/repo/quickshare/test-quickshare-clients-config.properties
|
||||
// loaded from org/alfresco/repo/client/config/test-repo-clients-apps.properties
|
||||
ClientApp client1 = clientAppConfig.getClient("test-client1");
|
||||
assertNotNull(client1);
|
||||
assertEquals("test-client1", client1.getName());
|
||||
assertEquals("http://localhost:8081/test-client1/o", client1.getSharedLinkBaseUrl());
|
||||
assertEquals("http://localhost:8081/test-client1/o", client1.getProperty("sharedLinkBaseUrl"));
|
||||
assertEquals("http://localhost:8081/test-client1", client1.getTemplateAssetsUrl());
|
||||
|
||||
// loaded from org/alfresco/repo/quickshare/test-quickshare-clients-config.properties and overridden by
|
||||
// org/alfresco/repo/quickshare/test-global-properties.properties
|
||||
// loaded from org/alfresco/repo/client/config/test-repo-clients-apps.properties and overridden by
|
||||
// org/alfresco/repo/client/config/test-global-properties.properties
|
||||
ClientApp client2 = clientAppConfig.getClient("test-client2");
|
||||
assertNotNull(client2);
|
||||
assertEquals("test-client2", client2.getName());
|
||||
assertEquals("https://127.0.0.1:8082/test-client2/t", client2.getSharedLinkBaseUrl());
|
||||
assertEquals("https://127.0.0.1:8082/test-client2/t", client2.getProperty("sharedLinkBaseUrl"));
|
||||
assertEquals("https://127.0.0.1:8082/test-client2", client2.getTemplateAssetsUrl());
|
||||
|
||||
// loaded from org/alfresco/repo/quickshare/test-global-properties.properties
|
||||
// loaded from org/alfresco/repo/client/config/test-global-properties.properties
|
||||
ClientApp client3 = clientAppConfig.getClient("test-client5");
|
||||
assertNotNull(client3);
|
||||
assertEquals("test-client5", client3.getName());
|
||||
assertEquals("http://localhost:8085/test-client5/f", client3.getSharedLinkBaseUrl());
|
||||
assertEquals("http://localhost:8085/test-client5", client3.getTemplateAssetsUrl());
|
||||
assertEquals("http://localhost:8085/test-client5/f", client3.getProperty("myProp1"));
|
||||
assertEquals("http://localhost:8085/test-client5", client3.getProperty("myProp2"));
|
||||
assertEquals("test prop3", client3.getProperty("myProp3"));
|
||||
assertEquals("test prop4", client3.getProperty("myProp4"));
|
||||
assertEquals("test prop5", client3.getProperty("myProp5-with-hyphen"));
|
||||
assertNull(client3.getTemplateAssetsUrl());
|
||||
|
||||
// loaded from org/alfresco/repo/client/config/test-global-properties.properties
|
||||
ClientApp client4 = clientAppConfig.getClient("test-client11");
|
||||
assertNotNull(client4);
|
||||
assertEquals("test-client11", client4.getName());
|
||||
assertEquals("http://localhost:8811/test-client11/t", client4.getProperty("myClientRequiredConfigUrl"));
|
||||
assertNull(client4.getTemplateAssetsUrl());
|
||||
// Try to add a property into an unmodifiable map
|
||||
try
|
||||
{
|
||||
client4.getProperties().put("newProperty"," test value");
|
||||
fail("Shouldn't be able to modify the client's processed properties.");
|
||||
}
|
||||
catch (UnsupportedOperationException ex)
|
||||
{
|
||||
// expected
|
||||
}
|
||||
|
||||
// Try to add a client into an unmodifiable map
|
||||
ClientApp newClient = new ClientApp("testClient" + System.currentTimeMillis(), "http://localhost:8085/test-client/s",
|
||||
"http://localhost:8085/testclient");
|
||||
ClientApp newClient = new ClientApp("testClient" + System.currentTimeMillis(),
|
||||
"http://localhost:8085/testclient", Collections.singletonMap("sharedLinkBaseUrl", "http://localhost:8085/test-client/s"));
|
||||
try
|
||||
{
|
||||
clients.put(newClient.getName(), newClient);
|
@@ -0,0 +1,38 @@
|
||||
# Simulate the alfresco global properties file
|
||||
|
||||
# Override the default properties of client2
|
||||
repo.client-app.test-client2.sharedLinkBaseUrl=https://127.0.0.1:8082/test-client2/t
|
||||
repo.client-app.test-client2.templateAssetsUrl=https://127.0.0.1:8082/test-client2
|
||||
|
||||
# Add a new client with a few properties
|
||||
repo.client-app.test-client5.myProp1=http://localhost:8085/test-client5/f
|
||||
repo.client-app.test-client5.myProp2=http://localhost:8085/test-client5
|
||||
repo.client-app.test-client5.myProp3=test prop3
|
||||
repo.client-app.test-client5.myProp4=test prop4
|
||||
repo.client-app.test-client5.myProp5-with-hyphen=test prop5
|
||||
|
||||
# Try to override the default properties of client1 with invalid values
|
||||
repo.client-app.test-client1.sharedLinkBaseUrl=
|
||||
repo.client-app.test-client1.templateAssetsUrl=
|
||||
|
||||
# Invalid keys - undefined key structure
|
||||
repo.client-app.invalid.test-client6.sharedLinkBaseUrl=http://localhost:8086/test-client6/s
|
||||
repo.client-app.invalid.test-client6.templateAssetsUrl=http://localhost:8086/test-client6
|
||||
|
||||
# Invalid keys - undefined key structure
|
||||
invalid.test-client7.sharedLinkBaseUrl=http://localhost:8087/test-client7/s
|
||||
invalid.test-client7.templateAssetsUrl=http://localhost:8087/test-client7
|
||||
|
||||
# Invalid keys - undefined key structure
|
||||
repo.client-app.test-client8.invalid.sharedLinkBaseUrl=http://localhost:8088/test-client8/e
|
||||
repo.client-app.test-client8.invalid.templateAssetsUrl=http://localhost:8088/test-client8
|
||||
|
||||
# Invalid key - missing the property name after the dot
|
||||
repo.client-app.test-client9.=http://localhost:8089/test-client9
|
||||
|
||||
# Invalid key - missing the property name
|
||||
repo.client-app.test-client10=http://localhost:8810/test-client10
|
||||
|
||||
# Register a client with only one configuration
|
||||
repo.client-app.test-client11.myClientRequiredConfigUrl=http://localhost:8811/test-client11/t
|
||||
|
@@ -3,10 +3,10 @@
|
||||
|
||||
<beans>
|
||||
|
||||
<bean id="quickShareDefaultPropertiesTest" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<bean id="clientAppDefaultPropertiesTest" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<property name="locations">
|
||||
<list>
|
||||
<value>classpath*:org/alfresco/repo/quickshare/test-quickshare-clients-config.properties</value>
|
||||
<value>classpath*:org/alfresco/repo/client/config/test-repo-clients-apps.properties</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
@@ -14,13 +14,13 @@
|
||||
<bean id="globalPropertiesTest" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
|
||||
<property name="locations">
|
||||
<list>
|
||||
<value>classpath*:org/alfresco/repo/quickshare/test-global-properties.properties</value>
|
||||
<value>classpath*:org/alfresco/repo/client/config/test-global-properties.properties</value>
|
||||
</list>
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="quickShareClientsConfigTest" class="org.alfresco.repo.quickshare.ClientAppConfig">
|
||||
<property name="defaultProperties" ref="quickShareDefaultPropertiesTest"/>
|
||||
<bean id="clientAppConfigTest" class="org.alfresco.repo.client.config.ClientAppConfig">
|
||||
<property name="defaultProperties" ref="clientAppDefaultPropertiesTest"/>
|
||||
<property name="globalProperties" ref="globalPropertiesTest"/>
|
||||
</bean>
|
||||
</beans>
|
@@ -0,0 +1,15 @@
|
||||
# registry of clients that are able to email shared links
|
||||
|
||||
repo.client-app.test-client1.sharedLinkBaseUrl=http://localhost:8081/test-client1/o
|
||||
repo.client-app.test-client1.templateAssetsUrl=http://localhost:8081/test-client1
|
||||
|
||||
repo.client-app.test-client2.sharedLinkBaseUrl=http://localhost:8082/test-client2/t
|
||||
repo.client-app.test-client2.templateAssetsUrl=http://localhost:8082/test-client2
|
||||
|
||||
# Invalid keys - undefined key structure
|
||||
invalid.test-client3.sharedLinkBaseUrl=http://localhost:8083/test-client3/s
|
||||
invalid.test-client3.templateAssetsUrl=http://localhost:8083/test-client3
|
||||
|
||||
# Invalid values. As there are no values for this client, then is shouldn't be registered.
|
||||
repo.client-app.test-client4.sharedLinkBaseUrl=
|
||||
repo.client-app.test-client4.templateAssetsUrl=
|
@@ -1,41 +0,0 @@
|
||||
# Simulate the alfresco global properties file
|
||||
|
||||
# Override the default properties of client2
|
||||
quickshare.client.test-client2.sharedLinkBaseUrl=https://127.0.0.1:8082/test-client2/t
|
||||
quickshare.client.test-client2.templateAssetsUrl=https://127.0.0.1:8082/test-client2
|
||||
|
||||
# Add a new client
|
||||
quickshare.client.test-client5.sharedLinkBaseUrl=http://localhost:8085/test-client5/f
|
||||
quickshare.client.test-client5.templateAssetsUrl=http://localhost:8085/test-client5
|
||||
|
||||
# Try to override the default properties of client1 with invalid values
|
||||
quickshare.client.test-client1.sharedLinkBaseUrl=
|
||||
quickshare.client.test-client1.templateAssetsUrl=
|
||||
|
||||
# Invalid keys - undefined key structure
|
||||
quickshare.client.invalid.test-client6.sharedLinkBaseUrl=http://localhost:8086/test-client6/s
|
||||
quickshare.client.invalid.test-client6.templateAssetsUrl=http://localhost:8086/test-client6
|
||||
|
||||
# Invalid keys - undefined key structure
|
||||
invalid.test-client7.sharedLinkBaseUrl=http://localhost:8087/test-client7/s
|
||||
invalid.test-client7.templateAssetsUrl=http://localhost:8087/test-client7
|
||||
|
||||
# Invalid keys - undefined key structure
|
||||
quickshare.client.test-client8.invalid.sharedLinkBaseUrl=http://localhost:8088/test-client8/e
|
||||
quickshare.client.test-client8.invalid.templateAssetsUrl=http://localhost:8088/test-client8
|
||||
|
||||
# Invalid key - missing the required 'sharedLinkBaseUrl' and 'templateAssetsUrl' after the dot
|
||||
quickshare.client.test-client9.=http://localhost:8089/test-client9
|
||||
|
||||
# Invalid key - missing the required 'sharedLinkBaseUrl' and 'templateAssetsUrl'
|
||||
quickshare.client.test-client10=http://localhost:8810/test-client10
|
||||
|
||||
# Invalid keys - undefined 'sharedLink' and 'templateUrl'
|
||||
quickshare.client.test-client11.sharedLink=http://localhost:8811/test-client11/e
|
||||
quickshare.client.test-client11.templateUrl=http://localhost:8811/test-client11
|
||||
|
||||
# Invalid client config - missing the required 'templateAssetsUrl' config
|
||||
quickshare.client.test-client12.sharedLinkBaseUrl=http://localhost:8812/test-client12/t
|
||||
|
||||
# Invalid client config - missing the required 'sharedLinkBaseUrl' config
|
||||
quickshare.client.test-client13.templateAssetsUrl=http://localhost:8812/test-client13
|
@@ -1,15 +0,0 @@
|
||||
# registry of clients that are able to email shared links
|
||||
|
||||
quickshare.client.test-client1.sharedLinkBaseUrl=http://localhost:8081/test-client1/o
|
||||
quickshare.client.test-client1.templateAssetsUrl=http://localhost:8081/test-client1
|
||||
|
||||
quickshare.client.test-client2.sharedLinkBaseUrl=http://localhost:8082/test-client2/t
|
||||
quickshare.client.test-client2.templateAssetsUrl=http://localhost:8082/test-client2
|
||||
|
||||
# Invalid keys - undefined key structure
|
||||
invalid.test-client3.sharedLinkBaseUrl=http://localhost:8083/test-client3/s
|
||||
invalid.test-client3.templateAssetsUrl=http://localhost:8083/test-client3
|
||||
|
||||
# Invalid values
|
||||
quickshare.client.test-client4.sharedLinkBaseUrl=
|
||||
quickshare.client.test-client4.templateAssetsUrl=
|
Reference in New Issue
Block a user