use of com.thinkbiganalytics.feedmgr.sla.TestSlaVelocityEmail in project kylo by Teradata.
the class ServiceLevelAgreementRestController method sendTestTemplate.
@POST
@Path("/send-test-email-template")
@Produces(MediaType.APPLICATION_JSON)
@ApiOperation("Test sending the SLA email template.")
@ApiResponses({ @ApiResponse(code = 200, message = "Test and send the email template to a test address. If unable to send or an error occurs it will be indicated in the response.", response = VelocityEmailTemplate.class) })
public VelocityEmailTemplate sendTestTemplate(TestSlaVelocityEmail template) {
accessController.checkPermission(AccessController.SERVICES, FeedServicesAccessControl.EDIT_SERVICE_LEVEL_AGREEMENT_EMAIL_TEMPLATE);
VelocityEmailTemplate parsedTemplate = testTemplate(template);
String subject = parsedTemplate.getSubject();
String body = parsedTemplate.getBody();
TestSlaVelocityEmail testSlaVelocityEmail = new TestSlaVelocityEmail(subject, body, template.getEmailAddress());
// if we have the plugin then send it
try {
Object emailService = SpringApplicationContext.getBean("slaEmailService");
if (emailService != null) {
MethodUtils.invokeMethod(emailService, "sendMail", template.getEmailAddress(), subject, body);
testSlaVelocityEmail.setSuccess(true);
}
} catch (Exception e) {
String message = e.getMessage();
Throwable root = ExceptionUtils.getRootCause(e);
if (root != null) {
message = root.getMessage();
}
log.error("unable to send preview/test email for SLA template {} ", message, e);
testSlaVelocityEmail.setExceptionMessage(message);
}
return testSlaVelocityEmail;
}
Aggregations