Merge branch 'master' into bug4100

Change-Id: I98c3af4d7cda4fafee6e22c485d74e1d21ad41e6
This commit is contained in:
Axel Uhl committed 2017-06-27 16:44:17 +02:00
commit 29c12ac1b4
24 files changed
+244 -105

No files matched your search

@@ -1,12 +1,20 @@
package com.sap.sailing.server.notification.impl;
import java.io.Serializable;
import java.net.URL;
import java.util.Arrays;
import com.sap.sse.common.Util.Pair;
public class NotificationMailTemplate {
/**
* The class needs to implement the {@link Serializable} interface because it can become part of a
* {@link SerializableMultipartSupplier}.
*
* @author Axel Uhl (D043530)
*
*/
public class NotificationMailTemplate implements Serializable {
private static final long serialVersionUID = 3291811210425722552L;
private final String subject;
private final String title;
private final String text;
@@ -10,17 +10,12 @@ import java.util.Locale;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.activation.DataHandler;
import javax.activation.DataSource;
import javax.mail.BodyPart;
import javax.mail.Multipart;
import javax.mail.internet.MimeBodyPart;
import javax.mail.internet.MimeMultipart;
import javax.mail.util.ByteArrayDataSource;
import com.sap.sse.common.Util.Pair;
import com.sap.sse.i18n.impl.ResourceBundleStringMessagesImpl;
import com.sap.sse.mail.MailService;
import com.sap.sse.mail.SerializableDefaultMimeBodyPartSupplier;
import com.sap.sse.mail.SerializableImageMimeBodyPartSupplier;
import com.sap.sse.mail.SerializableMultipartSupplier;
import com.sap.sse.mail.queue.MailNotification;
import com.sap.sse.security.PreferenceObjectBasedNotificationSet;
import com.sap.sse.security.User;
@@ -81,22 +76,12 @@ public abstract class NotificationSetNotification<T> implements MailNotification
// send batches with the actual mail addresses as bcc?
associatedNotificationSet.forUsersWithVerifiedEmailMappedTo(objectToNotifyAbout, (user) -> {
Locale locale = user.getLocaleOrDefault();
Multipart multipart = new MimeMultipart("related");
BodyPart bodyPart = new MimeBodyPart();
BodyPart messageImagePart = new MimeBodyPart();
final NotificationMailTemplate mailTemplate = getMailTemplate(objectToNotifyAbout, locale);
try {
// TODO: add cid:saplogo
NotificationMailTemplate mailTemplate = getMailTemplate(objectToNotifyAbout, locale);
bodyPart.setContent(getMailContent(mailTemplate, user, locale), "text/html");
multipart.addBodyPart(bodyPart);
DataSource imageDs = new ByteArrayDataSource(LOGO_BYTES, "image/png");
messageImagePart.setDataHandler(new DataHandler(imageDs));
messageImagePart.setHeader("Content-ID", "saplogo");
messageImagePart.setHeader("Content-Disposition", "inline;filename=\"saplogo.png\"");
multipart.addBodyPart(messageImagePart);
mailService.sendMail(user.getEmail(), mailTemplate.getSubject(), multipart);
final SerializableMultipartSupplier multipartSupplier = new SerializableMultipartSupplier("related",
new SerializableDefaultMimeBodyPartSupplier(getMailContent(mailTemplate, user, locale), "text/html"),
new SerializableImageMimeBodyPartSupplier(LOGO_BYTES, "image/png", "saplogo", "saplogo.png"));
mailService.sendMail(user.getEmail(), mailTemplate.getSubject(), multipartSupplier);
} catch (Exception e) {
logger.log(Level.SEVERE,
"Could not send mail notification for \"" + objectToNotifyAbout + "\" to user \"" + user + "\"", e);