use of com.redhat.cloud.notifications.models.Template in project notifications-backend by RedHatInsights.
the class TemplateRepository method createAggregationEmailTemplate.
@Transactional
public AggregationEmailTemplate createAggregationEmailTemplate(AggregationEmailTemplate template) {
Template subjectTemplate = findTemplate(template.getSubjectTemplateId(), SUBJECT_NOT_FOUND);
Template bodyTemplate = findTemplate(template.getBodyTemplateId(), BODY_NOT_FOUND);
template.setSubscriptionType(template.getSubscriptionType());
template.setSubjectTemplate(subjectTemplate);
template.setBodyTemplate(bodyTemplate);
if (template.getApplicationId() != null) {
Application app = findApplication(template.getApplicationId());
template.setApplication(app);
}
entityManager.persist(template);
// The full application isn't needed in the REST response.
template.filterOutApplication();
// The full templates aren't needed in the REST response.
template.filterOutTemplates();
return template;
}
use of com.redhat.cloud.notifications.models.Template in project notifications-backend by RedHatInsights.
the class TemplateRepository method updateInstantEmailTemplate.
@Transactional
public boolean updateInstantEmailTemplate(UUID id, InstantEmailTemplate template) {
String hql = "UPDATE InstantEmailTemplate SET eventType = :eventType, subjectTemplate = :subjectTemplate, " + "bodyTemplate = :bodyTemplate WHERE id = :id";
EventType eventType;
if (template.getEventTypeId() == null) {
eventType = null;
} else {
eventType = findEventType(template.getEventTypeId());
}
Template subjectTemplate = findTemplate(template.getSubjectTemplateId(), SUBJECT_NOT_FOUND);
Template bodyTemplate = findTemplate(template.getBodyTemplateId(), BODY_NOT_FOUND);
int rowCount = entityManager.createQuery(hql).setParameter("eventType", eventType).setParameter("subjectTemplate", subjectTemplate).setParameter("bodyTemplate", bodyTemplate).setParameter("id", id).executeUpdate();
return rowCount > 0;
}
use of com.redhat.cloud.notifications.models.Template in project notifications-backend by RedHatInsights.
the class TemplateRepository method deleteTemplate.
@Transactional
public boolean deleteTemplate(UUID id) {
Template template = entityManager.find(Template.class, id);
if (template == null) {
throw new NotFoundException("Template not found");
} else {
String checkHql = "SELECT COUNT(*) FROM Template WHERE id != :id AND data LIKE :include";
long count = entityManager.createQuery(checkHql, Long.class).setParameter("id", id).setParameter("include", "%{#include " + template.getName() + "%").getSingleResult();
if (count > 0) {
throw new BadRequestException("Included templates can't be deleted, remove the inclusion or delete the outer template first");
} else {
String deleteHql = "DELETE FROM Template WHERE id = :id";
int rowCount = entityManager.createQuery(deleteHql).setParameter("id", id).executeUpdate();
return rowCount > 0;
}
}
}
use of com.redhat.cloud.notifications.models.Template in project notifications-backend by RedHatInsights.
the class TemplateRepository method createInstantEmailTemplate.
@Transactional
public InstantEmailTemplate createInstantEmailTemplate(InstantEmailTemplate template) {
Template subjectTemplate = findTemplate(template.getSubjectTemplateId(), SUBJECT_NOT_FOUND);
Template bodyTemplate = findTemplate(template.getBodyTemplateId(), BODY_NOT_FOUND);
template.setSubjectTemplate(subjectTemplate);
template.setBodyTemplate(bodyTemplate);
if (template.getEventTypeId() != null) {
EventType eventType = findEventType(template.getEventTypeId());
template.setEventType(eventType);
}
entityManager.persist(template);
// The full event type isn't needed in the REST response.
template.filterOutEventType();
// The full templates aren't needed in the REST response.
template.filterOutTemplates();
return template;
}
use of com.redhat.cloud.notifications.models.Template in project notifications-backend by RedHatInsights.
the class TemplateRepository method updateAggregationEmailTemplate.
@Transactional
public boolean updateAggregationEmailTemplate(UUID id, AggregationEmailTemplate template) {
String hql = "UPDATE AggregationEmailTemplate SET application = :app, subjectTemplate = :subjectTemplate, " + "subscriptionType = :subscriptionType, bodyTemplate = :bodyTemplate WHERE id = :id";
Application app;
if (template.getApplicationId() == null) {
app = null;
} else {
app = findApplication(template.getApplicationId());
}
Template subjectTemplate = findTemplate(template.getSubjectTemplateId(), SUBJECT_NOT_FOUND);
Template bodyTemplate = findTemplate(template.getBodyTemplateId(), BODY_NOT_FOUND);
int rowCount = entityManager.createQuery(hql).setParameter("app", app).setParameter("subscriptionType", template.getSubscriptionType()).setParameter("subjectTemplate", subjectTemplate).setParameter("bodyTemplate", bodyTemplate).setParameter("id", id).executeUpdate();
return rowCount > 0;
}
Aggregations