Search in sources :

Example 6 with StringTemplateLoader

use of cz.metacentrum.perun.notif.StringTemplateLoader in project perun by CESNET.

the class PerunNotifTemplateManagerImpl method init.

@PostConstruct
public void init() throws Exception {
    // Loads all templates to cache
    List<PerunNotifTemplate> templates = perunNotifTemplateDao.getAllPerunNotifTemplates();
    for (PerunNotifTemplate template : templates) {
        // Cache template by id
        allTemplatesById.put(template.getId(), template);
        // Cache template by regexId
        for (PerunNotifRegex regexId : template.getMatchingRegexs()) {
            List<PerunNotifTemplate> templateList = null;
            if (!allTemplatesByRegexId.containsKey(regexId.getId())) {
                templateList = new ArrayList<PerunNotifTemplate>();
                templateList.add(template);
                allTemplatesByRegexId.put(regexId.getId(), templateList);
            } else {
                templateList = allTemplatesByRegexId.get(regexId.getId());
                templateList.add(template);
            }
        }
    }
    //Initialization of freemarker
    StringTemplateLoader stringTemplateLoader = new StringTemplateLoader();
    for (PerunNotifTemplate template : templates) {
        for (PerunNotifTemplateMessage pattern : template.getPerunNotifTemplateMessages()) {
            insertPerunNotifTemplateMessageToLoader(stringTemplateLoader, pattern);
        }
    }
    // create evaluation freemarker template
    stringTemplateLoader.putTemplate(EVALUATION_TEMPLATE, "");
    //All templates loaded to freemarker configuration
    configuration = createFreemarkerConfiguration(stringTemplateLoader);
    session = NotifUtils.getPerunSession(perun);
}
Also used : StringTemplateLoader(cz.metacentrum.perun.notif.StringTemplateLoader) PostConstruct(javax.annotation.PostConstruct)

Aggregations

StringTemplateLoader (cz.metacentrum.perun.notif.StringTemplateLoader)6 Template (freemarker.template.Template)2 StringWriter (java.io.StringWriter)2 PerunBean (cz.metacentrum.perun.core.api.PerunBean)1 AttributeNotExistsException (cz.metacentrum.perun.core.api.exceptions.AttributeNotExistsException)1 UserNotExistsException (cz.metacentrum.perun.core.api.exceptions.UserNotExistsException)1 NotExistsException (cz.metacentrum.perun.notif.exceptions.NotExistsException)1 NotifTemplateMessageAlreadyExistsException (cz.metacentrum.perun.notif.exceptions.NotifTemplateMessageAlreadyExistsException)1 Configuration (freemarker.template.Configuration)1 TemplateException (freemarker.template.TemplateException)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Matcher (java.util.regex.Matcher)1 PostConstruct (javax.annotation.PostConstruct)1