use of com.axelor.apps.message.db.Template in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method sendRefusalEmail.
@Override
@Transactional(rollbackOn = { Exception.class })
public Message sendRefusalEmail(Timesheet timesheet) throws AxelorException, ClassNotFoundException, InstantiationException, IllegalAccessException, MessagingException, IOException, JSONException {
HRConfig hrConfig = hrConfigService.getHRConfig(timesheet.getCompany());
Template template = hrConfig.getRefusedTimesheetTemplate();
if (hrConfig.getTimesheetMailNotification() && template != null) {
return templateMessageService.generateAndSendMessage(timesheet, template);
}
return null;
}
use of com.axelor.apps.message.db.Template in project axelor-open-suite by axelor.
the class BatchTimesheetValidationReminder method generateAllEmailTemplate.
public void generateAllEmailTemplate() {
Template template = batch.getMailBatch().getTemplate();
String model = template.getMetaModel().getFullName();
String tag = template.getMetaModel().getName();
List<Employee> employeeList = Beans.get(EmployeeRepository.class).all().filter("self.timesheetReminder = true").fetch();
for (Employee employee : employeeList) {
if (employee == null || EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
continue;
}
try {
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.Template 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.Template 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.Template 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);
}
Aggregations