EmailTemplateServiceImpl implements EmailTemplateService { @Override public String applyTemplate(String templateName, String templateContent, WorkflowInstance workflowInstance) { if (templateContent == null && templateScannerRef.get() != null) { templateContent = templateScannerRef.get().getTemplate(templateName); } if (templateContent == null) { logger.warn("E-mail template not found: {}", templateName); return "TEMPLATE NOT FOUND: " + templateName; } HashMap<String, HashMap<String, String>> catalogs = initCatalogs(workflowInstance.getMediaPackage()); WorkflowOperationInstance failed = findFailedOperation(workflowInstance); List<Incident> incidentList = null; if (failed != null) { try { IncidentTree incidents = incidentService.getIncidentsOfJob(failed.getId(), true); incidentList = generateIncidentList(incidents); } catch (Exception e) { logger.error("Error when populating template with incidents", e); } } return DocUtil.generate(new EmailData(templateName, workflowInstance, catalogs, failed, incidentList), templateContent); }  @Override String applyTemplate(String templateName, String templateContent, WorkflowInstance workflowInstance); void setIncidentService(IncidentService incidentService); static final String DEFAULT_DELIMITER_FOR_MULTIPLE; }
@Test public void testTemplateContent() throws Exception { String templateName = "template"; String templateContent = "This is the media package: ${mediaPackage.identifier}"; String result = service.applyTemplate(templateName, templateContent, workflowInstance); Assert.assertEquals("This is the media package: 3e7bb56d-2fcc-4efe-9f0e-d6e56422f557", result); }
@Test public void testTemplateUsingBasicFields() throws Exception { String templateName = "templateBasic"; String templateContent = null; String result = service.applyTemplate(templateName, templateContent, workflowInstance); Assert.assertEquals("Media package id: 3e7bb56d-2fcc-4efe-9f0e-d6e56422f557, workflow id: 1, " + "title: Test Media Package, series title: Fall 2013 Test, " + "date: 2013-11-19T15:20:00Z", result); }
@Test public void testTemplateUsingCatalogFields() throws Exception { String templateName = "templateCatalog"; String templateContent = null; String result = service.applyTemplate(templateName, templateContent, workflowInstance); Assert.assertEquals("EPISODE creator: Rute Santos, isPartOf: 20140119997, " + "title: Test Media Package, created: 2013-11-19T15:20:00Z, " + "SERIES creator: Harvard Extension School, description: http: + "subject: TEST E-19997", result); }
@Test public void testWorkflowConfiguration() throws Exception { String templateName = "templateConfig"; String templateContent = "This is an email address: ${workflowConfig['emailAddress']}"; String result = service.applyTemplate(templateName, templateContent, workflowInstance); Assert.assertEquals("This is an email address: user@domain.com", result); }
@Test public void testFailedOperationAndErrors() throws Exception { String templateName = "templateFailed"; String templateContent = null; String result = service.applyTemplate(templateName, templateContent, workflowInstance); Assert.assertEquals("Workflow failed in operation: operation1, " + "Workflow errors: error in operation1 error in operation2 ", result); }
@Test(expected = Exception.class) public void testErrorInTemplate() throws Exception { String templateName = "templateSyntaxError"; String templateContent = null; service.applyTemplate(templateName, templateContent, workflowInstance); }