use of com.redhat.cloud.notifications.models.Template in project notifications-backend by RedHatInsights.
the class DbQuteEngineTest method updateTemplateData.
@Transactional
void updateTemplateData(UUID id, String data) {
Template template = entityManager.find(Template.class, id);
template.setData(data);
}
use of com.redhat.cloud.notifications.models.Template in project notifications-backend by RedHatInsights.
the class DbQuteEngineTest method testToTimeAgoExtension.
@Test
void testToTimeAgoExtension() {
Template template = createTemplate("to-time-ago-template", "{date.toTimeAgo()}");
LocalDateTime date = LocalDateTime.now().minusDays(2L);
TemplateInstance templateInstance = templateService.compileTemplate(template.getData(), template.getName());
assertEquals("2 days ago", templateInstance.data("date", date).render());
assertEquals("2 days ago", templateInstance.data("date", date.toString()).render());
}
use of com.redhat.cloud.notifications.models.Template in project notifications-backend by RedHatInsights.
the class DbQuteEngineTest method testIncludeUnknownTemplate.
@Test
void testIncludeUnknownTemplate() {
Template outerTemplate = createTemplate("other-outer-template", "Hello, {#include unknown-inner-template /}");
TemplateException e = assertThrows(TemplateException.class, () -> {
statelessSessionFactory.withSession(statelessSession -> {
templateService.compileTemplate(outerTemplate.getData(), outerTemplate.getName()).render();
});
});
assertEquals("Included template [unknown-inner-template] not found in template [other-outer-template] on line 1", e.getMessage());
}
use of com.redhat.cloud.notifications.models.Template in project notifications-backend by RedHatInsights.
the class DbQuteEngineTest method createTemplate.
@Transactional
Template createTemplate(String name, String data) {
Template template = new Template();
template.setName(name);
template.setDescription("The best template ever created");
template.setData(data);
entityManager.persist(template);
return template;
}
use of com.redhat.cloud.notifications.models.Template in project notifications-backend by RedHatInsights.
the class EmailTemplateMigrationService method getOrCreateTemplate.
/*
* Creates a template only if it does not already exist in the DB.
* Existing templates are never updated by this migration service.
*/
Template getOrCreateTemplate(List<String> warnings, String name, String extension, String description) {
try {
Template template = entityManager.createQuery("FROM Template WHERE name = :name", Template.class).setParameter("name", name).getSingleResult();
warnings.add(String.format("Template found in DB: %s", name));
return template;
} catch (NoResultException e) {
LOGGER.infof("Creating template: %s", name);
Template template = new Template();
template.setName(name);
template.setDescription(description);
template.setData(loadResourceTemplate(name, extension));
entityManager.persist(template);
return template;
}
}
Aggregations