mirror of
https://github.com/Alfresco/alfresco-community-repo.git
synced 2025-10-08 14:51:49 +00:00
Merged FILE-FOLDER-API (5.2.0) to HEAD (5.2)
124158 jkaabimofrad: SFS-405, RA-778: (WIP) - Added quick-share client registry config. - Modified the send shared-link email API, based on the revised acceptance criteria. git-svn-id: https://svn.alfresco.com/repos/alfresco-enterprise/alfresco/HEAD/root@126547 c4b6b30b-aa2e-2d43-bbcb-ca4b014f7261
This commit is contained in:
@@ -29,7 +29,6 @@ import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.alfresco.error.AlfrescoRuntimeException;
|
||||
import org.alfresco.events.types.ActivityEvent;
|
||||
import org.alfresco.events.types.Event;
|
||||
import org.alfresco.model.ContentModel;
|
||||
@@ -47,6 +46,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.security.authentication.AuthenticationUtil;
|
||||
import org.alfresco.repo.security.authentication.AuthenticationUtil.RunAsWork;
|
||||
import org.alfresco.repo.security.permissions.AccessDeniedException;
|
||||
@@ -105,7 +105,9 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
||||
private static final String FTL_SENDER_MESSAGE = "sender_message";
|
||||
private static final String FTL_SENDER_FIRST_NAME = "sender_first_name";
|
||||
private static final String FTL_SENDER_LAST_NAME = "sender_last_name";
|
||||
private static final String FTL_TEMPLATE_ASSETS_URL = "template_assets_url";
|
||||
private static final String DEFAULT_EMAIL_SUBJECT = "quickshare.notifier.email.subject";
|
||||
private static final String EMAIL_TEMPLATE_REF ="alfresco/templates/quickshare-email-templates/quickshare-email.default.template.ftl";
|
||||
|
||||
private AttributeService attributeService;
|
||||
private DictionaryService dictionaryService;
|
||||
@@ -123,7 +125,7 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
||||
|
||||
private boolean enabled;
|
||||
private String defaultEmailSender;
|
||||
private Map<String, String> templateRegistry;
|
||||
private ClientAppConfig clientAppConfig;
|
||||
|
||||
/**
|
||||
* Set the attribute service
|
||||
@@ -240,11 +242,11 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the templates
|
||||
* Set the quickShare clientAppConfig
|
||||
*/
|
||||
public void setTemplateRegistry(Map<String, String> templateRegistry)
|
||||
public void setClientAppConfig(ClientAppConfig clientAppConfig)
|
||||
{
|
||||
this.templateRegistry = templateRegistry;
|
||||
this.clientAppConfig = clientAppConfig;
|
||||
}
|
||||
|
||||
private void checkMandatoryProperties()
|
||||
@@ -262,7 +264,7 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
||||
PropertyCheck.mandatory(this, "preferenceService", preferenceService);
|
||||
PropertyCheck.mandatory(this, "behaviourFilter", behaviourFilter);
|
||||
PropertyCheck.mandatory(this, "defaultEmailSender", defaultEmailSender);
|
||||
PropertyCheck.mandatory(this, "templateRegistry", templateRegistry);
|
||||
PropertyCheck.mandatory(this, "clientAppConfig", clientAppConfig);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -677,9 +679,10 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
||||
ParameterCheck.mandatory("emailRequest", emailRequest);
|
||||
emailRequest.validate();
|
||||
|
||||
if (!templateRegistry.containsKey(emailRequest.getTemplateId()))
|
||||
ClientApp clientApp = clientAppConfig.getClient(emailRequest.getClient());
|
||||
if (clientApp == null)
|
||||
{
|
||||
throw new AlfrescoRuntimeException("Invalid template. Couldn't find a template with id:" + emailRequest.getTemplateId());
|
||||
throw new QuickShareClientNotFoundException("Client was not found [" + emailRequest.getClient() + "]");
|
||||
}
|
||||
|
||||
// Set the details of the person sending the email
|
||||
@@ -688,31 +691,30 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
||||
final Map<QName, Serializable> senderProps = nodeService.getProperties(senderNodeRef);
|
||||
final String senderFirstName = (String) senderProps.get(ContentModel.PROP_FIRSTNAME);
|
||||
final String senderLastName = (String) senderProps.get(ContentModel.PROP_LASTNAME);
|
||||
final String senderEmail = (String) senderProps.get(ContentModel.PROP_EMAIL);
|
||||
final String senderFullName = ((senderFirstName != null ? senderFirstName + " " : "") + (senderLastName != null ? senderLastName : "")).trim();
|
||||
|
||||
// Set the default model information
|
||||
Map<String, Serializable> templateModel = new HashMap<>(5);
|
||||
Map<String, Serializable> templateModel = new HashMap<>(6);
|
||||
templateModel.put(FTL_SENDER_FIRST_NAME, senderFirstName);
|
||||
templateModel.put(FTL_SENDER_LAST_NAME, senderLastName);
|
||||
templateModel.put(FTL_SHARED_NODE_URL, emailRequest.getSharedNodeURL());
|
||||
final String sharedNodeUrl = getUrl(clientApp.getSharedLinkBaseUrl()) + '/' + emailRequest.getSharedId();
|
||||
templateModel.put(FTL_SHARED_NODE_URL, sharedNodeUrl);
|
||||
templateModel.put(FTL_SHARED_NODE_NAME, emailRequest.getSharedNodeName());
|
||||
templateModel.put(FTL_SENDER_MESSAGE, emailRequest.getSenderMessage());
|
||||
|
||||
// Email sender
|
||||
// By default the current-user's email address will not be used to send this mail.
|
||||
// However, current-user's first and lastname will be used as the personal name.
|
||||
final String from = (!emailRequest.isSendFromDefaultEmail() && senderEmail != null) ? senderEmail : this.defaultEmailSender;
|
||||
String templateAssetsUrl = getUrl(clientApp.getTemplateAssetsUrl());
|
||||
templateModel.put(FTL_TEMPLATE_ASSETS_URL, templateAssetsUrl);
|
||||
|
||||
// Set the email details
|
||||
Map<String, Serializable> actionParams = new HashMap<>();
|
||||
actionParams.put(MailActionExecuter.PARAM_FROM, from);
|
||||
// Email sender. By default the current-user's email address will not be used to send this mail.
|
||||
// However, current-user's first and lastname will be used as the personal name.
|
||||
actionParams.put(MailActionExecuter.PARAM_FROM, this.defaultEmailSender);
|
||||
actionParams.put(MailActionExecuter.PARAM_FROM_PERSONAL_NAME, senderFullName);
|
||||
actionParams.put(MailActionExecuter.PARAM_SUBJECT, DEFAULT_EMAIL_SUBJECT);
|
||||
actionParams.put(MailActionExecuter.PARAM_SUBJECT_PARAMS, new Object[] { senderFirstName, senderLastName, emailRequest.getSharedNodeName() });
|
||||
actionParams.put(MailActionExecuter.PARAM_IGNORE_SEND_FAILURE, emailRequest.isIgnoreSendFailure());
|
||||
// Pick the template
|
||||
actionParams.put(MailActionExecuter.PARAM_TEMPLATE, templateRegistry.get(emailRequest.getTemplateId()));
|
||||
actionParams.put(MailActionExecuter.PARAM_TEMPLATE, EMAIL_TEMPLATE_REF);
|
||||
actionParams.put(MailActionExecuter.PARAM_TEMPLATE_MODEL, (Serializable) templateModel);
|
||||
actionParams.put(MailActionExecuter.PARAM_LOCALE, getDefaultIfNull(getEmailCreatorLocale(authenticatedUser), emailRequest.getLocale()));
|
||||
|
||||
@@ -725,6 +727,15 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
||||
}
|
||||
}
|
||||
|
||||
private String getUrl(String url)
|
||||
{
|
||||
if (url.endsWith("/"))
|
||||
{
|
||||
return url.substring(0, url.length() - 1);
|
||||
}
|
||||
return url;
|
||||
}
|
||||
|
||||
private <T> T getDefaultIfNull(T defaultValue, T newValue)
|
||||
{
|
||||
return (newValue == null) ? defaultValue : newValue;
|
||||
@@ -742,11 +753,9 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
||||
public static class QuickShareEmailRequest
|
||||
{
|
||||
/**
|
||||
* Whether to send an email from the default email address or use the current-user's email (if not null).
|
||||
* The default is true.
|
||||
* The client's name that must be registered in order to send emails.
|
||||
*/
|
||||
private boolean sendFromDefaultEmail = true;
|
||||
|
||||
private String client;
|
||||
/**
|
||||
* Optional Locale for subject and body text
|
||||
*/
|
||||
@@ -758,19 +767,15 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
||||
private Set<String> toEmails;
|
||||
|
||||
/**
|
||||
* The template id. If not provided, a default template will be used.
|
||||
* The shared id.
|
||||
*/
|
||||
private String templateId = "default";
|
||||
|
||||
/**
|
||||
* The shared content URL.
|
||||
*/
|
||||
private String sharedNodeURL;
|
||||
private String sharedId;
|
||||
|
||||
/**
|
||||
* The shared content name.
|
||||
*/
|
||||
private String sharedNodeName;
|
||||
|
||||
/**
|
||||
* Optional message from the sender.
|
||||
*/
|
||||
@@ -784,29 +789,8 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
||||
public void validate()
|
||||
{
|
||||
ParameterCheck.mandatoryCollection("toEmails", toEmails);
|
||||
ParameterCheck.mandatoryString("templateId", templateId);
|
||||
ParameterCheck.mandatoryString("sharedNodeURL", sharedNodeURL);
|
||||
ParameterCheck.mandatoryString("sharedId", sharedId);
|
||||
ParameterCheck.mandatoryString("sharedNodeName", sharedNodeName);
|
||||
ParameterCheck.mandatoryString("senderMessage", senderMessage);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link QuickShareEmailRequest#sendFromDefaultEmail}
|
||||
*/
|
||||
public boolean isSendFromDefaultEmail()
|
||||
{
|
||||
return sendFromDefaultEmail;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link QuickShareEmailRequest#sendFromDefaultEmail}
|
||||
*/
|
||||
public void setSendFromDefaultEmail(Boolean sendFromDefaultEmail)
|
||||
{
|
||||
if (sendFromDefaultEmail != null)
|
||||
{
|
||||
this.sendFromDefaultEmail = sendFromDefaultEmail;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -845,38 +829,37 @@ public class QuickShareServiceImpl implements QuickShareService, NodeServicePoli
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link QuickShareEmailRequest#templateId}
|
||||
* {@link QuickShareEmailRequest#client}
|
||||
*/
|
||||
public String getTemplateId()
|
||||
public String getClient()
|
||||
{
|
||||
return templateId;
|
||||
return client;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link QuickShareEmailRequest#templateId}
|
||||
* {@link QuickShareEmailRequest#client}
|
||||
*/
|
||||
public void setTemplateId(String templateId)
|
||||
public QuickShareEmailRequest setClient(String client)
|
||||
{
|
||||
if (templateId != null)
|
||||
{
|
||||
this.templateId = templateId;
|
||||
}
|
||||
this.client = client;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link QuickShareEmailRequest#sharedNodeURL}
|
||||
* {@link QuickShareEmailRequest#sharedId}
|
||||
*/
|
||||
public String getSharedNodeURL()
|
||||
public String getSharedId()
|
||||
{
|
||||
return sharedNodeURL;
|
||||
return sharedId;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link QuickShareEmailRequest#sharedNodeURL}
|
||||
* {@link QuickShareEmailRequest#sharedId}
|
||||
*/
|
||||
public void setSharedNodeURL(String sharedNodeURL)
|
||||
public QuickShareEmailRequest setSharedId(String sharedId)
|
||||
{
|
||||
this.sharedNodeURL = sharedNodeURL;
|
||||
this.sharedId = sharedId;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user