|
|
@ -1,36 +1,12 @@ |
|
|
|
/** |
|
|
|
/** |
|
|
|
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved. |
|
|
|
* Copyright (c) 2000-2013 Liferay, Inc. All rights reserved. The contents of this file are subject to the terms of the |
|
|
|
* |
|
|
|
* Liferay Enterprise Subscription License ("License"). You may not use this file except in compliance with the License. |
|
|
|
* The contents of this file are subject to the terms of the Liferay Enterprise Subscription License |
|
|
|
* You can obtain a copy of the License by contacting Liferay, Inc. See the License for the specific language governing |
|
|
|
* ("License"). You may not use this file except in compliance with the License. You can obtain a |
|
|
|
* permissions and limitations under the License, including but not limited to distribution rights of the Software. |
|
|
|
* copy of the License by contacting Liferay, Inc. See the License for the specific language |
|
|
|
|
|
|
|
* governing permissions and limitations under the License, including but not limited to |
|
|
|
|
|
|
|
* distribution rights of the Software. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
package it.tref.liferay.portos.mailmanager.service.impl; |
|
|
|
package it.tref.liferay.portos.mailmanager.service.impl; |
|
|
|
|
|
|
|
|
|
|
|
import com.liferay.mail.model.FileAttachment; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.exception.PortalException; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.exception.SystemException; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.log.Log; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.log.LogFactoryUtil; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.repository.model.Folder; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.util.FileUtil; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.util.OrderByComparator; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.util.StringPool; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.util.StringUtil; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.util.Validator; |
|
|
|
|
|
|
|
import com.liferay.portal.model.Company; |
|
|
|
|
|
|
|
import com.liferay.portal.model.Group; |
|
|
|
|
|
|
|
import com.liferay.portal.model.User; |
|
|
|
|
|
|
|
import com.liferay.portal.security.permission.ActionKeys; |
|
|
|
|
|
|
|
import com.liferay.portal.service.ServiceContext; |
|
|
|
|
|
|
|
import com.liferay.portlet.documentlibrary.model.DLFolderConstants; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import it.tref.liferay.portos.mailmanager.EmailBccException; |
|
|
|
import it.tref.liferay.portos.mailmanager.EmailBccException; |
|
|
|
import it.tref.liferay.portos.mailmanager.EmailBulkAddressesException; |
|
|
|
import it.tref.liferay.portos.mailmanager.EmailBulkAddressesException; |
|
|
|
import it.tref.liferay.portos.mailmanager.EmailCcException; |
|
|
|
import it.tref.liferay.portos.mailmanager.EmailCcException; |
|
|
@ -51,18 +27,30 @@ import java.util.Collections; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.Date; |
|
|
|
import java.util.List; |
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import com.liferay.mail.model.FileAttachment; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.exception.PortalException; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.exception.SystemException; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.repository.model.Folder; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.util.FileUtil; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.util.OrderByComparator; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.util.StringPool; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.util.StringUtil; |
|
|
|
|
|
|
|
import com.liferay.portal.kernel.util.Validator; |
|
|
|
|
|
|
|
import com.liferay.portal.model.Company; |
|
|
|
|
|
|
|
import com.liferay.portal.model.Group; |
|
|
|
|
|
|
|
import com.liferay.portal.model.User; |
|
|
|
|
|
|
|
import com.liferay.portal.security.permission.ActionKeys; |
|
|
|
|
|
|
|
import com.liferay.portal.service.ServiceContext; |
|
|
|
|
|
|
|
import com.liferay.portlet.documentlibrary.model.DLFolderConstants; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* The implementation of the email local service. |
|
|
|
* The implementation of the email local service. |
|
|
|
* |
|
|
|
|
|
|
|
* <p> |
|
|
|
* <p> |
|
|
|
* All custom service methods should be put in this class. Whenever methods are |
|
|
|
* All custom service methods should be put in this class. Whenever methods are added, rerun ServiceBuilder to copy |
|
|
|
* added, rerun ServiceBuilder to copy their definitions into the |
|
|
|
* their definitions into the {@link it.noovle.azimut.icf.mailmanager.service.EmailLocalService} interface. |
|
|
|
* {@link it.noovle.azimut.icf.mailmanager.service.EmailLocalService} interface. |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p> |
|
|
|
* <p> |
|
|
|
* This is a local service. Methods of this service will not have security |
|
|
|
* This is a local service. Methods of this service will not have security checks based on the propagated JAAS |
|
|
|
* checks based on the propagated JAAS credentials because this service can only |
|
|
|
* credentials because this service can only be accessed from within the same VM. |
|
|
|
* be accessed from within the same VM. |
|
|
|
|
|
|
|
* </p> |
|
|
|
* </p> |
|
|
|
* |
|
|
|
* |
|
|
|
* @author |
|
|
|
* @author |
|
|
@ -71,70 +59,67 @@ import java.util.List; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class EmailLocalServiceImpl extends EmailLocalServiceBaseImpl { |
|
|
|
public class EmailLocalServiceImpl extends EmailLocalServiceBaseImpl { |
|
|
|
/* |
|
|
|
/* |
|
|
|
* NOTE FOR DEVELOPERS: |
|
|
|
* NOTE FOR DEVELOPERS: Never reference this interface directly. Always use {@link |
|
|
|
* |
|
|
|
* it.noovle.azimut.icf.mailmanager.service.EmailLocalServiceUtil} to access the email local service. |
|
|
|
* Never reference this interface directly. Always use {@link |
|
|
|
|
|
|
|
* it.noovle.azimut.icf.mailmanager.service.EmailLocalServiceUtil} to access |
|
|
|
|
|
|
|
* the email local service. |
|
|
|
|
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
private final static Log _log = LogFactoryUtil.getLog(EmailLocalServiceImpl.class); |
|
|
|
@Override |
|
|
|
|
|
|
|
public Email addEmail(String className, long classPK, String from, String to[], String cc[], String bcc[], |
|
|
|
|
|
|
|
String subject, String body, boolean htmlFormat, ServiceContext serviceContext) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
public Email addEmail(String className, long classPK, String from, String to[], String cc[], |
|
|
|
return addEmail(className, classPK, from, to, cc, bcc, null, subject, body, htmlFormat, null, null, null, null, |
|
|
|
String bcc[], String subject, String body, boolean htmlFormat, ServiceContext serviceContext) |
|
|
|
0, false, null, null, Collections.<FileAttachment> emptyList(), serviceContext); |
|
|
|
throws Exception { |
|
|
|
|
|
|
|
return addEmail(className, classPK, from, to, cc, bcc, null, subject, body, htmlFormat, null, null, |
|
|
|
|
|
|
|
null, null, 0, false, null, null, Collections.<FileAttachment> emptyList(), serviceContext); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Email addEmail(String className, long classPK, String from, String to[], String cc[], |
|
|
|
@Override |
|
|
|
String bcc[], String subject, String body, boolean htmlFormat, |
|
|
|
public Email addEmail(String className, long classPK, String from, String to[], String cc[], String bcc[], |
|
|
|
List<FileAttachment> fileAttachments, ServiceContext serviceContext) throws Exception { |
|
|
|
String subject, String body, boolean htmlFormat, List<FileAttachment> fileAttachments, |
|
|
|
return addEmail(className, classPK, from, to, cc, bcc, null, subject, body, htmlFormat, null, null, |
|
|
|
ServiceContext serviceContext) throws Exception { |
|
|
|
null, null, 0, false, null, null, fileAttachments, false, null, serviceContext); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Email addEmail(String className, long classPK, String from, String to[], String cc[], |
|
|
|
return addEmail(className, classPK, from, to, cc, bcc, null, subject, body, htmlFormat, null, null, null, null, |
|
|
|
String bcc[], String[] bulkAddresses, String subject, String body, boolean htmlFormat, |
|
|
|
0, false, null, null, fileAttachments, false, null, serviceContext); |
|
|
|
String[] replyTo, String messageId, String inReplyTo, String smtpHost, int smtpPort, |
|
|
|
|
|
|
|
boolean smtpSecure, String smtpUsername, String smtpPassword, |
|
|
|
|
|
|
|
List<FileAttachment> fileAttachments, ServiceContext serviceContext) throws Exception { |
|
|
|
|
|
|
|
return addEmail(className, classPK, from, to, cc, bcc, bulkAddresses, subject, body, htmlFormat, |
|
|
|
|
|
|
|
replyTo, messageId, inReplyTo, smtpHost, smtpPort, smtpSecure, smtpUsername, smtpPassword, |
|
|
|
|
|
|
|
fileAttachments, false, null, serviceContext); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Email addEmail(String className, long classPK, String from, String to[], String cc[], |
|
|
|
@Override |
|
|
|
String bcc[], String subject, String body, boolean htmlFormat, |
|
|
|
public Email addEmail(String className, long classPK, String from, String to[], String cc[], String bcc[], |
|
|
|
List<FileAttachment> fileAttachments, boolean sendSync, ServiceContext serviceContext) |
|
|
|
String[] bulkAddresses, String subject, String body, boolean htmlFormat, String[] replyTo, |
|
|
|
throws Exception { |
|
|
|
String messageId, String inReplyTo, String smtpHost, int smtpPort, boolean smtpSecure, String smtpUsername, |
|
|
|
return addEmail(className, classPK, from, to, cc, bcc, null, subject, body, htmlFormat, null, null, |
|
|
|
String smtpPassword, List<FileAttachment> fileAttachments, ServiceContext serviceContext) throws Exception { |
|
|
|
null, null, 0, false, null, null, fileAttachments, sendSync, null, serviceContext); |
|
|
|
|
|
|
|
|
|
|
|
return addEmail(className, classPK, from, to, cc, bcc, bulkAddresses, subject, body, htmlFormat, replyTo, |
|
|
|
|
|
|
|
messageId, inReplyTo, smtpHost, smtpPort, smtpSecure, smtpUsername, smtpPassword, fileAttachments, |
|
|
|
|
|
|
|
false, null, serviceContext); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Email addEmail(String className, long classPK, String from, String to[], String cc[], |
|
|
|
@Override |
|
|
|
String bcc[], String subject, String body, boolean htmlFormat, |
|
|
|
public Email addEmail(String className, long classPK, String from, String to[], String cc[], String bcc[], |
|
|
|
List<FileAttachment> fileAttachments, boolean sendSync, String templateName, |
|
|
|
String subject, String body, boolean htmlFormat, List<FileAttachment> fileAttachments, boolean sendSync, |
|
|
|
ServiceContext serviceContext) throws Exception { |
|
|
|
ServiceContext serviceContext) throws Exception { |
|
|
|
return addEmail(className, classPK, from, to, cc, bcc, null, subject, body, htmlFormat, null, null, |
|
|
|
|
|
|
|
null, null, 0, false, null, null, fileAttachments, sendSync, templateName, serviceContext); |
|
|
|
return addEmail(className, classPK, from, to, cc, bcc, null, subject, body, htmlFormat, null, null, null, null, |
|
|
|
|
|
|
|
0, false, null, null, fileAttachments, sendSync, null, serviceContext); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Email addEmail(String className, long classPK, String from, String to[], String cc[], |
|
|
|
@Override |
|
|
|
String bcc[], String[] bulkAddresses, String subject, String body, boolean htmlFormat, |
|
|
|
public Email addEmail(String className, long classPK, String from, String to[], String cc[], String bcc[], |
|
|
|
String[] replyTo, String messageId, String inReplyTo, String smtpHost, int smtpPort, |
|
|
|
String subject, String body, boolean htmlFormat, List<FileAttachment> fileAttachments, boolean sendSync, |
|
|
|
boolean smtpSecure, String smtpUsername, String smtpPassword, |
|
|
|
String templateName, ServiceContext serviceContext) throws Exception { |
|
|
|
List<FileAttachment> fileAttachments, boolean sendSync, String templateName, |
|
|
|
|
|
|
|
|
|
|
|
return addEmail(className, classPK, from, to, cc, bcc, null, subject, body, htmlFormat, null, null, null, null, |
|
|
|
|
|
|
|
0, false, null, null, fileAttachments, sendSync, templateName, serviceContext); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Email addEmail(String className, long classPK, String from, String to[], String cc[], String bcc[], |
|
|
|
|
|
|
|
String[] bulkAddresses, String subject, String body, boolean htmlFormat, String[] replyTo, |
|
|
|
|
|
|
|
String messageId, String inReplyTo, String smtpHost, int smtpPort, boolean smtpSecure, String smtpUsername, |
|
|
|
|
|
|
|
String smtpPassword, List<FileAttachment> fileAttachments, boolean sendSync, String templateName, |
|
|
|
ServiceContext serviceContext) throws Exception { |
|
|
|
ServiceContext serviceContext) throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
User user = userLocalService.getUser(serviceContext.getUserId()); |
|
|
|
User user = userLocalService.getUser(serviceContext.getUserId()); |
|
|
|
|
|
|
|
|
|
|
|
Date now = new Date(); |
|
|
|
Date now = new Date(); |
|
|
|
|
|
|
|
|
|
|
|
validate(from, to, cc, bcc, bulkAddresses, subject, body, replyTo); |
|
|
|
validate(from, to, cc, bcc, bulkAddresses, subject, body, replyTo); |
|
|
|
|
|
|
|
Email email = createEmail(counterLocalService.increment(Email.class.getName())); |
|
|
|
Email email = emailLocalService.createEmail(counterLocalService.increment(Email.class.getName())); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
email.setGroupId(serviceContext.getScopeGroupId()); |
|
|
|
email.setGroupId(serviceContext.getScopeGroupId()); |
|
|
|
email.setCompanyId(serviceContext.getCompanyId()); |
|
|
|
email.setCompanyId(serviceContext.getCompanyId()); |
|
|
|
email.setCreateDate(serviceContext.getCreateDate(now)); |
|
|
|
email.setCreateDate(serviceContext.getCreateDate(now)); |
|
|
@ -143,7 +128,6 @@ public class EmailLocalServiceImpl extends EmailLocalServiceBaseImpl { |
|
|
|
email.setClassPK(classPK); |
|
|
|
email.setClassPK(classPK); |
|
|
|
email.setUserId(user.getUserId()); |
|
|
|
email.setUserId(user.getUserId()); |
|
|
|
email.setUserName(user.getFullName()); |
|
|
|
email.setUserName(user.getFullName()); |
|
|
|
|
|
|
|
|
|
|
|
email.setFrom(from); |
|
|
|
email.setFrom(from); |
|
|
|
email.setTo(StringUtil.merge(to, StringPool.COMMA)); |
|
|
|
email.setTo(StringUtil.merge(to, StringPool.COMMA)); |
|
|
|
email.setCc(StringUtil.merge(cc, StringPool.COMMA)); |
|
|
|
email.setCc(StringUtil.merge(cc, StringPool.COMMA)); |
|
|
@ -151,12 +135,10 @@ public class EmailLocalServiceImpl extends EmailLocalServiceBaseImpl { |
|
|
|
email.setBulkAddresses(StringUtil.merge(bulkAddresses, StringPool.COMMA)); |
|
|
|
email.setBulkAddresses(StringUtil.merge(bulkAddresses, StringPool.COMMA)); |
|
|
|
email.setSubject(subject); |
|
|
|
email.setSubject(subject); |
|
|
|
email.setBody(body); |
|
|
|
email.setBody(body); |
|
|
|
|
|
|
|
|
|
|
|
email.setHtmlFormat(htmlFormat); |
|
|
|
email.setHtmlFormat(htmlFormat); |
|
|
|
email.setReplyTo(StringUtil.merge(replyTo, StringPool.COMMA)); |
|
|
|
email.setReplyTo(StringUtil.merge(replyTo, StringPool.COMMA)); |
|
|
|
email.setMessageId(messageId); |
|
|
|
email.setMessageId(messageId); |
|
|
|
email.setInReplyTo(inReplyTo); |
|
|
|
email.setInReplyTo(inReplyTo); |
|
|
|
|
|
|
|
|
|
|
|
email.setSmtpHost(smtpHost); |
|
|
|
email.setSmtpHost(smtpHost); |
|
|
|
email.setSmtpPort(smtpPort); |
|
|
|
email.setSmtpPort(smtpPort); |
|
|
|
email.setSmtpSecure(smtpSecure); |
|
|
|
email.setSmtpSecure(smtpSecure); |
|
|
@ -164,47 +146,37 @@ public class EmailLocalServiceImpl extends EmailLocalServiceBaseImpl { |
|
|
|
email.setSmtpPassword(smtpPassword); |
|
|
|
email.setSmtpPassword(smtpPassword); |
|
|
|
email.setCancel(false); |
|
|
|
email.setCancel(false); |
|
|
|
email.setTemplateName(templateName); |
|
|
|
email.setTemplateName(templateName); |
|
|
|
|
|
|
|
|
|
|
|
email = addEmail(email); |
|
|
|
email = addEmail(email); |
|
|
|
|
|
|
|
|
|
|
|
// Email Attachments
|
|
|
|
// Email Attachments
|
|
|
|
|
|
|
|
|
|
|
|
if (fileAttachments != null && !fileAttachments.isEmpty()) { |
|
|
|
if (fileAttachments != null && !fileAttachments.isEmpty()) { |
|
|
|
Folder folder = addEmailAttachmentsFolder(serviceContext.getCompanyId(), email.getEmailId()); |
|
|
|
Folder folder = addEmailAttachmentsFolder(serviceContext.getCompanyId(), email.getEmailId()); |
|
|
|
for (FileAttachment fileAttachment : fileAttachments) { |
|
|
|
for (FileAttachment fileAttachment : fileAttachments) { |
|
|
|
if (fileAttachment instanceof FileAttachment) { |
|
|
|
if (fileAttachment instanceof FileAttachment) { |
|
|
|
((it.tref.liferay.portos.mailmanager.shared.model.FileAttachment) fileAttachment) |
|
|
|
((it.tref.liferay.portos.mailmanager.shared.model.FileAttachment) fileAttachment).generateFile(); |
|
|
|
.generateFile(); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
emailAttachmentLocalService.addEmailAttachment(serviceContext.getCompanyId(), |
|
|
|
emailAttachmentLocalService.addEmailAttachment(serviceContext.getCompanyId(), email.getEmailId(), |
|
|
|
email.getEmailId(), folder.getFolderId(), fileAttachment.getFileName(), |
|
|
|
folder.getFolderId(), fileAttachment.getFileName(), fileAttachment.getFile()); |
|
|
|
fileAttachment.getFile()); |
|
|
|
|
|
|
|
FileUtil.delete(fileAttachment.getFile()); |
|
|
|
FileUtil.delete(fileAttachment.getFile()); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Manifattura Web Group per Regione Siciliana
|
|
|
|
// Manifattura Web Group per Regione Siciliana
|
|
|
|
// Il valore di ritorno viene ignorato da SchedulerInvioDocumenti, le
|
|
|
|
// Il valore di ritorno viene ignorato da SchedulerInvioDocumenti, le mail impostate per l'invio asincrono si
|
|
|
|
// mail impostate per l'invio asincrono si perdono nell'abisso
|
|
|
|
// perdono nell'abisso dell'oblio. Siccome questo è già un task asincrono, inviamo in maniera sincrona e
|
|
|
|
// dell'oblio. Siccome questo è già un task asincrono, inviamo in
|
|
|
|
// festeggiamo.
|
|
|
|
// maniera sincrona e festeggiamo.
|
|
|
|
|
|
|
|
sendSync = true; |
|
|
|
sendSync = true; |
|
|
|
|
|
|
|
|
|
|
|
if (sendSync) { |
|
|
|
if (sendSync) { |
|
|
|
MailSenderUtil.sendMail(email); |
|
|
|
MailSenderUtil.sendMail(email); |
|
|
|
markAsSent(email.getEmailId(), new Date(), StringPool.BLANK); |
|
|
|
markAsSent(email.getEmailId(), new Date(), StringPool.BLANK); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return email; |
|
|
|
return email; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Email updateEmail(long emailId, String from, String to[], String cc[], String bcc[], |
|
|
|
@Override |
|
|
|
String subject, String body, ServiceContext serviceContext) throws Exception { |
|
|
|
public Email updateEmail(long emailId, String from, String to[], String cc[], String bcc[], String subject, |
|
|
|
|
|
|
|
String body, ServiceContext serviceContext) throws Exception { |
|
|
|
Email email = emailLocalService.getEmail(emailId); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Email email = getEmail(emailId); |
|
|
|
validate(from, to, cc, bcc, null, subject, body, null); |
|
|
|
validate(from, to, cc, bcc, null, subject, body, null); |
|
|
|
|
|
|
|
|
|
|
|
email.setModifiedDate(new Date()); |
|
|
|
email.setModifiedDate(new Date()); |
|
|
|
email.setFrom(from); |
|
|
|
email.setFrom(from); |
|
|
|
email.setTo(StringUtil.merge(to, StringPool.COMMA)); |
|
|
|
email.setTo(StringUtil.merge(to, StringPool.COMMA)); |
|
|
@ -212,60 +184,54 @@ public class EmailLocalServiceImpl extends EmailLocalServiceBaseImpl { |
|
|
|
email.setBcc(StringUtil.merge(bcc, StringPool.COMMA)); |
|
|
|
email.setBcc(StringUtil.merge(bcc, StringPool.COMMA)); |
|
|
|
email.setSubject(subject); |
|
|
|
email.setSubject(subject); |
|
|
|
email.setBody(body); |
|
|
|
email.setBody(body); |
|
|
|
|
|
|
|
|
|
|
|
return updateEmail(email); |
|
|
|
return updateEmail(email); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Email markAsSent(long emailId, Date sentDate, String statusMessage) throws PortalException, |
|
|
|
@Override |
|
|
|
SystemException { |
|
|
|
public Email markAsSent(long emailId, Date sentDate, String statusMessage) throws PortalException, SystemException { |
|
|
|
|
|
|
|
|
|
|
|
Email email = emailLocalService.getEmail(emailId); |
|
|
|
Email email = getEmail(emailId); |
|
|
|
email.setModifiedDate(new Date()); |
|
|
|
email.setModifiedDate(new Date()); |
|
|
|
|
|
|
|
|
|
|
|
email.setSent(true); |
|
|
|
email.setSent(true); |
|
|
|
email.setSentDate(sentDate); |
|
|
|
email.setSentDate(sentDate); |
|
|
|
email.setStatusMessage(statusMessage); |
|
|
|
email.setStatusMessage(statusMessage); |
|
|
|
|
|
|
|
|
|
|
|
return updateEmail(email); |
|
|
|
return updateEmail(email); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Email updateStatusMessage(long emailId, String statusMessage) throws PortalException, |
|
|
|
@Override |
|
|
|
SystemException { |
|
|
|
public Email updateStatusMessage(long emailId, String statusMessage) throws PortalException, SystemException { |
|
|
|
|
|
|
|
|
|
|
|
Email email = emailLocalService.getEmail(emailId); |
|
|
|
Email email = getEmail(emailId); |
|
|
|
email.setModifiedDate(new Date()); |
|
|
|
email.setModifiedDate(new Date()); |
|
|
|
|
|
|
|
|
|
|
|
email.setStatusMessage(statusMessage); |
|
|
|
email.setStatusMessage(statusMessage); |
|
|
|
|
|
|
|
|
|
|
|
return updateEmail(email); |
|
|
|
return updateEmail(email); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Email resendEmail(long emailId) throws PortalException, SystemException { |
|
|
|
public Email resendEmail(long emailId) throws PortalException, SystemException { |
|
|
|
|
|
|
|
|
|
|
|
Email email = emailLocalService.getEmail(emailId); |
|
|
|
Email email = getEmail(emailId); |
|
|
|
email.setModifiedDate(new Date()); |
|
|
|
email.setModifiedDate(new Date()); |
|
|
|
|
|
|
|
|
|
|
|
email.setStatusMessage(""); |
|
|
|
email.setStatusMessage(""); |
|
|
|
email.setSent(false); |
|
|
|
email.setSent(false); |
|
|
|
email.setSentDate(null); |
|
|
|
email.setSentDate(null); |
|
|
|
email.setCancel(false); |
|
|
|
email.setCancel(false); |
|
|
|
|
|
|
|
|
|
|
|
return updateEmail(email); |
|
|
|
return updateEmail(email); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public Email cancelEmail(long emailId) throws PortalException, SystemException { |
|
|
|
public Email cancelEmail(long emailId) throws PortalException, SystemException { |
|
|
|
|
|
|
|
|
|
|
|
Email email = emailLocalService.getEmail(emailId); |
|
|
|
Email email = getEmail(emailId); |
|
|
|
email.setModifiedDate(new Date()); |
|
|
|
email.setModifiedDate(new Date()); |
|
|
|
|
|
|
|
|
|
|
|
email.setCancel(true); |
|
|
|
email.setCancel(true); |
|
|
|
|
|
|
|
|
|
|
|
return updateEmail(email); |
|
|
|
return updateEmail(email); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public Email deleteEmail(long emailId) throws PortalException, SystemException { |
|
|
|
public Email deleteEmail(long emailId) throws PortalException, SystemException { |
|
|
|
Email email = emailLocalService.getEmail(emailId); |
|
|
|
|
|
|
|
|
|
|
|
Email email = getEmail(emailId); |
|
|
|
return deleteEmail(email); |
|
|
|
return deleteEmail(email); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -273,108 +239,126 @@ public class EmailLocalServiceImpl extends EmailLocalServiceBaseImpl { |
|
|
|
public Email deleteEmail(Email email) throws SystemException { |
|
|
|
public Email deleteEmail(Email email) throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
super.deleteEmail(email); |
|
|
|
super.deleteEmail(email); |
|
|
|
|
|
|
|
|
|
|
|
// Email Attachments
|
|
|
|
// Email Attachments
|
|
|
|
|
|
|
|
List<EmailAttachment> emailAttachments = emailAttachmentLocalService.findByEmailId(email.getEmailId()); |
|
|
|
List<EmailAttachment> emailAttachments = emailAttachmentLocalService |
|
|
|
|
|
|
|
.findByEmailId(email.getEmailId()); |
|
|
|
|
|
|
|
for (EmailAttachment emailAttachment : emailAttachments) { |
|
|
|
for (EmailAttachment emailAttachment : emailAttachments) { |
|
|
|
emailAttachmentLocalService.deleteEmailAttachment(emailAttachment); |
|
|
|
emailAttachmentLocalService.deleteEmailAttachment(emailAttachment); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return email; |
|
|
|
return email; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Email> findByCompany(long companyId) throws SystemException { |
|
|
|
public List<Email> findByCompany(long companyId) throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
return emailPersistence.findByCompany(companyId); |
|
|
|
return emailPersistence.findByCompany(companyId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Email> findByCompany(long companyId, int start, int end) throws SystemException { |
|
|
|
public List<Email> findByCompany(long companyId, int start, int end) throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
return emailPersistence.findByCompany(companyId, start, end); |
|
|
|
return emailPersistence.findByCompany(companyId, start, end); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Email> findByCompany(long companyId, int start, int end, OrderByComparator orderByComparator) |
|
|
|
public List<Email> findByCompany(long companyId, int start, int end, OrderByComparator orderByComparator) |
|
|
|
throws SystemException { |
|
|
|
throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
return emailPersistence.findByCompany(companyId, start, end, orderByComparator); |
|
|
|
return emailPersistence.findByCompany(companyId, start, end, orderByComparator); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public int countByCompany(long companyId) throws SystemException { |
|
|
|
public int countByCompany(long companyId) throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
return emailPersistence.countByCompany(companyId); |
|
|
|
return emailPersistence.countByCompany(companyId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Email> findByC_G(long companyId, long groupId) throws SystemException { |
|
|
|
public List<Email> findByC_G(long companyId, long groupId) throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
return emailPersistence.findByC_G(companyId, groupId); |
|
|
|
return emailPersistence.findByC_G(companyId, groupId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Email> findByC_G(long companyId, long groupId, int start, int end) throws SystemException { |
|
|
|
public List<Email> findByC_G(long companyId, long groupId, int start, int end) throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
return emailPersistence.findByC_G(companyId, groupId, start, end); |
|
|
|
return emailPersistence.findByC_G(companyId, groupId, start, end); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<Email> findByC_G(long companyId, long groupId, int start, int end, |
|
|
|
@Override |
|
|
|
OrderByComparator orderByComparator) throws SystemException { |
|
|
|
public List<Email> findByC_G(long companyId, long groupId, int start, int end, OrderByComparator orderByComparator) |
|
|
|
|
|
|
|
throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
return emailPersistence.findByC_G(companyId, groupId, start, end, orderByComparator); |
|
|
|
return emailPersistence.findByC_G(companyId, groupId, start, end, orderByComparator); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public int countByC_G(long companyId, long groupId) throws SystemException { |
|
|
|
public int countByC_G(long companyId, long groupId) throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
return emailPersistence.countByC_G(companyId, groupId); |
|
|
|
return emailPersistence.countByC_G(companyId, groupId); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Email> findByC_G_T(long companyId, long groupId, String templateName) throws SystemException { |
|
|
|
public List<Email> findByC_G_T(long companyId, long groupId, String templateName) throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
return emailPersistence.findByC_G_T(companyId, groupId, templateName); |
|
|
|
return emailPersistence.findByC_G_T(companyId, groupId, templateName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Email> findByC_G_T(long companyId, long groupId, String templateName, int start, int end) |
|
|
|
public List<Email> findByC_G_T(long companyId, long groupId, String templateName, int start, int end) |
|
|
|
throws SystemException { |
|
|
|
throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
return emailPersistence.findByC_G_T(companyId, groupId, templateName, start, end); |
|
|
|
return emailPersistence.findByC_G_T(companyId, groupId, templateName, start, end); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public int countByC_G_T(long companyId, long groupId, String templateName) throws SystemException { |
|
|
|
public int countByC_G_T(long companyId, long groupId, String templateName) throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
return emailPersistence.countByC_G_T(companyId, groupId, templateName); |
|
|
|
return emailPersistence.countByC_G_T(companyId, groupId, templateName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
public List<Email> findByC_G_C_C(long companyId, long groupId, long classNameId, long classPK) |
|
|
|
public List<Email> findByC_G_C_C(long companyId, long groupId, long classNameId, long classPK) |
|
|
|
throws SystemException { |
|
|
|
throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
return emailPersistence.findByC_G_C_C(companyId, groupId, classNameId, classPK); |
|
|
|
return emailPersistence.findByC_G_C_C(companyId, groupId, classNameId, classPK); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public List<Email> findByC_G_C_C(long companyId, long groupId, long classNameId, long classPK, int start, |
|
|
|
@Override |
|
|
|
int end) throws SystemException { |
|
|
|
public List<Email> findByC_G_C_C(long companyId, long groupId, long classNameId, long classPK, int start, int end) |
|
|
|
|
|
|
|
throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
return emailPersistence.findByC_G_C_C(companyId, groupId, classNameId, classPK, start, end); |
|
|
|
return emailPersistence.findByC_G_C_C(companyId, groupId, classNameId, classPK, start, end); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int countByC_G_C_C(long companyId, long groupId, long classNameId, long classPK) |
|
|
|
@Override |
|
|
|
throws SystemException { |
|
|
|
public int countByC_G_C_C(long companyId, long groupId, long classNameId, long classPK) throws SystemException { |
|
|
|
|
|
|
|
|
|
|
|
return emailPersistence.countByC_G_C_C(companyId, groupId, classNameId, classPK); |
|
|
|
return emailPersistence.countByC_G_C_C(companyId, groupId, classNameId, classPK); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Folder addEmailAttachmentsFolder(long companyId, long emailId) throws PortalException, |
|
|
|
private Folder addEmailAttachmentsFolder(long companyId, long emailId) throws PortalException, SystemException { |
|
|
|
SystemException { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Company company = companyLocalService.getCompany(companyId); |
|
|
|
Company company = companyLocalService.getCompany(companyId); |
|
|
|
|
|
|
|
|
|
|
|
Group companyGroup = company.getGroup(); |
|
|
|
Group companyGroup = company.getGroup(); |
|
|
|
User defaultUser = company.getDefaultUser(); |
|
|
|
User defaultUser = company.getDefaultUser(); |
|
|
|
|
|
|
|
Folder folder = |
|
|
|
Folder folder = dlAppLocalService.getFolder(companyGroup.getGroupId(), |
|
|
|
dlAppLocalService.getFolder(companyGroup.getGroupId(), DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, |
|
|
|
DLFolderConstants.DEFAULT_PARENT_FOLDER_ID, EmailConstants.DEFAULT_ATTACHMENTS_FOLDER_NAME); |
|
|
|
EmailConstants.DEFAULT_ATTACHMENTS_FOLDER_NAME); |
|
|
|
|
|
|
|
|
|
|
|
ServiceContext serviceContext = new ServiceContext(); |
|
|
|
ServiceContext serviceContext = new ServiceContext(); |
|
|
|
serviceContext.setGroupPermissions(new String[] { ActionKeys.VIEW }); |
|
|
|
serviceContext.setGroupPermissions(new String[] { ActionKeys.VIEW }); |
|
|
|
serviceContext.setGuestPermissions(new String[] { ActionKeys.VIEW }); |
|
|
|
serviceContext.setGuestPermissions(new String[] { ActionKeys.VIEW }); |
|
|
|
|
|
|
|
return dlAppLocalService.addFolder(defaultUser.getUserId(), folder.getRepositoryId(), folder.getFolderId(), |
|
|
|
return dlAppLocalService.addFolder(defaultUser.getUserId(), folder.getRepositoryId(), |
|
|
|
String.valueOf(emailId), StringPool.BLANK, serviceContext); |
|
|
|
folder.getFolderId(), String.valueOf(emailId), StringPool.BLANK, serviceContext); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void validate(String from, String to[], String cc[], String bcc[], String[] bulkAddresses, |
|
|
|
private void validate(String from, String to[], String cc[], String bcc[], String[] bulkAddresses, String subject, |
|
|
|
String subject, String body, String[] replyTo) throws PortalException { |
|
|
|
String body, String[] replyTo) throws PortalException { |
|
|
|
|
|
|
|
|
|
|
|
if (Validator.isNull(from)) { |
|
|
|
if (Validator.isNull(from)) { |
|
|
|
throw new RequiredEmailFromException(); |
|
|
|
throw new RequiredEmailFromException(); |
|
|
|
} else if (!Validator.isEmailAddress(from)) { |
|
|
|
} else if (!Validator.isEmailAddress(from)) { |
|
|
|
throw new EmailFromException(); |
|
|
|
throw new EmailFromException(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (to == null || (to != null && to.length == 0)) { |
|
|
|
if (to == null || (to != null && to.length == 0)) { |
|
|
|
throw new RequiredEmailToException(); |
|
|
|
throw new RequiredEmailToException(); |
|
|
|
} else { |
|
|
|
} else { |
|
|
@ -384,7 +368,6 @@ public class EmailLocalServiceImpl extends EmailLocalServiceBaseImpl { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (cc != null && cc.length > 0) { |
|
|
|
if (cc != null && cc.length > 0) { |
|
|
|
for (String emailAddress : cc) { |
|
|
|
for (String emailAddress : cc) { |
|
|
|
if (!Validator.isEmailAddress(emailAddress)) { |
|
|
|
if (!Validator.isEmailAddress(emailAddress)) { |
|
|
@ -392,7 +375,6 @@ public class EmailLocalServiceImpl extends EmailLocalServiceBaseImpl { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (bcc != null && bcc.length > 0) { |
|
|
|
if (bcc != null && bcc.length > 0) { |
|
|
|
for (String emailAddress : bcc) { |
|
|
|
for (String emailAddress : bcc) { |
|
|
|
if (!Validator.isEmailAddress(emailAddress)) { |
|
|
|
if (!Validator.isEmailAddress(emailAddress)) { |
|
|
@ -400,7 +382,6 @@ public class EmailLocalServiceImpl extends EmailLocalServiceBaseImpl { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (bulkAddresses != null && bulkAddresses.length > 0) { |
|
|
|
if (bulkAddresses != null && bulkAddresses.length > 0) { |
|
|
|
for (String emailAddress : bulkAddresses) { |
|
|
|
for (String emailAddress : bulkAddresses) { |
|
|
|
if (!Validator.isEmailAddress(emailAddress)) { |
|
|
|
if (!Validator.isEmailAddress(emailAddress)) { |
|
|
@ -408,15 +389,12 @@ public class EmailLocalServiceImpl extends EmailLocalServiceBaseImpl { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Validator.isNull(subject)) { |
|
|
|
if (Validator.isNull(subject)) { |
|
|
|
throw new RequiredEmailSubjectException(); |
|
|
|
throw new RequiredEmailSubjectException(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (Validator.isNull(body)) { |
|
|
|
if (Validator.isNull(body)) { |
|
|
|
throw new RequiredEmailBodyException(); |
|
|
|
throw new RequiredEmailBodyException(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (replyTo != null && replyTo.length == 0) { |
|
|
|
if (replyTo != null && replyTo.length == 0) { |
|
|
|
for (String emailAddress : replyTo) { |
|
|
|
for (String emailAddress : replyTo) { |
|
|
|
if (!Validator.isEmailAddress(emailAddress)) { |
|
|
|
if (!Validator.isEmailAddress(emailAddress)) { |
|
|
|