Search in sources :

Example 11 with Template

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

Example 12 with Template

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());
        }
    }
}
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 13 with Template

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

Example 14 with Template

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);
}
Also used : TemplateRepository(com.axelor.apps.message.db.repo.TemplateRepository) User(com.axelor.auth.db.User) Message(com.axelor.apps.message.db.Message) EmailAddressRepository(com.axelor.apps.message.db.repo.EmailAddressRepository) FullContext(com.axelor.apps.tool.context.FullContext) ArrayList(java.util.ArrayList) EmailAddress(com.axelor.apps.message.db.EmailAddress) Template(com.axelor.apps.message.db.Template)

Example 15 with Template

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);
}
Also used : Employee(com.axelor.apps.hr.db.Employee) User(com.axelor.auth.db.User) Message(com.axelor.apps.message.db.Message) EmailAddress(com.axelor.apps.message.db.EmailAddress) 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