Search in sources :

Example 1 with MailAddress

use of com.axelor.mail.db.MailAddress in project axelor-open-suite by axelor.

the class MailServiceBaseImpl method recipients.

@Override
protected Set<String> recipients(MailMessage message, Model entity) {
    final Set<String> recipients = new LinkedHashSet<>();
    final MailFollowerRepository followers = Beans.get(MailFollowerRepository.class);
    String entityName = entity.getClass().getName();
    if (message.getRecipients() != null) {
        for (MailAddress address : message.getRecipients()) {
            recipients.add(address.getAddress());
        }
    }
    for (MailFollower follower : followers.findAll(message)) {
        if (follower.getArchived()) {
            continue;
        }
        User user = follower.getUser();
        if (user != null) {
            if (!(user.getReceiveEmails() && user.getFollowedMetaModelSet().stream().anyMatch(x -> x.getFullName().equals(entityName)))) {
                continue;
            } else {
                Partner partner = user.getPartner();
                if (partner != null && partner.getEmailAddress() != null) {
                    recipients.add(partner.getEmailAddress().getAddress());
                } else if (user.getEmail() != null) {
                    recipients.add(user.getEmail());
                }
            }
        } else {
            if (follower.getEmail() != null) {
                recipients.add(follower.getEmail().getAddress());
            } else {
                log.info("No email address found for follower : " + follower);
            }
        }
    }
    return Sets.filter(recipients, Predicates.notNull());
}
Also used : LinkedHashSet(java.util.LinkedHashSet) UserRepository(com.axelor.auth.db.repo.UserRepository) MetaAttachment(com.axelor.meta.db.MetaAttachment) Templates(com.axelor.text.Templates) Filter(com.axelor.rpc.filter.Filter) Inject(com.google.inject.Inject) LoggerFactory(org.slf4j.LoggerFactory) MessagingException(javax.mail.MessagingException) StringTemplates(com.axelor.text.StringTemplates) Map(java.util.Map) MailBuilder(com.axelor.mail.MailBuilder) TypeReference(com.fasterxml.jackson.core.type.TypeReference) Path(java.nio.file.Path) MailServiceMessageImpl(com.axelor.apps.message.service.MailServiceMessageImpl) MailFollower(com.axelor.mail.db.MailFollower) MethodHandles(java.lang.invoke.MethodHandles) Set(java.util.Set) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) StringUtils(com.axelor.common.StringUtils) Sets(com.google.common.collect.Sets) Executors(java.util.concurrent.Executors) List(java.util.List) MailException(com.axelor.mail.MailException) StringUtils.isBlank(com.axelor.common.StringUtils.isBlank) MailFollowerRepository(com.axelor.mail.db.repo.MailFollowerRepository) Partner(com.axelor.apps.base.db.Partner) UnsupportedEncodingException(java.io.UnsupportedEncodingException) MailAddress(com.axelor.mail.db.MailAddress) Joiner(com.google.common.base.Joiner) Query(com.axelor.db.Query) MailTemplateAssociation(com.axelor.apps.base.db.MailTemplateAssociation) EntityHelper(com.axelor.db.EntityHelper) HashMap(java.util.HashMap) Callable(java.util.concurrent.Callable) MailSender(com.axelor.mail.MailSender) Singleton(javax.inject.Singleton) MailMessageRepository(com.axelor.mail.db.repo.MailMessageRepository) MailService(com.axelor.mail.service.MailService) ArrayList(java.util.ArrayList) InternetAddress(javax.mail.internet.InternetAddress) Strings(com.google.common.base.Strings) GroovyTemplates(com.axelor.text.GroovyTemplates) Predicates(com.google.common.base.Predicates) MailMessage(com.axelor.mail.db.MailMessage) LinkedHashSet(java.util.LinkedHashSet) ExecutorService(java.util.concurrent.ExecutorService) MetaFiles(com.axelor.meta.MetaFiles) Logger(org.slf4j.Logger) Model(com.axelor.db.Model) JpaSecurity(com.axelor.db.JpaSecurity) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TraceBackService(com.axelor.exception.service.TraceBackService) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) IOException(java.io.IOException) MimeMessage(javax.mail.internet.MimeMessage) TemplateRepository(com.axelor.apps.message.db.repo.TemplateRepository) Maps(com.google.common.collect.Maps) Template(com.axelor.apps.message.db.Template) File(java.io.File) Beans(com.axelor.inject.Beans) EmailAccount(com.axelor.apps.message.db.EmailAccount) Preconditions(com.google.common.base.Preconditions) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) User(com.axelor.auth.db.User) MailFollowerRepository(com.axelor.mail.db.repo.MailFollowerRepository) MailAddress(com.axelor.mail.db.MailAddress) User(com.axelor.auth.db.User) MailFollower(com.axelor.mail.db.MailFollower) Partner(com.axelor.apps.base.db.Partner)

Example 2 with MailAddress

use of com.axelor.mail.db.MailAddress in project axelor-open-suite by axelor.

