Search in sources :

Example 6 with Template

use of com.axelor.apps.message.db.Template in project axelor-open-suite by axelor.

the class BatchEbicsCertificate method process.

@Override
protected void process() {
    Template template = templateRepo.find(bankPaymentBatch.getTemplate().getId());
    List<EbicsUser> users = Beans.get(EbicsUserRepository.class).all().filter("self.a005Certificate != null OR self.e002Certificate != null OR self.x002Certificate != null").fetch();
    Set<EbicsCertificate> certificatesSet = new HashSet<>();
    LocalDate today = Beans.get(AppBaseService.class).getTodayDate(bankPaymentBatch.getCompany());
    LocalDate commingDay = today.plusDays(bankPaymentBatch.getDaysNbr());
    for (EbicsUser user : users) {
        if (user.getA005Certificate() != null && user.getA005Certificate().getValidTo().isBefore(commingDay)) {
            certificatesSet.add(user.getA005Certificate());
        }
        if (user.getE002Certificate() != null && user.getE002Certificate().getValidTo().isBefore(commingDay)) {
            certificatesSet.add(user.getE002Certificate());
        }
        if (user.getX002Certificate() != null && user.getX002Certificate().getValidTo().isBefore(commingDay)) {
            certificatesSet.add(user.getX002Certificate());
        }
    }
    certificatesSet.addAll(Beans.get(EbicsCertificateRepository.class).all().filter("self.ebicsBank != null AND self.validTo <= ?1", commingDay).fetch());
    for (EbicsCertificate certificate : certificatesSet) {
        certificate.addBatchSetItem(batchRepo.find(batch.getId()));
        try {
            templateMessageService.generateMessage(certificate, template);
        } catch (ClassNotFoundException | InstantiationException | IllegalAccessException | AxelorException | IOException e) {
            e.printStackTrace();
        }
    }
}
Also used : EbicsUserRepository(com.axelor.apps.bankpayment.db.repo.EbicsUserRepository) AxelorException(com.axelor.exception.AxelorException) EbicsUser(com.axelor.apps.bankpayment.db.EbicsUser) IOException(java.io.IOException) LocalDate(java.time.LocalDate) Template(com.axelor.apps.message.db.Template) EbicsCertificate(com.axelor.apps.bankpayment.db.EbicsCertificate) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) HashSet(java.util.HashSet)

Example 7 with Template

use of com.axelor.apps.message.db.Template in project axelor-open-suite by axelor.

the class UserServiceImpl method processChangedPassword.

@Override
@Transactional(rollbackOn = { Exception.class })
public void processChangedPassword(User user) throws ClassNotFoundException, InstantiationException, IllegalAccessException, MessagingException, IOException, AxelorException, JSONException {
    Preconditions.checkNotNull(user, I18n.get("User cannot be null."));
    try {
        if (!user.getSendEmailUponPasswordChange()) {
            return;
        }
        if (user.equals(AuthUtils.getUser())) {
            logger.debug("User {} changed own password.", user.getCode());
            return;
        }
        AppBase appBase = Beans.get(AppBaseService.class).getAppBase();
        Template template = appBase.getPasswordChangedTemplate();
        if (template == null) {
            throw new AxelorException(appBase, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get("Template for changed password is missing."));
        }
        TemplateMessageService templateMessageService = Beans.get(TemplateMessageService.class);
        templateMessageService.generateAndSendMessage(user, template);
    } finally {
        user.setTransientPassword(null);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) AppBase(com.axelor.apps.base.db.AppBase) Template(com.axelor.apps.message.db.Template) Transactional(com.google.inject.persist.Transactional)

Example 8 with Template

use of com.axelor.apps.message.db.Template in project axelor-open-suite by axelor.

the class TimesheetReportServiceImpl method sendReminders.

@Transactional
public List<Message> sendReminders(TimesheetReport timesheetReport) throws AxelorException {
    Template reminderTemplate = Beans.get(AppHumanResourceService.class).getAppTimesheet().getTimesheetReminderTemplate();
    if (reminderTemplate == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.EMPLOYEE_TIMESHEET_REMINDER_TEMPLATE));
    }
    List<TimesheetReminder> timesheetReminders = getTimesheetReminderList(timesheetReport);
    return sendEmailMessage(timesheetReminders, reminderTemplate);
}
Also used : AxelorException(com.axelor.exception.AxelorException) TimesheetReminder(com.axelor.apps.hr.db.TimesheetReminder) Template(com.axelor.apps.message.db.Template) Transactional(com.google.inject.persist.Transactional)

Example 9 with Template

use of com.axelor.apps.message.db.Template in project axelor-open-suite by axelor.

the class TimesheetServiceImpl method sendConfirmationEmail.

@Override
@Transactional(rollbackOn = { Exception.class })
public Message sendConfirmationEmail(Timesheet timesheet) throws AxelorException, ClassNotFoundException, InstantiationException, IllegalAccessException, MessagingException, IOException, JSONException {
    HRConfig hrConfig = hrConfigService.getHRConfig(timesheet.getCompany());
    Template template = hrConfig.getSentTimesheetTemplate();
    if (hrConfig.getTimesheetMailNotification() && template != null) {
        return templateMessageService.generateAndSendMessage(timesheet, template);
    }
    return null;
}
Also used : HRConfig(com.axelor.apps.hr.db.HRConfig) Template(com.axelor.apps.message.db.Template) Transactional(com.google.inject.persist.Transactional)

Example 10 with Template

use of com.axelor.apps.message.db.Template in project axelor-open-suite by axelor.

the class TimesheetServiceImpl method sendValidationEmail.

@Override
@Transactional(rollbackOn = { Exception.class })
public Message sendValidationEmail(Timesheet timesheet) throws AxelorException, ClassNotFoundException, InstantiationException, IllegalAccessException, MessagingException, IOException, JSONException {
    HRConfig hrConfig = hrConfigService.getHRConfig(timesheet.getCompany());
    Template template = hrConfig.getValidatedTimesheetTemplate();
    if (hrConfig.getTimesheetMailNotification() && template != null) {
        return templateMessageService.generateAndSendMessage(timesheet, template);
    }
    return null;
}
Also used : HRConfig(com.axelor.apps.hr.db.HRConfig) Template(com.axelor.apps.message.db.Template) Transactional(com.google.inject.persist.Transactional)

Aggregations

Template (com.axelor.apps.message.db.Template)18 AxelorException (com.axelor.exception.AxelorException)8 Transactional (com.google.inject.persist.Transactional)8 Message (com.axelor.apps.message.db.Message)7 IOException (java.io.IOException)5 Employee (com.axelor.apps.hr.db.Employee)4 HRConfig (com.axelor.apps.hr.db.HRConfig)4 TemplateMessageService (com.axelor.apps.message.service.TemplateMessageService)3 MessagingException (javax.mail.MessagingException)3 Company (com.axelor.apps.base.db.Company)2 AppBaseService (com.axelor.apps.base.service.app.AppBaseService)2 EmailAddress (com.axelor.apps.message.db.EmailAddress)2 User (com.axelor.auth.db.User)2 MetaModel (com.axelor.meta.db.MetaModel)2 HashSet (java.util.HashSet)2 DebtRecoveryHistory (com.axelor.apps.account.db.DebtRecoveryHistory)1 DebtRecoveryMethodLine (com.axelor.apps.account.db.DebtRecoveryMethodLine)1 IExceptionMessage (com.axelor.apps.account.exception.IExceptionMessage)1 EbicsCertificate (com.axelor.apps.bankpayment.db.EbicsCertificate)1 EbicsUser (com.axelor.apps.bankpayment.db.EbicsUser)1