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:
Ancuta Morarasu
2016-05-11 12:11:01 +00:00
parent 85decb5bd2
commit 03b2b9ea85
8 changed files with 255 additions and 43 deletions

View File

@@ -59,7 +59,7 @@
</property>
</bean>
<bean id="quickShareClientsConfig" class="org.alfresco.repo.quickshare.ClientAppConfig">
<bean id="quickShareClientsConfig" class="org.alfresco.repo.quickshare.ClientAppConfig" init-method="init">
<property name="defaultProperties" ref="quickShareDefaultProperties"/>
<property name="globalProperties" ref="global-properties"/>
</bean>

View File

@@ -322,7 +322,9 @@ middle;"><p>${shared_node_name} shared with you</p></span></div>
<div class="mktEditable" id="Body Text 1" align="left">
<span style="color:#727174; font-family:Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size:18px;font-weight:400; text-align:left; text-decoration:none; -webkit-text-size-adjust:none;">
<p>${sender_first_name} ${sender_last_name} has shared <a href="${shared_node_url}">${shared_node_name}</a> with you.</p>
<#if sender_message??>
<p>${sender_message}</p>
</#if>
</span>
</div>

View File

@@ -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;

View File

@@ -268,6 +268,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.quickshare.QuickShareServiceIntegrationTest.class));
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.rating.RatingServiceIntegrationTest.class));
suite.addTest(new JUnit4TestAdapter(org.alfresco.repo.remotecredentials.RemoteCredentialsServicesTest.class));

View File

@@ -0,0 +1,102 @@
/*
* Copyright (C) 2005-2016 Alfresco Software Limited.
*
* This file is part of Alfresco
*
* Alfresco is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Alfresco is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Alfresco. If not, see <http://www.gnu.org/licenses/>.
*/
package org.alfresco.repo.quickshare;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.fail;
import org.alfresco.repo.quickshare.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.Map;
/**
* This class contains tests for the class {@link ClientAppConfig}
*
* @author Jamal Kaabi-Mofrad
*/
public class ClientAppConfigTest
{
private static ClassPathXmlApplicationContext context;
private static ClientAppConfig clientAppConfig;
@BeforeClass
public static void setUp() throws Exception
{
context = new ClassPathXmlApplicationContext(new String[] { "classpath:org/alfresco/repo/quickshare/test-quickshare-clients-context.xml" },
ApplicationContextHelper.getApplicationContext());
clientAppConfig = context.getBean("quickShareClientsConfigTest", ClientAppConfig.class);
}
@AfterClass
public static void tearDown() throws Exception
{
context.close();
}
@Test
public void testClients() throws Exception
{
Map<String, ClientApp> clients = clientAppConfig.getClients();
assertNotNull(clients);
assertEquals("Incorrect number of clients", 3, clients.size());
// loaded from org/alfresco/repo/quickshare/test-quickshare-clients-config.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", client1.getTemplateAssetsUrl());
// loaded from org/alfresco/repo/quickshare/test-quickshare-clients-config.properties and overridden by
// org/alfresco/repo/quickshare/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", client2.getTemplateAssetsUrl());
// loaded from org/alfresco/repo/quickshare/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());
// 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");
try
{
clients.put(newClient.getName(), newClient);
fail("Shouldn't be able to modify the clients map.");
}
catch (UnsupportedOperationException ex)
{
// expected
}
}
}

View File

@@ -0,0 +1,41 @@
# 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

View File

@@ -0,0 +1,15 @@
# 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=

View File

@@ -0,0 +1,26 @@
<?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="quickShareDefaultPropertiesTest" class="org.springframework.beans.factory.config.PropertiesFactoryBean">
<property name="locations">
<list>
<value>classpath*:org/alfresco/repo/quickshare/test-quickshare-clients-config.properties</value>
</list>
</property>
</bean>
<!-- simulate the alfresco global properties bean -->
<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>
</list>
</property>
</bean>
<bean id="quickShareClientsConfigTest" class="org.alfresco.repo.quickshare.ClientAppConfig">
<property name="defaultProperties" ref="quickShareDefaultPropertiesTest"/>
<property name="globalProperties" ref="globalPropertiesTest"/>
</bean>
</beans>