Search in sources :

Example 36 with Message

use of com.axelor.apps.message.db.Message 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 37 with Message

use of com.axelor.apps.message.db.Message 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 38 with Message

use of com.axelor.apps.message.db.Message 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)

Example 39 with Message

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

the class MessageServiceCrmImpl method createMessage.

@Transactional(rollbackOn = { Exception.class })
public Message createMessage(Event event) throws AxelorException, ClassNotFoundException, InstantiationException, IllegalAccessException, IOException {
    // Get template depending on event type
    Template template = null;
    switch(event.getTypeSelect()) {
        case EventRepository.TYPE_EVENT:
            template = Beans.get(CrmConfigService.class).getCrmConfig(event.getUser().getActiveCompany()).getEventTemplate();
            break;
        case EventRepository.TYPE_CALL:
            template = Beans.get(CrmConfigService.class).getCrmConfig(event.getUser().getActiveCompany()).getCallTemplate();
            break;
        case EventRepository.TYPE_MEETING:
            template = Beans.get(CrmConfigService.class).getCrmConfig(event.getUser().getActiveCompany()).getMeetingTemplate();
            break;
        case EventRepository.TYPE_TASK:
            template = Beans.get(CrmConfigService.class).getCrmConfig(event.getUser().getActiveCompany()).getTaskTemplate();
            break;
        default:
            break;
    }
    Message message = Beans.get(TemplateMessageService.class).generateMessage(event, template);
    return messageRepository.save(message);
}
Also used : CrmConfigService(com.axelor.apps.crm.service.config.CrmConfigService) Message(com.axelor.apps.message.db.Message) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) Template(com.axelor.apps.message.db.Template) Transactional(com.google.inject.persist.Transactional)

Example 40 with Message

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

the class DMSFileServiceImpl method sendEmail.

@Override
public void sendEmail(DMSFile dmsFile) throws AxelorException, MessagingException {
    final EmailAccount emailAccount = mailAccountService.getDefaultSender();
    User currentUser = AuthUtils.getUser();
    User lockedBy = dmsFile.getLockedBy();
    EmailAddress emailAddress = this.getEmailAddress(lockedBy);
    String content = null;
    String language = currentUser.getLanguage();
    if (language != null && language.equals("fr")) {
        content = String.format(CONTENT_EN, lockedBy.getFullName(), currentUser.getFullName());
    } else {
        content = String.format(CONTENT_EN, lockedBy.getFullName(), currentUser.getFullName());
    }
    List<EmailAddress> toEmailAddressList = new ArrayList<>();
    toEmailAddressList.add(emailAddress);
    Message message = messageService.createMessage(null, 0, I18n.get(SUBJECT), content, null, null, toEmailAddressList, null, null, null, null, MessageRepository.MEDIA_TYPE_EMAIL, emailAccount, null);
    messageService.sendByEmail(message);
}
Also used : EmailAccount(com.axelor.apps.message.db.EmailAccount) User(com.axelor.auth.db.User) IExceptionMessage(com.axelor.apps.projectdms.exception.IExceptionMessage) Message(com.axelor.apps.message.db.Message) ArrayList(java.util.ArrayList) EmailAddress(com.axelor.apps.message.db.EmailAddress)

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