use of com.axelor.apps.message.db.Message 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;
}
use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.
the class MessageServiceImpl method createMessage.
@Override
public Message createMessage(String model, long id, String subject, String content, EmailAddress fromEmailAddress, List<EmailAddress> replyToEmailAddressList, List<EmailAddress> toEmailAddressList, List<EmailAddress> ccEmailAddressList, List<EmailAddress> bccEmailAddressList, Set<MetaFile> metaFiles, String addressBlock, int mediaTypeSelect, EmailAccount emailAccount, String signature, Boolean isForTemporaryMessage) {
if (!isForTemporaryMessage) {
return createMessage(model, id, subject, content, fromEmailAddress, replyToEmailAddressList, toEmailAddressList, ccEmailAddressList, bccEmailAddressList, metaFiles, addressBlock, mediaTypeSelect, emailAccount, signature);
}
emailAccount = emailAccount != null ? Beans.get(EmailAccountRepository.class).find(emailAccount.getId()) : emailAccount;
Message message = createMessage(content, fromEmailAddress, model, id, null, 0, false, MessageRepository.STATUS_DRAFT, subject, MessageRepository.TYPE_SENT, replyToEmailAddressList, toEmailAddressList, ccEmailAddressList, bccEmailAddressList, addressBlock, mediaTypeSelect, emailAccount, signature);
return message;
}
use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.
the class SendMailQueueService method findMessage.
private Message findMessage(Long messageId) {
Message foundMessage;
final long startTime = System.currentTimeMillis();
while ((foundMessage = messageRepository.find(messageId)) == null && System.currentTimeMillis() - startTime < ENTITY_FIND_TIMEOUT) {
sleep();
}
if (foundMessage == null) {
throw new EntityNotFoundException(messageId.toString());
}
return foundMessage;
}
use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.
the class TemplateMessageServiceImpl method generateMessage.
@Override
@Transactional(rollbackOn = { Exception.class })
public Message generateMessage(Long objectId, String model, String tag, Template template, Boolean isForTemporaryEmail) throws ClassNotFoundException, InstantiationException, IllegalAccessException, AxelorException, IOException {
Templates templates;
Map<String, Object> templatesContext = Maps.newHashMap();
if (template.getTemplateEngineSelect() == TemplateRepository.TEMPLATE_ENGINE_GROOVY_TEMPLATE) {
templates = Beans.get(GroovyTemplates.class);
} else {
templates = new StringTemplates(TEMPLATE_DELIMITER, TEMPLATE_DELIMITER);
}
Object modelObj = template.getIsJson() ? template.getMetaJsonModel() : template.getMetaModel();
if (modelObj != null) {
String modelName = template.getIsJson() ? ((MetaJsonModel) modelObj).getName() : ((MetaModel) modelObj).getFullName();
if (!model.equals(modelName)) {
throw new AxelorException(TraceBackRepository.CATEGORY_INCONSISTENCY, String.format(I18n.get(IExceptionMessage.INVALID_MODEL_TEMPLATE_EMAIL), modelName, model));
}
if (objectId != 0L) {
initMaker(objectId, model, tag, template.getIsJson(), templatesContext);
computeTemplateContexts(template.getTemplateContextList(), objectId, model, template.getIsJson(), templatesContext);
} else {
Class<?> klass = EntityHelper.getEntityClass(this.modelObject);
Context context = new Context(Mapper.toMap(this.modelObject), klass);
templatesContext.put(tag, context.asType(klass));
if (template.getTemplateContextList() != null) {
for (TemplateContext templateContext : template.getTemplateContextList()) {
Object result = templateContextService.computeTemplateContext(templateContext, context);
templatesContext.put(templateContext.getName(), result);
}
}
}
}
log.debug("model : {}", model);
log.debug("tag : {}", tag);
log.debug("object id : {}", objectId);
log.debug("template : {}", template);
Message message = generateMessage(model, objectId, template, templates, templatesContext, isForTemporaryEmail);
if (!isForTemporaryEmail) {
message.setTemplate(Beans.get(TemplateRepository.class).find(template.getId()));
message = Beans.get(MessageRepository.class).save(message);
messageService.attachMetaFiles(message, getMetaFiles(template, templates, templatesContext));
}
return message;
}
use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.
the class TemplateMessageServiceImpl method generateAndSendTemporaryMessage.
@Override
public Message generateAndSendTemporaryMessage(Model model, Template template) throws MessagingException, IOException, AxelorException, ClassNotFoundException, InstantiationException, IllegalAccessException, JSONException {
Message message = this.generateMessage(model, template, true);
messageService.sendMessage(message, true);
return message;
}
Aggregations