use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.
the class ExtraHoursController method confirm.
// confirming request and sending mail to manager
public void confirm(ActionRequest request, ActionResponse response) throws AxelorException {
try {
ExtraHours extraHours = request.getContext().asType(ExtraHours.class);
extraHours = Beans.get(ExtraHoursRepository.class).find(extraHours.getId());
Beans.get(ExtraHoursService.class).confirm(extraHours);
Message message = Beans.get(ExtraHoursService.class).sendConfirmationEmail(extraHours);
if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
}
} catch (Exception e) {
TraceBackService.trace(response, e);
} finally {
response.setReload(true);
}
}
use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.
the class ExtraHoursController method valid.
/**
* validating request and sending mail to applicant
*
* @param request
* @param response
* @throws AxelorException
*/
public void valid(ActionRequest request, ActionResponse response) throws AxelorException {
try {
ExtraHours extraHours = request.getContext().asType(ExtraHours.class);
extraHours = Beans.get(ExtraHoursRepository.class).find(extraHours.getId());
Beans.get(ExtraHoursService.class).validate(extraHours);
Message message = Beans.get(ExtraHoursService.class).sendValidationEmail(extraHours);
if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
}
Beans.get(PeriodService.class).checkPeriod(extraHours.getCompany(), extraHours.getValidationDate());
} catch (Exception e) {
TraceBackService.trace(response, e);
} finally {
response.setReload(true);
}
}
use of com.axelor.apps.message.db.Message in project axelor-open-suite by axelor.
the class LeaveController method validate.
/**
* Validates leave request and sends an email to the applicant.
*
* @param request
* @param response
* @throws AxelorException
*/
public void validate(ActionRequest request, ActionResponse response) {
try {
LeaveService leaveService = Beans.get(LeaveService.class);
LeaveRequest leaveRequest = request.getContext().asType(LeaveRequest.class);
leaveRequest = Beans.get(LeaveRequestRepository.class).find(leaveRequest.getId());
leaveService.validate(leaveRequest);
Message message = leaveService.sendValidationEmail(leaveRequest);
if (message != null && message.getStatusSelect() == MessageRepository.STATUS_SENT) {
response.setFlash(String.format(I18n.get("Email sent to %s"), Beans.get(MessageServiceBaseImpl.class).getToRecipients(message)));
}
Beans.get(PeriodService.class).checkPeriod(leaveRequest.getCompany(), leaveRequest.getToDateT().toLocalDate(), leaveRequest.getFromDateT().toLocalDate());
} catch (Exception e) {
TraceBackService.trace(response, e);
} finally {
response.setReload(true);
}
}
use of com.axelor.apps.message.db.Message 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.Message in project axelor-open-suite by axelor.
the class BatchTimesheetValidationReminder method generateAndSendMessage.
@Transactional(rollbackOn = { MessagingException.class, IOException.class, Exception.class })
protected Message generateAndSendMessage(Employee employee) throws MessagingException, IOException, AxelorException {
Message message = new Message();
message.setMediaTypeSelect(MessageRepository.MEDIA_TYPE_EMAIL);
message.setReplyToEmailAddressSet(new HashSet<>());
message.setCcEmailAddressSet(new HashSet<>());
message.setBccEmailAddressSet(new HashSet<>());
message.addToEmailAddressSetItem(employee.getContactPartner().getEmailAddress());
message.setSenderUser(AuthUtils.getUser());
message.setSubject(batch.getMailBatch().getSubject());
message.setContent(batch.getMailBatch().getContent());
message.setMailAccount(Beans.get(EmailAccountRepository.class).all().filter("self.isDefault = true").fetchOne());
message = messageRepo.save(message);
return messageService.sendByEmail(message);
}
Aggregations