Search in sources :

Example 31 with Message

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);
    }
}
Also used : ExtraHours(com.axelor.apps.hr.db.ExtraHours) Message(com.axelor.apps.message.db.Message) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) ExtraHoursService(com.axelor.apps.hr.service.extra.hours.ExtraHoursService) AxelorException(com.axelor.exception.AxelorException)

Example 32 with Message

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);
    }
}
Also used : ExtraHours(com.axelor.apps.hr.db.ExtraHours) Message(com.axelor.apps.message.db.Message) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) PeriodService(com.axelor.apps.base.service.PeriodService) ExtraHoursService(com.axelor.apps.hr.service.extra.hours.ExtraHoursService) AxelorException(com.axelor.exception.AxelorException)

Example 33 with Message

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);
    }
}
Also used : IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) LeaveService(com.axelor.apps.hr.service.leave.LeaveService) MessageServiceBaseImpl(com.axelor.apps.base.service.message.MessageServiceBaseImpl) PeriodService(com.axelor.apps.base.service.PeriodService) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) AxelorException(com.axelor.exception.AxelorException)

Example 34 with Message

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());
        }
    }
}
Also used : EmployeeRepository(com.axelor.apps.hr.db.repo.EmployeeRepository) Employee(com.axelor.apps.hr.db.Employee) Message(com.axelor.apps.message.db.Message) MessagingException(javax.mail.MessagingException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) Template(com.axelor.apps.message.db.Template)

Example 35 with Message

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);
}
Also used : Message(com.axelor.apps.message.db.Message) Transactional(com.google.inject.persist.Transactional)

Aggregations

Message (com.axelor.apps.message.db.Message)54 AxelorException (com.axelor.exception.AxelorException)25 MessageServiceBaseImpl (com.axelor.apps.base.service.message.MessageServiceBaseImpl)16 IExceptionMessage (com.axelor.apps.message.exception.IExceptionMessage)14 Transactional (com.google.inject.persist.Transactional)13 IExceptionMessage (com.axelor.apps.hr.exception.IExceptionMessage)11 Template (com.axelor.apps.message.db.Template)7 Timesheet (com.axelor.apps.hr.db.Timesheet)6 ArrayList (java.util.ArrayList)6 Employee (com.axelor.apps.hr.db.Employee)5 EmailAddress (com.axelor.apps.message.db.EmailAddress)5 IExceptionMessage (com.axelor.apps.base.exceptions.IExceptionMessage)4 Expense (com.axelor.apps.hr.db.Expense)4 ExtraHours (com.axelor.apps.hr.db.ExtraHours)4 LeaveRequest (com.axelor.apps.hr.db.LeaveRequest)4 ExpenseService (com.axelor.apps.hr.service.expense.ExpenseService)4 ExtraHoursService (com.axelor.apps.hr.service.extra.hours.ExtraHoursService)4 LeaveService (com.axelor.apps.hr.service.leave.LeaveService)4 TimesheetService (com.axelor.apps.hr.service.timesheet.TimesheetService)4 User (com.axelor.auth.db.User)4