Search in sources :

Example 1 with TestSlaVelocityEmail

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;
}
Also used : VelocityEmailTemplate(com.thinkbiganalytics.common.velocity.model.VelocityEmailTemplate) WebApplicationException(javax.ws.rs.WebApplicationException) InvalidOperationException(com.thinkbiganalytics.feedmgr.InvalidOperationException) TestSlaVelocityEmail(com.thinkbiganalytics.feedmgr.sla.TestSlaVelocityEmail) Path(javax.ws.rs.Path) POST(javax.ws.rs.POST) Produces(javax.ws.rs.Produces) ApiOperation(io.swagger.annotations.ApiOperation) ApiResponses(io.swagger.annotations.ApiResponses)

Aggregations

VelocityEmailTemplate (com.thinkbiganalytics.common.velocity.model.VelocityEmailTemplate)1 InvalidOperationException (com.thinkbiganalytics.feedmgr.InvalidOperationException)1 TestSlaVelocityEmail (com.thinkbiganalytics.feedmgr.sla.TestSlaVelocityEmail)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ApiResponses (io.swagger.annotations.ApiResponses)1 POST (javax.ws.rs.POST)1 Path (javax.ws.rs.Path)1 Produces (javax.ws.rs.Produces)1 WebApplicationException (javax.ws.rs.WebApplicationException)1