use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.
the class BatchEventReminder method findOrCreateEmailAddress.
@Transactional
protected EmailAddress findOrCreateEmailAddress(String email, String name) {
EmailAddress emailAddress = emailAddressRepo.all().filter("self.name = '" + name + "'").fetchOne();
if (emailAddress == null) {
emailAddress = new EmailAddress();
emailAddress.setAddress(email);
emailAddress = emailAddressRepo.save(emailAddress);
}
return emailAddress;
}
use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.
the class ICalendarService method findOrCreateUser.
public ICalendarUser findOrCreateUser(User user) {
String email = null;
if (user.getPartner() != null && user.getPartner().getEmailAddress() != null && !Strings.isNullOrEmpty(user.getPartner().getEmailAddress().getAddress())) {
email = user.getPartner().getEmailAddress().getAddress();
} else if (!Strings.isNullOrEmpty(user.getEmail())) {
email = user.getEmail();
} else {
return null;
}
ICalendarUserRepository repo = Beans.get(ICalendarUserRepository.class);
ICalendarUser icalUser = null;
icalUser = repo.all().filter("self.email = ?1 AND self.user.id = ?2", email, user.getId()).fetchOne();
if (icalUser == null) {
icalUser = repo.all().filter("self.user.id = ?1", user.getId()).fetchOne();
}
if (icalUser == null) {
icalUser = repo.all().filter("self.email = ?1", email).fetchOne();
}
if (icalUser == null) {
icalUser = new ICalendarUser();
icalUser.setEmail(email);
icalUser.setName(user.getFullName());
EmailAddress emailAddress = Beans.get(EmailAddressRepository.class).findByAddress(email);
if (emailAddress != null && emailAddress.getPartner() != null && emailAddress.getPartner().getUser() != null) {
icalUser.setUser(emailAddress.getPartner().getUser());
}
}
return icalUser;
}
use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.
the class SyncContactService method importEmailAddress.
protected void importEmailAddress(Person googlePerson, Partner partner, Boolean updateContactField) {
if (googlePerson.getEmailAddresses() == null) {
return;
}
com.google.api.services.people.v1.model.EmailAddress googleEmail = Mapper.toBean(com.google.api.services.people.v1.model.EmailAddress.class, googlePerson.getEmailAddresses().get(0));
if (Strings.isNullOrEmpty(googleEmail.getValue()) || !EmailTool.isValidEmailAddress(googleEmail.getValue())) {
return;
}
if (partner.getEmailAddress() == null || Strings.isNullOrEmpty(partner.getEmailAddress().getAddress())) {
EmailAddress partnerEmail = createEmailAddress(googleEmail.getValue());
partnerEmail.setPartner(partner);
partner.setEmailAddress(partnerEmail);
} else {
if (!partner.getEmailAddress().getAddress().equalsIgnoreCase(googleEmail.getValue())) {
if (updateContactField) {
EmailAddress partnerEmail = createEmailAddress(googleEmail.getValue());
updateDescription(partner, I18n.get(SYNC_CONTACT_OLD_EMAIL), partner.getEmailAddress().getAddress());
partnerEmail.setPartner(partner);
partner.setEmailAddress(partnerEmail);
} else {
updateDescription(partner, I18n.get(SYNC_CONTACT_GOOGLE_EMAIL), googleEmail.getValue());
}
}
}
}
use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.
the class TemplateMessageServiceImpl method generateMessage.
protected Message generateMessage(String model, Long objectId, Template template, Templates templates, Map<String, Object> templatesContext, Boolean isForTemporaryEmail) {
String content = "";
String subject = "";
String replyToRecipients = "";
String toRecipients = "";
String ccRecipients = "";
String bccRecipients = "";
String addressBlock = "";
int mediaTypeSelect;
String signature = "";
if (!Strings.isNullOrEmpty(template.getContent())) {
content = templates.fromText(template.getContent()).make(templatesContext).render();
}
if (!Strings.isNullOrEmpty(template.getAddressBlock())) {
addressBlock = templates.fromText(template.getAddressBlock()).make(templatesContext).render();
}
if (!Strings.isNullOrEmpty(template.getSubject())) {
subject = templates.fromText(template.getSubject()).make(templatesContext).render();
log.debug("Subject ::: {}", subject);
}
if (!Strings.isNullOrEmpty(template.getReplyToRecipients())) {
replyToRecipients = templates.fromText(template.getReplyToRecipients()).make(templatesContext).render();
log.debug("Reply to ::: {}", replyToRecipients);
}
if (template.getToRecipients() != null) {
toRecipients = templates.fromText(template.getToRecipients()).make(templatesContext).render();
log.debug("To ::: {}", toRecipients);
}
if (template.getCcRecipients() != null) {
ccRecipients = templates.fromText(template.getCcRecipients()).make(templatesContext).render();
log.debug("CC ::: {}", ccRecipients);
}
if (template.getBccRecipients() != null) {
bccRecipients = templates.fromText(template.getBccRecipients()).make(templatesContext).render();
log.debug("BCC ::: {}", bccRecipients);
}
mediaTypeSelect = this.getMediaTypeSelect(template);
log.debug("Media ::: {}", mediaTypeSelect);
if (template.getSignature() != null) {
signature = templates.fromText(template.getSignature()).make(templatesContext).render();
log.debug("Signature ::: {}", signature);
}
EmailAccount mailAccount = getMailAccount();
EmailAddress fromAddress = null;
if (mailAccount == null) {
TraceBackService.trace(new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.MAIL_ACCOUNT_6)));
} else {
fromAddress = getEmailAddress(mailAccount.getFromAddress());
}
Message message = messageService.createMessage(model, Math.toIntExact(objectId), subject, content, fromAddress, getEmailAddresses(replyToRecipients), getEmailAddresses(toRecipients), getEmailAddresses(ccRecipients), getEmailAddresses(bccRecipients), null, addressBlock, mediaTypeSelect, mailAccount, signature, isForTemporaryEmail);
return message;
}
use of com.axelor.apps.message.db.EmailAddress in project axelor-open-suite by axelor.
the class MailAccountServiceImpl method getEmailAddress.
private EmailAddress getEmailAddress(InternetAddress address) {
EmailAddress emailAddress = null;
emailAddress = emailAddressRepo.findByAddress(address.getAddress());
if (emailAddress == null) {
emailAddress = new EmailAddress();
emailAddress.setAddress(address.getAddress());
}
return emailAddress;
}
Aggregations