Search in sources :

Example 1 with EmailProcesser

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());
    }
}
Also used : MailReport(com.cognizant.devops.platformworkflow.workflowtask.email.MailReport) JsonObject(com.google.gson.JsonObject) EmailProcesser(com.cognizant.devops.platformworkflow.workflowtask.email.EmailProcesser) PlatformWorkflowApplicationTest(com.cognizant.devops.platformworkflow.workflowtask.utils.PlatformWorkflowApplicationTest) Test(org.testng.annotations.Test)

Example 2 with EmailProcesser

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());
    }
}
Also used : ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) Callable(java.util.concurrent.Callable) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) AddressException(javax.mail.internet.AddressException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) InsightsEmailTemplates(com.cognizant.devops.platformdal.assessmentreport.InsightsEmailTemplates) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) ArrayList(java.util.ArrayList) List(java.util.List) EmailProcesser(com.cognizant.devops.platformworkflow.workflowtask.email.EmailProcesser)

Aggregations

EmailProcesser (com.cognizant.devops.platformworkflow.workflowtask.email.EmailProcesser)2 JsonObject (com.google.gson.JsonObject)2 InsightsEmailTemplates (com.cognizant.devops.platformdal.assessmentreport.InsightsEmailTemplates)1 InsightsJobFailedException (com.cognizant.devops.platformreports.exception.InsightsJobFailedException)1 MailReport (com.cognizant.devops.platformworkflow.workflowtask.email.MailReport)1 PlatformWorkflowApplicationTest (com.cognizant.devops.platformworkflow.workflowtask.utils.PlatformWorkflowApplicationTest)1 Gson (com.google.gson.Gson)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1 AddressException (javax.mail.internet.AddressException)1 Test (org.testng.annotations.Test)1