use of com.cognizant.devops.platformworkflow.workflowtask.email.EmailProcesser in project Insights by CognizantOneDevOps.
the class WorkflowTest method testEmailProcessor.
@Test(priority = 10)
public void testEmailProcessor() throws Exception {
try {
MailReport mailReportDTO = createMailDTO();
EmailProcesser emailProcesser = new EmailProcesser(mailReportDTO);
JsonObject response = emailProcesser.call();
Assert.assertEquals(response.get("status").getAsString(), "error");
} catch (AssertionError e) {
Assert.fail(e.getMessage());
}
}
use of com.cognizant.devops.platformworkflow.workflowtask.email.EmailProcesser in project Insights by CognizantOneDevOps.
the class ReportEmailSubscriber method handleTaskExecution.
@Override
public void handleTaskExecution(byte[] body) throws IOException {
String message = new String(body, MQMessageConstants.MESSAGE_ENCODING);
JsonObject statusObject = null;
JsonObject incomingTaskMessage = JsonUtils.parseStringAsJsonObject(message);
try {
long startTime = System.nanoTime();
log.debug("Workflow Detail ==== ReportEmailSubscriber routing key message handleDelivery {} ===== ", message);
InsightsEmailTemplates emailTemplate = workflowDAL.getEmailTemplateByWorkflowId(incomingTaskMessage.get(AssessmentReportAndWorkflowConstants.WORKFLOW_ID).getAsString());
if (emailTemplate != null) {
mailReportDTO = updateEmailHistoryWithEmailTemplateValues(incomingTaskMessage, emailTemplate);
List<JsonObject> failedJobs = new ArrayList<>();
List<JsonObject> successJobs = new ArrayList<>();
List<Callable<JsonObject>> emailListToExecute = new ArrayList<>();
EmailProcesser emailProcesser = new EmailProcesser(mailReportDTO);
emailListToExecute.add(emailProcesser);
/* segregate entire email execution list into defined chunks */
List<List<Callable<JsonObject>>> emailChunkList = WorkflowThreadPool.getChunk(emailListToExecute, 1);
/* submit each chunk to threadpool in a loop */
executeEmailChunks(emailChunkList, failedJobs, successJobs);
if (!successJobs.isEmpty()) {
updateEmailHistoryWithStatus(incomingTaskMessage.get(AssessmentReportAndWorkflowConstants.EXECUTIONID).getAsLong(), WorkflowTaskEnum.EmailStatus.COMPLETED.name());
InsightsStatusProvider.getInstance().createInsightStatusNode("ReportEmailSubscriberEmail Completed ", PlatformServiceConstants.SUCCESS);
}
if (!failedJobs.isEmpty()) {
statusObject = updateFailedTaskStatusLog(failedJobs);
throw new InsightsJobFailedException("Unable to send an email");
}
long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
log.debug("Type=EmailExecution executionId={} workflowId={} ReportName={} mailto={} mailFrom={} ProcessingTime={} message={}", executionId, workflowId, "-", mailReportDTO.getMailTo(), mailReportDTO.getMailFrom(), processingTime, " AttachmentName: " + mailReportDTO.getEmailAttachmentName());
} else {
throw new InsightsJobFailedException("Email template not found!");
}
} catch (InsightsJobFailedException e) {
log.error("Workflow Detail ==== ReportEmailSubscriberEmail Send failed to execute Exception ===== ", e);
updateEmailHistoryWithStatus(incomingTaskMessage.get(AssessmentReportAndWorkflowConstants.EXECUTIONID).getAsLong(), WorkflowTaskEnum.EmailStatus.ERROR.name());
InsightsStatusProvider.getInstance().createInsightStatusNode("ReportEmailSubscriberEmail Completed with error " + e.getMessage(), PlatformServiceConstants.FAILURE);
if (statusObject != null) {
setStatusLog(new Gson().toJson(statusObject));
} else {
setStatusLog(e.getMessage());
}
log.error("Type=EmailExecution executionId={} workflowId={} ReportName={} mailto={} mailFrom={} ProcessingTime={} message={}", executionId, workflowId, "-", mailReportDTO.getMailTo(), mailReportDTO.getMailFrom(), 0, " AttachmentName :" + mailReportDTO.getEmailAttachmentName() + "Failed to send email in ReportEmailSubscriber" + e.getMessage());
throw new InsightsJobFailedException("Failed to send email in ReportEmailSubscriber");
} catch (Exception e) {
log.error("Workflow Detail ==== ReportEmailSubscriberEmail Send failed to execute Exception ===== ", e);
InsightsStatusProvider.getInstance().createInsightStatusNode("ReportEmailSubscriberEmail Completed with error " + e.getMessage(), PlatformServiceConstants.FAILURE);
log.error("Type=EmailExecution executionId={} workflowId={} ReportName={} mailto={} mailFrom={} ProcessingTime={} message={}", executionId, workflowId, "-", mailReportDTO.getMailTo(), mailReportDTO.getMailFrom(), 0, " AttachmentName :" + mailReportDTO.getEmailAttachmentName() + " ReportEmailSubscriberEmail Send failed to execute Exception " + e.getMessage());
}
}
Aggregations