Search in sources :

Example 21 with Template

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());
}
Also used : LocalDateTime(java.time.LocalDateTime) Template(com.redhat.cloud.notifications.models.Template) TemplateInstance(io.quarkus.qute.TemplateInstance) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 22 with Template

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());
}
Also used : Context(com.redhat.cloud.notifications.ingress.Context) Template(com.redhat.cloud.notifications.models.Template) TemplateInstance(io.quarkus.qute.TemplateInstance) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 23 with Template

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());
}
Also used : Payload(com.redhat.cloud.notifications.ingress.Payload) Template(com.redhat.cloud.notifications.models.Template) TemplateInstance(io.quarkus.qute.TemplateInstance) QuarkusTest(io.quarkus.test.junit.QuarkusTest) Test(org.junit.jupiter.api.Test)

Example 24 with Template

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;
}
Also used : AggregationEmailTemplate(com.redhat.cloud.notifications.models.AggregationEmailTemplate) Template(com.redhat.cloud.notifications.models.Template) InstantEmailTemplate(com.redhat.cloud.notifications.models.InstantEmailTemplate) Transactional(javax.transaction.Transactional)

Example 25 with 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);
        }
    }
}
Also used : AggregationEmailTemplate(com.redhat.cloud.notifications.models.AggregationEmailTemplate) Application(com.redhat.cloud.notifications.models.Application) AggregationEmailTemplate(com.redhat.cloud.notifications.models.AggregationEmailTemplate) Template(com.redhat.cloud.notifications.models.Template) InstantEmailTemplate(com.redhat.cloud.notifications.models.InstantEmailTemplate)

Aggregations

Template (com.redhat.cloud.notifications.models.Template)25 AggregationEmailTemplate (com.redhat.cloud.notifications.models.AggregationEmailTemplate)14 InstantEmailTemplate (com.redhat.cloud.notifications.models.InstantEmailTemplate)14 QuarkusTest (io.quarkus.test.junit.QuarkusTest)12 Test (org.junit.jupiter.api.Test)12 Transactional (javax.transaction.Transactional)8 TemplateInstance (io.quarkus.qute.TemplateInstance)6 CrudTestHelpers.createAggregationEmailTemplate (com.redhat.cloud.notifications.CrudTestHelpers.createAggregationEmailTemplate)5 CrudTestHelpers.createInstantEmailTemplate (com.redhat.cloud.notifications.CrudTestHelpers.createInstantEmailTemplate)5 CrudTestHelpers.createTemplate (com.redhat.cloud.notifications.CrudTestHelpers.createTemplate)5 CrudTestHelpers.deleteAggregationEmailTemplate (com.redhat.cloud.notifications.CrudTestHelpers.deleteAggregationEmailTemplate)5 CrudTestHelpers.deleteInstantEmailTemplate (com.redhat.cloud.notifications.CrudTestHelpers.deleteInstantEmailTemplate)5 CrudTestHelpers.deleteTemplate (com.redhat.cloud.notifications.CrudTestHelpers.deleteTemplate)5 CrudTestHelpers.updateAggregationEmailTemplate (com.redhat.cloud.notifications.CrudTestHelpers.updateAggregationEmailTemplate)5 CrudTestHelpers.updateInstantEmailTemplate (com.redhat.cloud.notifications.CrudTestHelpers.updateInstantEmailTemplate)5 CrudTestHelpers.updateTemplate (com.redhat.cloud.notifications.CrudTestHelpers.updateTemplate)5 DbIsolatedTest (com.redhat.cloud.notifications.db.DbIsolatedTest)4 Header (io.restassured.http.Header)4 JsonObject (io.vertx.core.json.JsonObject)4 LocalDateTime (java.time.LocalDateTime)4