Search in sources :

Example 16 with EmailAddress

use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.

the class ICalendarService method findOrCreateUser.

protected ICalendarUser findOrCreateUser(Property source, ICalendarEvent event) {
    URI addr = null;
    if (source instanceof Organizer) {
        addr = ((Organizer) source).getCalAddress();
    }
    if (source instanceof Attendee) {
        addr = ((Attendee) source).getCalAddress();
    }
    if (addr == null) {
        return null;
    }
    String email = mailto(addr.toString(), true);
    ICalendarUserRepository repo = Beans.get(ICalendarUserRepository.class);
    ICalendarUser user = null;
    if (source instanceof Organizer) {
        user = repo.all().filter("self.email = ?1", email).fetchOne();
    } else {
        user = repo.all().filter("self.email = ?1 AND self.event.id = ?2", email, event.getId()).fetchOne();
    }
    if (user == null) {
        user = new ICalendarUser();
        user.setEmail(email);
        user.setName(email);
        EmailAddress emailAddress = Beans.get(EmailAddressRepository.class).findByAddress(email);
        if (emailAddress != null && emailAddress.getPartner() != null && emailAddress.getPartner().getUser() != null) {
            user.setUser(emailAddress.getPartner().getUser());
        }
    }
    if (source.getParameter(Parameter.CN) != null) {
        user.setName(source.getParameter(Parameter.CN).getValue());
    }
    if (source.getParameter(Parameter.PARTSTAT) != null) {
        String role = source.getParameter(Parameter.PARTSTAT).getValue();
        if (role.equals("TENTATIVE")) {
            user.setStatusSelect(ICalendarUserRepository.STATUS_MAYBE);
        } else if (role.equals("ACCEPTED")) {
            user.setStatusSelect(ICalendarUserRepository.STATUS_YES);
        } else if (role.equals("DECLINED")) {
            user.setStatusSelect(ICalendarUserRepository.STATUS_NO);
        }
    }
    return user;
}
Also used : ICalendarUser(com.axelor.apps.base.db.ICalendarUser) Organizer(net.fortuna.ical4j.model.property.Organizer) EmailAddressRepository(com.axelor.apps.message.db.repo.EmailAddressRepository) URI(java.net.URI) Attendee(net.fortuna.ical4j.model.property.Attendee) EmailAddress(com.axelor.apps.message.db.EmailAddress) ICalendarUserRepository(com.axelor.apps.base.db.repo.ICalendarUserRepository)

Example 17 with EmailAddress

use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.

the class MessageServiceImpl method createMessage.

protected Message createMessage(String content, EmailAddress fromEmailAddress, String relatedTo1Select, long relatedTo1SelectId, String relatedTo2Select, long relatedTo2SelectId, boolean sentByEmail, int statusSelect, String subject, int typeSelect, List<EmailAddress> replyToEmailAddressList, List<EmailAddress> toEmailAddressList, List<EmailAddress> ccEmailAddressList, List<EmailAddress> bccEmailAddressList, String addressBlock, int mediaTypeSelect, EmailAccount emailAccount, String signature) {
    Set<EmailAddress> replyToEmailAddressSet = Sets.newHashSet();
    Set<EmailAddress> bccEmailAddressSet = Sets.newHashSet();
    Set<EmailAddress> toEmailAddressSet = Sets.newHashSet();
    Set<EmailAddress> ccEmailAddressSet = Sets.newHashSet();
    if (mediaTypeSelect == MessageRepository.MEDIA_TYPE_EMAIL) {
        if (replyToEmailAddressList != null) {
            replyToEmailAddressSet.addAll(replyToEmailAddressList);
        }
        if (bccEmailAddressList != null) {
            bccEmailAddressSet.addAll(bccEmailAddressList);
        }
        if (toEmailAddressList != null) {
            toEmailAddressSet.addAll(toEmailAddressList);
        }
        if (ccEmailAddressList != null) {
            ccEmailAddressSet.addAll(ccEmailAddressList);
        }
    }
    if (!Strings.isNullOrEmpty(signature)) {
        content += "<p></p><p></p>" + signature;
    } else if (emailAccount != null) {
        content += "<p></p><p></p>" + Beans.get(MailAccountService.class).getSignature(emailAccount);
    }
    Message message = new Message(typeSelect, subject, content, statusSelect, mediaTypeSelect, addressBlock, fromEmailAddress, replyToEmailAddressSet, toEmailAddressSet, ccEmailAddressSet, bccEmailAddressSet, sentByEmail, emailAccount);
    message.setRelatedTo1Select(relatedTo1Select);
    message.setRelatedTo1SelectId(relatedTo1SelectId);
    message.setRelatedTo2Select(relatedTo2Select);
    message.setRelatedTo2SelectId(relatedTo2SelectId);
    return message;
}
Also used : Message(com.axelor.apps.message.db.Message) IExceptionMessage(com.axelor.apps.message.exception.IExceptionMessage) EmailAddress(com.axelor.apps.message.db.EmailAddress)

Example 18 with EmailAddress

use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.

the class TemplateMessageServiceImpl method getEmailAddress.

protected EmailAddress getEmailAddress(String recipient) {
    if (Strings.isNullOrEmpty(recipient)) {
        return null;
    }
    EmailAddressRepository emailAddressRepo = Beans.get(EmailAddressRepository.class);
    EmailAddress emailAddress = emailAddressRepo.findByAddress(recipient);
    if (emailAddress == null) {
        Map<String, Object> values = new HashMap<>();
        values.put("address", recipient);
        emailAddress = emailAddressRepo.create(values);
    }
    return emailAddress;
}
Also used : HashMap(java.util.HashMap) EmailAddressRepository(com.axelor.apps.message.db.repo.EmailAddressRepository) EmailAddress(com.axelor.apps.message.db.EmailAddress)

Aggregations

EmailAddress (com.axelor.apps.message.db.EmailAddress)18 Message (com.axelor.apps.message.db.Message)5 EmailAddressRepository (com.axelor.apps.message.db.repo.EmailAddressRepository)5 User (com.axelor.auth.db.User)3 Transactional (com.google.inject.persist.Transactional)3 ArrayList (java.util.ArrayList)3 ICalendarUser (com.axelor.apps.base.db.ICalendarUser)2 Partner (com.axelor.apps.base.db.Partner)2 ICalendarUserRepository (com.axelor.apps.base.db.repo.ICalendarUserRepository)2 EmailAccount (com.axelor.apps.message.db.EmailAccount)2 Template (com.axelor.apps.message.db.Template)2 IExceptionMessage (com.axelor.apps.message.exception.IExceptionMessage)2 AxelorException (com.axelor.exception.AxelorException)2 HashMap (java.util.HashMap)2 InternetAddress (javax.mail.internet.InternetAddress)2 Address (com.axelor.apps.base.db.Address)1 PartnerService (com.axelor.apps.base.service.PartnerService)1 Lead (com.axelor.apps.crm.db.Lead)1 Employee (com.axelor.apps.hr.db.Employee)1 TemplateRepository (com.axelor.apps.message.db.repo.TemplateRepository)1