use of com.thinkbiganalytics.common.velocity.model.VelocityTemplate in project kylo by Teradata.
the class DefaultServiceLevelAgreementService method saveEmailTemplate.
public ServiceLevelAgreementEmailTemplate saveEmailTemplate(ServiceLevelAgreementEmailTemplate emailTemplate) {
accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_SERVICE_LEVEL_AGREEMENTS);
return metadataAccess.commit(() -> {
JpaVelocityTemplate jpaVelocityTemplate = null;
if (StringUtils.isNotBlank(emailTemplate.getId())) {
VelocityTemplate.ID id = velocityTemplateProvider.resolveId(emailTemplate.getId());
jpaVelocityTemplate = (JpaVelocityTemplate) velocityTemplateProvider.findById(id);
jpaVelocityTemplate.setName(emailTemplate.getName());
jpaVelocityTemplate.setTitle(emailTemplate.getSubject());
jpaVelocityTemplate.setTemplate(emailTemplate.getTemplate());
jpaVelocityTemplate.setEnabled(emailTemplate.isEnabled());
jpaVelocityTemplate.setDefault(emailTemplate.isDefault());
if (!emailTemplate.isEnabled()) {
List<? extends ServiceLevelAgreementActionTemplate> slaTemplates = serviceLevelAgreementActionTemplateProvider.findByVelocityTemplate(id);
if (slaTemplates != null && !slaTemplates.isEmpty()) {
throw new IllegalArgumentException("Unable to disable this template. There are " + slaTemplates.size() + " SLAs using it.");
}
}
} else {
jpaVelocityTemplate = new JpaVelocityTemplate(ServiceLevelAgreementEmailTemplate.EMAIL_TEMPLATE_TYPE, emailTemplate.getName(), emailTemplate.getName(), emailTemplate.getSubject(), emailTemplate.getTemplate(), emailTemplate.isEnabled());
}
VelocityTemplate template = velocityTemplateProvider.save(jpaVelocityTemplate);
emailTemplate.setId(template.getId().toString());
return emailTemplate;
});
}
use of com.thinkbiganalytics.common.velocity.model.VelocityTemplate in project kylo by Teradata.
the class EmailServiceLevelAgreementAction method parseVelocityTemplate.
private VelocityEmailTemplate parseVelocityTemplate(EmailServiceLevelAgreementActionConfiguration actionConfiguration, ServiceLevelAssessment assessment, Alert a) {
Map<String, Object> map = new HashMap();
map.put("alert", a);
map.put("assessment", assessment);
map.put("assessmentDescription", ServiceLevelAssessmentAlertUtil.getDescription(assessment, "<br/>"));
map.put("slaName", assessment.getAgreement().getName());
map.put("sla", assessment.getAgreement());
String template = actionConfiguration.getVelocityTemplateId();
if (StringUtils.isNotBlank(template)) {
VelocityTemplate defaultTemplate = velocityTemplateProvider.findDefault(ServiceLevelAgreementEmailTemplate.EMAIL_TEMPLATE_TYPE);
VelocityEmailTemplate defaultEmailTemplate = null;
if (defaultTemplate != null) {
defaultEmailTemplate = new VelocityEmailTemplate(defaultTemplate.getTitle(), defaultTemplate.getTemplate());
} else {
defaultEmailTemplate = emailService.getDefaultTemplate();
}
return velocityTemplateProvider.mergeEmailTemplate(template, map, defaultEmailTemplate);
}
return null;
}
use of com.thinkbiganalytics.common.velocity.model.VelocityTemplate in project kylo by Teradata.
the class JpaVelocityTemplateProvider method mergeEmailTemplate.
@Override
public VelocityEmailTemplate mergeEmailTemplate(String velocityTemplateId, Map<String, Object> properties, VelocityEmailTemplate defaultTemplate) {
VelocityTemplate template = findById(resolveId(velocityTemplateId));
VelocityTemplate.ID id = StringUtils.isNotBlank(velocityTemplateId) ? resolveId(velocityTemplateId) : null;
return velocityService.mergeEmailTemplate(template, id, properties, defaultTemplate);
}
use of com.thinkbiganalytics.common.velocity.model.VelocityTemplate in project kylo by Teradata.
the class JpaVelocityTemplateProvider method save.
public VelocityTemplate save(VelocityTemplate template) {
if (template.getId() == null) {
((JpaVelocityTemplate) template).setId(JpaVelocityTemplate.JpaVelocityTemplateId.create());
((JpaVelocityTemplate) template).setSystemName(template.getName());
VelocityTemplate check = velocityTemplateRepository.findBySystemName(template.getSystemName());
if (check != null) {
throw new RuntimeException("Error a template with this Name already exists. Please provide a new name");
}
}
// ensure the default flag is set correctly
JpaVelocityTemplate existingDefault = velocityTemplateRepository.findDefault(template.getType());
if (existingDefault != null) {
if (template.isDefault() && !existingDefault.getId().equals(template.getId())) {
existingDefault.setDefault(false);
velocityTemplateRepository.save(existingDefault);
}
((JpaVelocityTemplate) template).setDefault(template.isDefault());
} else {
((JpaVelocityTemplate) template).setDefault(true);
}
template = velocityTemplateRepository.save((JpaVelocityTemplate) template);
try {
registerWithVelocity(template);
} catch (Exception e) {
Throwables.propagate(e);
}
return template;
}
use of com.thinkbiganalytics.common.velocity.model.VelocityTemplate in project kylo by Teradata.
the class InMemoryVelocityTemplateProvider method mergeEmailTemplate.
@Override
public VelocityEmailTemplate mergeEmailTemplate(String velocityTemplateId, Map<String, Object> properties, VelocityEmailTemplate defaultTemplate) {
VelocityTemplate template = findById(resolveId(velocityTemplateId));
VelocityTemplate.ID id = StringUtils.isNotBlank(velocityTemplateId) ? resolveId(velocityTemplateId) : null;
return velocityService.mergeEmailTemplate(template, id, properties, defaultTemplate);
}
Aggregations