use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.
the class BatchTimesheetValidationReminder method generateEmailTemplate.
public void generateEmailTemplate() {
Company company = batch.getMailBatch().getCompany();
Template template = batch.getMailBatch().getTemplate();
List<Timesheet> timesheetList = null;
if (Beans.get(CompanyRepository.class).all().count() > 1) {
timesheetList = Beans.get(TimesheetRepository.class).all().filter("self.company.id = ?1 AND self.statusSelect = 1 AND self.user.employee.timesheetReminder = true", company.getId()).fetch();
} else {
timesheetList = Beans.get(TimesheetRepository.class).all().filter("self.statusSelect = 1 AND self.user.employee.timesheetReminder = true").fetch();
}
String model = template.getMetaModel().getFullName();
String tag = template.getMetaModel().getName();
for (Timesheet timesheet : timesheetList) {
try {
Employee employee = timesheet.getUser().getEmployee();
if (employee == null || EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
continue;
}
Message message = templateMessageService.generateMessage(employee.getId(), model, tag, template);
messageService.sendByEmail(message);
incrementDone();
} catch (Exception e) {
incrementAnomaly();
TraceBackService.trace(new Exception(e), ExceptionOriginRepository.REMINDER, batch.getId());
}
}
}
use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.
the class WkfEmailServiceImpl method sendEmail.
@Override
public void sendEmail(WkfTaskConfig wkfTaskConfig, DelegateExecution execution) throws ClassNotFoundException, MessagingException, AxelorException, InstantiationException, IllegalAccessException, IOException {
String title = wkfTaskConfig.getTaskEmailTitle();
if (title == null) {
return;
}
FullContext wkfContext = wkfUserActionService.getModelCtx(wkfTaskConfig, execution);
if (wkfContext == null) {
return;
}
String model = null;
String tag = null;
Long id = null;
title = wkfUserActionService.processTitle(title, wkfContext);
model = wkfContext.getTarget().getClass().getName();
if (wkfContext.getTarget().getClass().equals(MetaJsonRecord.class)) {
tag = (String) wkfContext.get("jsonModel");
model = tag;
} else {
tag = wkfContext.getTarget().getClass().getSimpleName();
}
id = (Long) wkfContext.get("id");
String url = createUrl(wkfContext, wkfTaskConfig.getDefaultForm());
String activeNode = execution.getCurrentActivityName();
Template template = Beans.get(TemplateRepository.class).findByName(wkfTaskConfig.getTemplateName());
Message message = null;
if (template != null) {
url = "<a href=\"" + url + "\" >" + url + "</a>";
message = Beans.get(TemplateMessageService.class).generateMessage(id, model, tag, template);
message.setSubject(message.getSubject().replace("{{activeNode}}", activeNode));
message.setContent(message.getContent().replace("{{activeNode}}", activeNode));
message.setSubject(message.getSubject().replace("{{recordUrl}}", url));
message.setContent(message.getContent().replace("{{recordUrl}}", url));
} else {
User user = null;
if (wkfTaskConfig.getUserPath() != null) {
user = wkfUserActionService.getUser(wkfTaskConfig.getUserPath(), wkfContext);
}
if (user == null || user.getEmail() == null) {
return;
}
String content = String.format(EMAIL_CONTENT, user.getName(), activeNode, url, url);
List<EmailAddress> toEmailAddressList = new ArrayList<EmailAddress>();
EmailAddress emailAddress = Beans.get(EmailAddressRepository.class).findByAddress(user.getEmail());
if (emailAddress == null) {
emailAddress = new EmailAddress(user.getEmail());
}
toEmailAddressList.add(emailAddress);
message = messageService.createMessage(model, id, title, content, null, null, toEmailAddressList, null, null, null, null, MessageRepository.MEDIA_TYPE_EMAIL, null, null);
}
messageService.sendByEmail(message);
}
use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.
the class AppraisalServiceImpl method send.
@Transactional(rollbackOn = { Exception.class })
@Override
public void send(Appraisal appraisal) throws ClassNotFoundException, InstantiationException, IllegalAccessException, AxelorException, IOException, MessagingException {
Employee employee = appraisal.getEmployee();
User user = employee.getUser();
if (user != null) {
mailFollowerRepo.follow(appraisal, user);
}
Template template = templateRepo.all().filter("self.metaModel.fullName = ?1", Appraisal.class.getName()).fetchOne();
EmailAddress email = null;
if (employee.getContactPartner() != null) {
email = employee.getContactPartner().getEmailAddress();
}
if (template != null && email != null) {
Message message = templateMessageService.generateMessage(appraisal, template);
message.addToEmailAddressSetItem(email);
messageService.sendByEmail(message);
}
appraisal.setStatusSelect(AppraisalRepository.STATUS_SENT);
appraisalRepo.save(appraisal);
}
use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.
the class MessageServiceCrmImpl method createMessage.
@Transactional(rollbackOn = { Exception.class })
public Message createMessage(Event event) throws AxelorException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
// Get template depending on event type
Template template = null;
switch(event.getTypeSelect()) {
case EventRepository.TYPE_EVENT:
template = Beans.get(CrmConfigService.class).getCrmConfig(event.getUser().getActiveCompany()).getEventTemplate();
break;
case EventRepository.TYPE_CALL:
template = Beans.get(CrmConfigService.class).getCrmConfig(event.getUser().getActiveCompany()).getCallTemplate();
break;
case EventRepository.TYPE_MEETING:
template = Beans.get(CrmConfigService.class).getCrmConfig(event.getUser().getActiveCompany()).getMeetingTemplate();
break;
case EventRepository.TYPE_TASK:
template = Beans.get(CrmConfigService.class).getCrmConfig(event.getUser().getActiveCompany()).getTaskTemplate();
break;
default:
break;
}
Message message = Beans.get(TemplateMessageService.class).generateMessage(event, template);
return messageRepository.save(message);
}
use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.
the class DMSFileServiceImpl method sendEmail.
@Override
public void sendEmail(DMSFile dmsFile) throws AxelorException, MessagingException {
final EmailAccount emailAccount = mailAccountService.getDefaultSender();
User currentUser = AuthUtils.getUser();
User lockedBy = dmsFile.getLockedBy();
EmailAddress emailAddress = this.getEmailAddress(lockedBy);
String content = null;
String language = currentUser.getLanguage();
if (language != null && language.equals("fr")) {
content = String.format(CONTENT_EN, lockedBy.getFullName(), currentUser.getFullName());
} else {
content = String.format(CONTENT_EN, lockedBy.getFullName(), currentUser.getFullName());
}
List<EmailAddress> toEmailAddressList = new ArrayList<>();
toEmailAddressList.add(emailAddress);
Message message = messageService.createMessage(null, 0, I18n.get(SUBJECT), content, null, null, toEmailAddressList, null, null, null, null, MessageRepository.MEDIA_TYPE_EMAIL, emailAccount, null);
messageService.sendByEmail(message);
}
Aggregations