Search in sources :

Example 1 with Template

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

the class LogisticalFormStockRepository method save.

@Override
public LogisticalForm save(LogisticalForm logisticalForm) {
    try {
        Company company = logisticalForm.getCompany();
        if (company != null) {
            if (Strings.isNullOrEmpty(logisticalForm.getDeliveryNumberSeq())) {
                String sequenceNumber = Beans.get(SequenceService.class).getSequenceNumber("logisticalForm", logisticalForm.getCompany());
                if (Strings.isNullOrEmpty(sequenceNumber)) {
                    throw new AxelorException(Sequence.class, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.LOGISTICAL_FORM_MISSING_SEQUENCE), logisticalForm.getCompany().getName());
                }
                logisticalForm.setDeliveryNumberSeq(sequenceNumber);
            }
            if (!logisticalForm.getIsEmailSent()) {
                StockConfig stockConfig = Beans.get(StockConfigService.class).getStockConfig(company);
                if (stockConfig.getLogisticalFormAutomaticEmail()) {
                    Template template = stockConfig.getLogisticalFormMessageTemplate();
                    if (template == null) {
                        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LOGISTICAL_FORM_MISSING_TEMPLATE), logisticalForm);
                    }
                    Beans.get(TemplateMessageService.class).generateAndSendMessage(logisticalForm, template);
                    logisticalForm.setIsEmailSent(true);
                }
            }
        }
        return super.save(logisticalForm);
    } catch (Exception e) {
        TraceBackService.traceExceptionFromSaveMethod(e);
        throw new PersistenceException(e.getMessage(), e);
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) StockConfig(com.axelor.apps.stock.db.StockConfig) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) PersistenceException(javax.persistence.PersistenceException) SequenceService(com.axelor.apps.base.service.administration.SequenceService) StockConfigService(com.axelor.apps.stock.service.config.StockConfigService) AxelorException(com.axelor.exception.AxelorException) PersistenceException(javax.persistence.PersistenceException) Template(com.axelor.apps.message.db.Template)

Example 2 with Template

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

the class TimesheetServiceImpl method sendCancellationEmail.

@Override
@Transactional(rollbackOn = { Exception.class })
public Message sendCancellationEmail(Timesheet timesheet) throws AxelorException, ClassNotFoundException, InstantiationException, IllegalAccessException, MessagingException, IOException, JSONException {
    HRConfig hrConfig = hrConfigService.getHRConfig(timesheet.getCompany());
    Template template = hrConfig.getCanceledTimesheetTemplate();
    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 3 with Template

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

the class ActionEmailBuilderService method sendEmail.

@CallMethod
public ActionResponse sendEmail(Long objectId, String model, String tag, Long templateId, int sendOption) throws ClassNotFoundException, InstantiationException, IllegalAccessException, AxelorException, IOException, MessagingException {
    Template template = templateRepo.find(templateId);
    Message message = templateMessageService.generateMessage(objectId, model, tag, template);
    ActionResponse response = new ActionResponse();
    if (sendOption == 0) {
        messageService.sendByEmail(message);
    } else {
        response.setView(ActionView.define(I18n.get(IExceptionMessage.MESSAGE_3)).model(Message.class.getName()).add("form", "message-form").param("forceEdit", "true").context("_showRecord", message.getId().toString()).map());
    }
    return response;
}
Also used : Message(com.axelor.apps.message.db.Message) IExceptionMessage(com.axelor.apps.message.exception.IExceptionMessage) ActionResponse(com.axelor.rpc.ActionResponse) Template(com.axelor.apps.message.db.Template) CallMethod(com.axelor.meta.CallMethod)

Example 4 with Template

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

the class ActionEmailBuilderService method build.

public MetaAction build(ActionBuilder builder) {
    String name = builder.getName();
    Object model = builder.getIsJson() ? metaJsonModelRepo.all().filter("self.name = ?", builder.getModel()).fetchOne() : metaModelRepo.all().filter("self.fullName = ?", builder.getModel()).fetchOne();
    int sendOption = builder.getEmailSendOptionSelect();
    Template template = builder.getEmailTemplate();
    String xml = "<action-method name=\"" + name + "\" id=\"" + builder.getXmlId() + "\">\n\t" + "<call class=\"com.axelor.studio.service.builder.ActionEmailBuilderService\" method=\"sendEmail(id, '" + (builder.getIsJson() ? ((MetaJsonModel) model).getName() : ((MetaModel) model).getFullName()) + "', '" + (builder.getIsJson() ? ((MetaJsonModel) model).getName() : ((MetaModel) model).getName()) + "', '" + template.getId() + "', '" + sendOption + "')\" " + "if=\"id != null\"/>\n" + "</action-method>";
    return studioMetaService.updateMetaAction(name, "action-method", xml, null, builder.getXmlId());
}
Also used : MetaJsonModel(com.axelor.meta.db.MetaJsonModel) MetaModel(com.axelor.meta.db.MetaModel) Template(com.axelor.apps.message.db.Template)

Example 5 with Template

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

the class BatchTimesheetReminder method process.

@Override
protected void process() {
    Template template = batch.getHrBatch().getTemplate();
    MetaModel metaModel = template.getMetaModel();
    try {
        if (metaModel != null) {
            if (metaModel.getName().equals(Employee.class.getSimpleName())) {
                sendReminderUsingEmployees(template);
            } else if (metaModel.getName().equals(Timesheet.class.getSimpleName())) {
                sendReminderUsingTimesheets(template);
            }
        }
    } catch (Exception e) {
        TraceBackService.trace(e, metaModel.getName(), batch.getId());
        incrementAnomaly();
    }
}
Also used : MetaModel(com.axelor.meta.db.MetaModel) Employee(com.axelor.apps.hr.db.Employee) MessagingException(javax.mail.MessagingException) AxelorException(com.axelor.exception.AxelorException) IOException(java.io.IOException) Template(com.axelor.apps.message.db.Template)

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