the class EventServiceImpl method manageFollowers.

@Override
@Transactional
public void manageFollowers(Event event) {
    MailFollowerRepository mailFollowerRepo = Beans.get(MailFollowerRepository.class);
    List<MailFollower> followers = mailFollowerRepo.findAll(event);
    List<ICalendarUser> attendeesSet = event.getAttendees();
    if (followers != null)
        followers.forEach(x -> mailFollowerRepo.remove(x));
    mailFollowerRepo.follow(event, event.getUser());
    if (attendeesSet != null) {
        for (ICalendarUser user : attendeesSet) {
            if (user.getUser() != null) {
                mailFollowerRepo.follow(event, user.getUser());
            } else {
                MailAddress mailAddress = Beans.get(MailAddressRepository.class).findOrCreate(user.getEmail(), user.getName());
                mailFollowerRepo.follow(event, mailAddress);
            }
        }
    }
}
Also used : PartnerService(com.axelor.apps.base.service.PartnerService) Inject(com.google.inject.Inject) BiFunction(java.util.function.BiFunction) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) Lead(com.axelor.apps.crm.db.Lead) Function(java.util.function.Function) EmailAddress(com.axelor.apps.message.db.EmailAddress) ICalendarService(com.axelor.apps.base.ical.ICalendarService) Transactional(com.google.inject.persist.Transactional) ICalendarUser(com.axelor.apps.base.db.ICalendarUser) Strings(com.google.common.base.Strings) Event(com.axelor.apps.crm.db.Event) AxelorException(com.axelor.exception.AxelorException) Duration(java.time.Duration) Map(java.util.Map) IExceptionMessage(com.axelor.apps.crm.exception.IExceptionMessage) I18n(com.axelor.i18n.I18n) RecurrenceConfiguration(com.axelor.apps.crm.db.RecurrenceConfiguration) MailFollower(com.axelor.mail.db.MailFollower) EmailAddressRepository(com.axelor.apps.message.db.repo.EmailAddressRepository) LeadRepository(com.axelor.apps.crm.db.repo.LeadRepository) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) PartnerRepository(com.axelor.apps.base.db.repo.PartnerRepository) Collectors(java.util.stream.Collectors) TooManyIterationsException(org.apache.commons.math3.exception.TooManyIterationsException) MessageService(com.axelor.apps.message.service.MessageService) EventRepository(com.axelor.apps.crm.db.repo.EventRepository) List(java.util.List) Beans(com.axelor.inject.Beans) DayOfWeek(java.time.DayOfWeek) LocalDate(java.time.LocalDate) DateTimeFormatter(java.time.format.DateTimeFormatter) RecurrenceConfigurationRepository(com.axelor.apps.crm.db.repo.RecurrenceConfigurationRepository) TemporalAdjusters(java.time.temporal.TemporalAdjusters) Address(com.axelor.apps.base.db.Address) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) MailAddressRepository(com.axelor.mail.db.repo.MailAddressRepository) MailFollowerRepository(com.axelor.mail.db.repo.MailFollowerRepository) Partner(com.axelor.apps.base.db.Partner) MailAddress(com.axelor.mail.db.MailAddress) User(com.axelor.auth.db.User) MailFollowerRepository(com.axelor.mail.db.repo.MailFollowerRepository) ICalendarUser(com.axelor.apps.base.db.ICalendarUser) MailAddress(com.axelor.mail.db.MailAddress) MailFollower(com.axelor.mail.db.MailFollower) MailAddressRepository(com.axelor.mail.db.repo.MailAddressRepository) Transactional(com.google.inject.persist.Transactional)

Aggregations

Partner (com.axelor.apps.base.db.Partner)2 PartnerRepository (com.axelor.apps.base.db.repo.PartnerRepository)2 TemplateMessageService (com.axelor.apps.message.service.TemplateMessageService)2 User (com.axelor.auth.db.User)2 Beans (com.axelor.inject.Beans)2 MailAddress (com.axelor.mail.db.MailAddress)2 MailFollower (com.axelor.mail.db.MailFollower)2 MailFollowerRepository (com.axelor.mail.db.repo.MailFollowerRepository)2 Strings (com.google.common.base.Strings)2 Address (com.axelor.apps.base.db.Address)1 ICalendarUser (com.axelor.apps.base.db.ICalendarUser)1 MailTemplateAssociation (com.axelor.apps.base.db.MailTemplateAssociation)1 ICalendarService (com.axelor.apps.base.ical.ICalendarService)1 PartnerService (com.axelor.apps.base.service.PartnerService)1 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)1 Event (com.axelor.apps.crm.db.Event)1 Lead (com.axelor.apps.crm.db.Lead)1 RecurrenceConfiguration (com.axelor.apps.crm.db.RecurrenceConfiguration)1 EventRepository (com.axelor.apps.crm.db.repo.EventRepository)1 LeadRepository (com.axelor.apps.crm.db.repo.LeadRepository)1