Search in sources :

Example 1 with BirtTemplate

use of com.axelor.apps.base.db.BirtTemplate in project axelor-open-suite by axelor.

the class MessageServiceBaseImpl method printMessage.

@SuppressWarnings("unchecked")
@Override
public String printMessage(Message message) throws AxelorException {
    Company company = message.getCompany();
    if (company == null) {
        return null;
    }
    PrintingSettings printSettings = company.getPrintingSettings();
    if (printSettings == null || printSettings.getDefaultMailBirtTemplate() == null) {
        return null;
    }
    BirtTemplate birtTemplate = printSettings.getDefaultMailBirtTemplate();
    logger.debug("Default BirtTemplate : {}", birtTemplate);
    Templates templates = new StringTemplates('$', '$');
    Map<String, Object> templatesContext = Maps.newHashMap();
    try {
        Class<? extends Model> className = (Class<? extends Model>) Class.forName(message.getClass().getName());
        templatesContext.put("Message", JPA.find(className, message.getId()));
    } catch (ClassNotFoundException e) {
        TraceBackService.trace(e);
    }
    String fileName = "Message " + message.getSubject() + "-" + appBaseService.getTodayDate(company).format(DateTimeFormatter.BASIC_ISO_DATE);
    return Beans.get(TemplateMessageServiceBaseImpl.class).generateBirtTemplateLink(templates, templatesContext, fileName, birtTemplate.getTemplateLink(), birtTemplate.getFormat(), birtTemplate.getBirtTemplateParameterList());
}
Also used : Company(com.axelor.apps.base.db.Company) BirtTemplate(com.axelor.apps.base.db.BirtTemplate) Templates(com.axelor.text.Templates) StringTemplates(com.axelor.text.StringTemplates) StringTemplates(com.axelor.text.StringTemplates) PrintingSettings(com.axelor.apps.base.db.PrintingSettings) Model(com.axelor.db.Model)

Example 2 with BirtTemplate

use of com.axelor.apps.base.db.BirtTemplate in project axelor-open-suite by axelor.

the class PrintTemplateServiceImpl method getMetaFiles.

public Set<MetaFile> getMetaFiles(TemplateMaker maker, PrintTemplate printTemplate) throws AxelorException, IOException {
    Set<MetaFile> metaFiles = new HashSet<>();
    if (printTemplate.getBirtTemplateSet() == null) {
        return metaFiles;
    }
    for (BirtTemplate birtTemplate : printTemplate.getBirtTemplateSet()) {
        metaFiles.add(templateMessageService.createMetaFileUsingBirtTemplate(maker, birtTemplate, null, null));
    }
    LOG.debug("MetaFile to attach: {}", metaFiles);
    return metaFiles;
}
Also used : BirtTemplate(com.axelor.apps.base.db.BirtTemplate) MetaFile(com.axelor.meta.db.MetaFile) HashSet(java.util.HashSet)

Example 3 with BirtTemplate

use of com.axelor.apps.base.db.BirtTemplate in project axelor-open-suite by axelor.

the class TemplateMessageServiceBaseImpl method getMetaFiles.

@Override
public Set<MetaFile> getMetaFiles(Template template, Templates templates, Map<String, Object> templatesContext) throws AxelorException, IOException {
    Set<MetaFile> metaFiles = super.getMetaFiles(template, templates, templatesContext);
    Set<BirtTemplate> birtTemplates = template.getBirtTemplateSet();
    if (CollectionUtils.isEmpty(birtTemplates)) {
        return metaFiles;
    }
    for (BirtTemplate birtTemplate : birtTemplates) {
        metaFiles.add(createMetaFileUsingBirtTemplate(null, birtTemplate, templates, templatesContext));
    }
    logger.debug("Metafile to attach: {}", metaFiles);
    return metaFiles;
}
Also used : BirtTemplate(com.axelor.apps.base.db.BirtTemplate) MetaFile(com.axelor.meta.db.MetaFile)

Aggregations

BirtTemplate (com.axelor.apps.base.db.BirtTemplate)3 MetaFile (com.axelor.meta.db.MetaFile)2 Company (com.axelor.apps.base.db.Company)1 PrintingSettings (com.axelor.apps.base.db.PrintingSettings)1 Model (com.axelor.db.Model)1 StringTemplates (com.axelor.text.StringTemplates)1 Templates (com.axelor.text.Templates)1 HashSet (java.util.HashSet)1