use of com.redhat.cloud.notifications.models.Template in project notifications-backend by RedHatInsights.
the class DbQuteEngineTest method testFromIsoLocalDateTimeExtension.
@Test
void testFromIsoLocalDateTimeExtension() {
Template template = createTemplate("from-iso-local-date-time-template", "{date.fromIsoLocalDateTime()}");
LocalDateTime date = LocalDateTime.of(2022, Month.JANUARY, 1, 0, 0);
TemplateInstance templateInstance = templateService.compileTemplate(template.getData(), template.getName());
assertEquals("2022-01-01T00:00", templateInstance.data("date", date.toString()).render());
}
use of com.redhat.cloud.notifications.models.Template in project notifications-backend by RedHatInsights.
the class DbQuteEngineTest method testActionContextExtension.
@Test
void testActionContextExtension() {
Template template = createTemplate("action-context-template", "{context.foo} {context.bar.baz}");
Context context = new Context.ContextBuilder().withAdditionalProperty("foo", "im foo").withAdditionalProperty("bar", Map.of("baz", "im baz")).build();
TemplateInstance templateInstance = templateService.compileTemplate(template.getData(), template.getName());
assertEquals("im foo im baz", templateInstance.data("context", context).render());
}
use of com.redhat.cloud.notifications.models.Template in project notifications-backend by RedHatInsights.
the class DbQuteEngineTest method testActionPayloadExtension.
@Test
void testActionPayloadExtension() {
Template template = createTemplate("action-payload-template", "{payload.foo} {payload.bar.baz}");
Payload payload = new Payload.PayloadBuilder().withAdditionalProperty("foo", "im foo").withAdditionalProperty("bar", Map.of("baz", "im baz")).build();
TemplateInstance templateInstance = templateService.compileTemplate(template.getData(), template.getName());
assertEquals("im foo im baz", templateInstance.data("payload", payload).render());
}
use of com.redhat.cloud.notifications.models.Template in project notifications-backend by RedHatInsights.
the class ResourceHelpers method createTemplate.
@Transactional
public Template createTemplate(String name, String description, String data) {
Template template = new Template();
template.setName(name);
template.setDescription(description);
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 createDailyEmailTemplate.
/*
* Creates an aggregation email template and the underlying templates only if:
* - the application exists in the DB
* - the aggregation email template does not already exist in the DB
* Existing aggregation email templates are never updated by this migration service.
*/
private void createDailyEmailTemplate(List<String> warnings, String bundleName, String appName, String subjectTemplateName, String subjectTemplateExtension, String subjectTemplateDescription, String bodyTemplateName, String bodyTemplateExtension, String bodyTemplateDescription) {
Optional<Application> app = findApplication(warnings, bundleName, appName);
if (app.isPresent()) {
if (aggregationEmailTemplateExists(app.get())) {
warnings.add(String.format("Aggregation email template found in DB for application: %s/%s", bundleName, appName));
} else {
Template subjectTemplate = getOrCreateTemplate(warnings, subjectTemplateName, subjectTemplateExtension, subjectTemplateDescription);
Template bodyTemplate = getOrCreateTemplate(warnings, bodyTemplateName, bodyTemplateExtension, bodyTemplateDescription);
LOGGER.infof("Creating daily email template for application: %s/%s", bundleName, appName);
AggregationEmailTemplate emailTemplate = new AggregationEmailTemplate();
emailTemplate.setApplication(app.get());
emailTemplate.setSubscriptionType(DAILY);
emailTemplate.setSubjectTemplate(subjectTemplate);
emailTemplate.setSubjectTemplateId(subjectTemplate.getId());
emailTemplate.setBodyTemplate(bodyTemplate);
emailTemplate.setBodyTemplateId(bodyTemplate.getId());
entityManager.persist(emailTemplate);
}
}
}
Aggregations