<commit_before>package me.adaptive.notification;

import me.adaptive.core.data.domain.NotificationEntity;
import me.adaptive.core.data.domain.NotificationErrorEntity;
import me.adaptive.core.data.domain.types.NotificationChannel;
import me.adaptive.core.data.util.UserPreferences;
import me.adaptive.services.notification.NotificationService;
import me.adaptive.services.notification.error.NotificationException;
import me.adaptive.services.notification.template.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.mail.javamail.MimeMessagePreparator;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by panthro on 17/08/15.
 * Sends notifications using SMTP server
 */
@Service
public class EmailSTMPNotificationService implements NotificationService {

    @Value("#{systemEnvironment.smtp.from}")
    String from;
    @Autowired
    TemplateService templateService;
    @Autowired
    JavaMailSender mailSender;

    public String getServiceId() {
        return EmailSTMPNotificationService.class.getSimpleName();
    }

    public NotificationChannel getChannel() {
        return NotificationChannel.EMAIL;
    }

    @Override
    public void notify(final NotificationEntity notification, Map<String, Object> model) throws NotificationException {
        String email = notification.getUserNotified().getPreferences().get(UserPreferences.Notification.EMAIL);
        if (email == null) {
            throw new NotificationException(new NotificationErrorEntity(notification, "User does not have an email to be sent"));
        }
        notification.setDestination(email);
        MimeMessagePreparator preparator = mimeMessage -> {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
            message.setTo(email);
            message.setFrom(from);
            String text = templateService.parseTemplate(notification, model);
            message.setText(text, true);
        };
        this.mailSender.send(preparator);
    }
}<commit_msg>only setting the destination in case it was not set before.<commit_after>package me.adaptive.notification;

import me.adaptive.core.data.domain.NotificationEntity;
import me.adaptive.core.data.domain.NotificationErrorEntity;
import me.adaptive.core.data.domain.types.NotificationChannel;
import me.adaptive.core.data.util.UserPreferences;
import me.adaptive.services.notification.NotificationService;
import me.adaptive.services.notification.error.NotificationException;
import me.adaptive.services.notification.template.TemplateService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.mail.javamail.MimeMessagePreparator;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by panthro on 17/08/15.
 * Sends notifications using SMTP server
 */
@Service
public class EmailSTMPNotificationService implements NotificationService {

    @Value("#{systemEnvironment.smtp.from}")
    String from;
    @Autowired
    TemplateService templateService;
    @Autowired
    JavaMailSender mailSender;

    public String getServiceId() {
        return EmailSTMPNotificationService.class.getSimpleName();
    }

    public NotificationChannel getChannel() {
        return NotificationChannel.EMAIL;
    }

    @Override
    public void notify(final NotificationEntity notification, Map<String, Object> model) throws NotificationException {
        if (notification.getDestination() == null) {
            String email = notification.getUserNotified().getPreferences().get(UserPreferences.Notification.EMAIL);
            if (email == null) {
                throw new NotificationException(new NotificationErrorEntity(notification, "User does not have an email to be sent"));
            }
            notification.setDestination(email);
        }
        MimeMessagePreparator preparator = mimeMessage -> {
            MimeMessageHelper message = new MimeMessageHelper(mimeMessage);
            message.setTo(notification.getDestination());
            message.setFrom(from);
            String text = templateService.parseTemplate(notification, model);
            message.setText(text, true);
        };
        this.mailSender.send(preparator);
    }
}
{'fraction_non_alphanumeric': 0.08859668031903427, 'fraction_numerical': 0.002586764388876913, 'mean_word_length': 4.110132158590308, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6083428', 'n_tokens_mistral': 1201, 'n_tokens_neox': 1164, 'n_words': 237}