Search in sources :

Example 1 with JpaVelocityTemplate

use of com.thinkbiganalytics.metadata.jpa.common.JpaVelocityTemplate 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)

Aggregations

VelocityTemplate (com.thinkbiganalytics.common.velocity.model.VelocityTemplate)1 JpaVelocityTemplate (com.thinkbiganalytics.metadata.jpa.common.JpaVelocityTemplate)1