diff --git a/source/java/org/alfresco/rest/api/QuickShareLinks.java b/source/java/org/alfresco/rest/api/QuickShareLinks.java index eaa781bc37..9375f9e056 100644 --- a/source/java/org/alfresco/rest/api/QuickShareLinks.java +++ b/source/java/org/alfresco/rest/api/QuickShareLinks.java @@ -19,15 +19,18 @@ package org.alfresco.rest.api; import org.alfresco.rest.api.model.QuickShareLink; +import org.alfresco.rest.api.model.QuickShareLinkEmailRequest; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.resource.content.BinaryResource; import org.alfresco.rest.framework.resource.parameters.Parameters; + import java.util.List; /** * Centralises access to quick share services and maps between representations. * * @author janv + * @author Jamal Kaabi-Mofrad * * @since publicapi1.0 */ @@ -74,4 +77,13 @@ public interface QuickShareLinks * @return */ List create(List nodeIds, Parameters parameters); + + /** + * Notifies users by email that a content has been shared with them. + * + * @param nodeId The content id + * @param emailRequest The email details including its template details + * @param parameters The {@link Parameters} object to get the parameters passed into the request + */ + void emailSharedLink(String nodeId, QuickShareLinkEmailRequest emailRequest, Parameters parameters); } \ No newline at end of file diff --git a/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java b/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java index 50b9db2a10..363e21dcdd 100644 --- a/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java +++ b/source/java/org/alfresco/rest/api/impl/QuickShareLinksImpl.java @@ -18,7 +18,9 @@ */ package org.alfresco.rest.api.impl; +import org.alfresco.model.ContentModel; import org.alfresco.model.QuickShareModel; +import org.alfresco.repo.quickshare.QuickShareServiceImpl.QuickShareEmailRequest; import org.alfresco.repo.security.authentication.AuthenticationUtil; import org.alfresco.repo.security.permissions.AccessDeniedException; import org.alfresco.repo.tenant.TenantUtil; @@ -26,6 +28,7 @@ import org.alfresco.rest.api.Nodes; import org.alfresco.rest.api.QuickShareLinks; import org.alfresco.rest.api.model.ContentInfo; import org.alfresco.rest.api.model.QuickShareLink; +import org.alfresco.rest.api.model.QuickShareLinkEmailRequest; import org.alfresco.rest.api.model.UserInfo; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; import org.alfresco.rest.framework.core.exceptions.InvalidArgumentException; @@ -47,6 +50,7 @@ import org.alfresco.util.ParameterCheck; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.springframework.beans.factory.InitializingBean; +import org.springframework.extensions.surf.util.I18NUtil; import java.util.ArrayList; import java.util.Date; @@ -59,6 +63,7 @@ import java.util.Map; * TODO - if QuickShare is disabled should we return 403 (as below) or 404 (eg. when accessing a link) ? * * @author janv + * @author Jamal Kaabi-Mofrad * * @since publicapi1.0 */ @@ -266,6 +271,35 @@ public class QuickShareLinksImpl implements QuickShareLinks, InitializingBean return result; } + @Override + public void emailSharedLink(String nodeId, QuickShareLinkEmailRequest emailRequest, Parameters parameters) + { + try + { NodeRef nodeRef = nodes.validateNode(nodeId); + final String nodeName = (String) nodeService.getProperty(nodeRef, ContentModel.PROP_NAME); + + QuickShareEmailRequest request = new QuickShareEmailRequest(); + request.setSharedNodeName(nodeName); + request.setSharedNodeURL(emailRequest.getSharedNodeUrl()); + request.setSenderMessage(emailRequest.getMessage()); + request.setLocale(I18NUtil.parseLocale(emailRequest.getLocale())); + request.setTemplateId(emailRequest.getTemplateId()); + request.setToEmails(emailRequest.getRecipientEmails()); + request.setSendFromDefaultEmail(emailRequest.getIsSendFromDefaultEmail()); + request.setIgnoreSendFailure(emailRequest.getIsIgnoreSendFailure()); + quickShareService.sendEmailNotification(request); + } + catch (Exception ex) + { + String errorMsg = ex.getMessage(); + if (errorMsg == null) + { + errorMsg = ""; + } + throw new InvalidArgumentException("Couldn't send an email. " + errorMsg); + } + } + private QuickShareLink getQuickShareInfo(String sharedId) { checkValidShareId(sharedId); diff --git a/source/java/org/alfresco/rest/api/model/QuickShareLinkEmailRequest.java b/source/java/org/alfresco/rest/api/model/QuickShareLinkEmailRequest.java new file mode 100644 index 0000000000..a7f01a5ba9 --- /dev/null +++ b/source/java/org/alfresco/rest/api/model/QuickShareLinkEmailRequest.java @@ -0,0 +1,123 @@ +/* + * 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 . + */ + +package org.alfresco.rest.api.model; + +import java.util.List; + +/** + * Representation of an email request for the quick share link + * + * @author Jamal Kaabi-Mofrad + */ +public class QuickShareLinkEmailRequest extends Target +{ + private String templateId; + private String sharedNodeUrl; + private String message; + private String locale; + private List recipientEmails; + private Boolean isSendFromDefaultEmail; + private Boolean isIgnoreSendFailure; + + public String getTemplateId() + { + return templateId; + } + + public void setTemplateId(String templateId) + { + this.templateId = templateId; + } + + public String getSharedNodeUrl() + { + return sharedNodeUrl; + } + + public void setSharedNodeUrl(String sharedNodeUrl) + { + this.sharedNodeUrl = sharedNodeUrl; + } + + public String getMessage() + { + return message; + } + + public void setMessage(String message) + { + this.message = message; + } + + public String getLocale() + { + return locale; + } + + public void setLocale(String locale) + { + this.locale = locale; + } + + public List getRecipientEmails() + { + return recipientEmails; + } + + public void setRecipientEmails(List recipientEmails) + { + this.recipientEmails = recipientEmails; + } + + public Boolean getIsSendFromDefaultEmail() + { + return isSendFromDefaultEmail; + } + + public void setIsSendFromDefaultEmail(Boolean isSendFromDefaultEmail) + { + this.isSendFromDefaultEmail = isSendFromDefaultEmail; + } + + public Boolean getIsIgnoreSendFailure() + { + return isIgnoreSendFailure; + } + + public void setIsIgnoreSendFailure(Boolean isIgnoreSendFailure) + { + this.isIgnoreSendFailure = isIgnoreSendFailure; + } + + @Override + public String toString() + { + final StringBuilder sb = new StringBuilder(250); + sb.append("QuickShareLinkEmailRequest [templateId='").append(templateId) + .append(", sharedNodeUrl='").append(sharedNodeUrl) + .append(", message='").append(message) + .append(", locale='").append(locale) + .append(", recipientEmails=").append(recipientEmails) + .append(", isSendFromDefaultEmail").append(isSendFromDefaultEmail) + .append(", isIgnoreSendFailure=").append(isIgnoreSendFailure) + .append(']'); + return sb.toString(); + } +} diff --git a/source/java/org/alfresco/rest/api/quicksharelinks/QuickShareLinkEntityResource.java b/source/java/org/alfresco/rest/api/quicksharelinks/QuickShareLinkEntityResource.java index 9b37784612..b5d0957d68 100644 --- a/source/java/org/alfresco/rest/api/quicksharelinks/QuickShareLinkEntityResource.java +++ b/source/java/org/alfresco/rest/api/quicksharelinks/QuickShareLinkEntityResource.java @@ -20,7 +20,9 @@ package org.alfresco.rest.api.quicksharelinks; import org.alfresco.rest.api.QuickShareLinks; import org.alfresco.rest.api.model.QuickShareLink; +import org.alfresco.rest.api.model.QuickShareLinkEmailRequest; import org.alfresco.rest.framework.BinaryProperties; +import org.alfresco.rest.framework.Operation; import org.alfresco.rest.framework.WebApiDescription; import org.alfresco.rest.framework.WebApiNoAuth; import org.alfresco.rest.framework.core.exceptions.EntityNotFoundException; @@ -38,6 +40,7 @@ import java.util.List; * An implementation of an Entity Resource for Shared Links. * * @author janv + * @author Jamal Kaabi-Mofrad */ @EntityResource(name="shared-links", title = "Shared Links") public class QuickShareLinkEntityResource implements EntityResourceAction.ReadById, @@ -46,10 +49,10 @@ public class QuickShareLinkEntityResource implements EntityResourceAction.ReadBy { private QuickShareLinks quickShareLinks; - public void setQuickShareLinks(QuickShareLinks quickShareLinks) - { - this.quickShareLinks = quickShareLinks; - } + public void setQuickShareLinks(QuickShareLinks quickShareLinks) + { + this.quickShareLinks = quickShareLinks; + } @Override public void afterPropertiesSet() @@ -121,4 +124,11 @@ public class QuickShareLinkEntityResource implements EntityResourceAction.ReadBy { return quickShareLinks.create(nodeIds, parameters); } + + @Operation("email") + @WebApiDescription(title = "Email shared link", description = "Email the shared link") + public void email(String nodeId, QuickShareLinkEmailRequest emailRequest, Parameters parameters) + { + quickShareLinks.emailSharedLink(nodeId, emailRequest, parameters); + } }