Search in sources :

Example 1 with VelocityTemplate

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;
    });
}
Also used : JpaVelocityTemplate(com.thinkbiganalytics.metadata.jpa.common.JpaVelocityTemplate) VelocityTemplate(com.thinkbiganalytics.common.velocity.model.VelocityTemplate) JpaVelocityTemplate(com.thinkbiganalytics.metadata.jpa.common.JpaVelocityTemplate)

Example 2 with VelocityTemplate

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;
}
Also used : VelocityTemplate(com.thinkbiganalytics.common.velocity.model.VelocityTemplate) HashMap(java.util.HashMap) VelocityEmailTemplate(com.thinkbiganalytics.common.velocity.model.VelocityEmailTemplate)

Example 3 with VelocityTemplate

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);
}
Also used : VelocityTemplate(com.thinkbiganalytics.common.velocity.model.VelocityTemplate)

Example 4 with VelocityTemplate

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;
}
Also used : VelocityTemplate(com.thinkbiganalytics.common.velocity.model.VelocityTemplate)

Example 5 with VelocityTemplate

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);
}
Also used : VelocityTemplate(com.thinkbiganalytics.common.velocity.model.VelocityTemplate)

Aggregations

VelocityTemplate (com.thinkbiganalytics.common.velocity.model.VelocityTemplate)5 VelocityEmailTemplate (com.thinkbiganalytics.common.velocity.model.VelocityEmailTemplate)1 JpaVelocityTemplate (com.thinkbiganalytics.metadata.jpa.common.JpaVelocityTemplate)1 HashMap (java.util.HashMap)1