Search in sources :

Example 1 with InsightsEmailTemplates

use of com.cognizant.devops.platformdal.assessmentreport.InsightsEmailTemplates in project Insights by CognizantOneDevOps.

the class WorkflowTestData method saveWorkflowConfig.

public InsightsWorkflowConfiguration saveWorkflowConfig(String workflowId, boolean isActive, boolean reoccurence, String schedule, String reportStatus, String workflowType, JsonArray taskList, long startdate, long enddate, JsonObject emailDetails, boolean runImmediate) throws InsightsCustomException {
    InsightsWorkflowConfiguration workflowConfig = new InsightsWorkflowConfiguration();
    workflowConfig.setWorkflowId(workflowId);
    workflowConfig.setActive(isActive);
    nextRunDaily = InsightsUtils.getNextRunTime(InsightsUtils.getCurrentTimeInSeconds(), schedule, true);
    workflowConfig.setNextRun(nextRunDaily);
    workflowConfig.setLastRun(0L);
    workflowConfig.setReoccurence(reoccurence);
    workflowConfig.setScheduleType(schedule);
    workflowConfig.setStatus(reportStatus);
    workflowConfig.setWorkflowType(workflowType);
    workflowConfig.setRunImmediate(runImmediate);
    Set<InsightsWorkflowTaskSequence> sequneceEntitySet = setSequence(taskList, workflowConfig);
    workflowConfig.setTaskSequenceEntity(sequneceEntitySet);
    if (emailDetails != null) {
        InsightsEmailTemplates emailTemplateConfig = createEmailTemplateObject(emailDetails, workflowConfig);
        workflowConfig.setEmailConfig(emailTemplateConfig);
    }
    return workflowConfig;
}
Also used : InsightsEmailTemplates(com.cognizant.devops.platformdal.assessmentreport.InsightsEmailTemplates) InsightsWorkflowTaskSequence(com.cognizant.devops.platformdal.workflow.InsightsWorkflowTaskSequence) InsightsWorkflowConfiguration(com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration)

Example 2 with InsightsEmailTemplates

use of com.cognizant.devops.platformdal.assessmentreport.InsightsEmailTemplates in project Insights by CognizantOneDevOps.

the class WorkflowTestData method createEmailTemplateObject.

public InsightsEmailTemplates createEmailTemplateObject(JsonObject emailDetails, InsightsWorkflowConfiguration workflowConfig) {
    InsightsEmailTemplates emailTemplateConfig = workflowConfig.getEmailConfig();
    if (emailTemplateConfig == null) {
        emailTemplateConfig = new InsightsEmailTemplates();
    }
    String mailBody = emailDetails.get("mailBodyTemplate").getAsString();
    mailBody = mailBody.replace("#", "<").replace("~", ">");
    emailTemplateConfig.setMailFrom(emailDetails.get("senderEmailAddress").getAsString());
    if (!emailDetails.get("receiverEmailAddress").getAsString().isEmpty()) {
        emailTemplateConfig.setMailTo(emailDetails.get("receiverEmailAddress").getAsString());
    } else {
        emailTemplateConfig.setMailTo(null);
    }
    if (!emailDetails.get("receiverCCEmailAddress").getAsString().isEmpty()) {
        emailTemplateConfig.setMailCC(emailDetails.get("receiverCCEmailAddress").getAsString());
    } else {
        emailTemplateConfig.setMailCC(null);
    }
    if (!emailDetails.get("receiverBCCEmailAddress").getAsString().isEmpty()) {
        emailTemplateConfig.setMailBCC(emailDetails.get("receiverBCCEmailAddress").getAsString());
    } else {
        emailTemplateConfig.setMailBCC(null);
    }
    emailTemplateConfig.setSubject(emailDetails.get("mailSubject").getAsString());
    emailTemplateConfig.setMailBody(mailBody);
    emailTemplateConfig.setWorkflowConfig(workflowConfig);
    return emailTemplateConfig;
}
Also used : InsightsEmailTemplates(com.cognizant.devops.platformdal.assessmentreport.InsightsEmailTemplates)

Example 3 with InsightsEmailTemplates

use of com.cognizant.devops.platformdal.assessmentreport.InsightsEmailTemplates 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)

Example 4 with InsightsEmailTemplates

use of com.cognizant.devops.platformdal.assessmentreport.InsightsEmailTemplates in project Insights by CognizantOneDevOps.

the class AssesmentReportServiceImpl method updateAssessmentReport.

/**
 * Method to update the details in ASSESSMENT_CONFIGURATION table.
 *
 * @param assessmentReportJson
 * @return
 * @throws InsightsCustomException
 */
public int updateAssessmentReport(JsonObject assessmentReportJson) throws InsightsCustomException {
    int assessmentReportId = assessmentReportJson.get("id").getAsInt();
    JsonObject emailDetails = null;
    try {
        InsightsAssessmentConfiguration assessmentConfig = reportConfigDAL.getAssessmentByConfigId(assessmentReportId);
        WorkflowServiceImpl workfowserice = new WorkflowServiceImpl();
        InsightsWorkflowConfiguration workFlowObject = assessmentConfig.getWorkflowConfig();
        workFlowObject.setReoccurence(assessmentReportJson.get(AssessmentReportAndWorkflowConstants.ISREOCCURING).getAsBoolean());
        JsonArray taskArray = assessmentReportJson.get("tasklist").getAsJsonArray();
        Set<InsightsWorkflowTaskSequence> taskSequenceSetPrevious = workFlowObject.getTaskSequenceEntity();
        if (assessmentConfig.getReportTemplateEntity().getVisualizationutil().equalsIgnoreCase(AssessmentReportAndWorkflowConstants.GRAFANAPDF)) {
            Set<Integer> previousTaskId = taskSequenceSetPrevious.stream().map(s -> s.getWorkflowTaskEntity().getTaskId()).collect(Collectors.toSet());
            Set<Integer> requestTaskId = new HashSet<>();
            taskArray.forEach(taskObj -> requestTaskId.add(taskObj.getAsJsonObject().get(AssessmentReportAndWorkflowConstants.TASK_ID).getAsInt()));
            Set<Integer> requestDiffTask = ValidationUtils.differenceOfSet(previousTaskId, requestTaskId);
            log.debug(" previousTaskId {} requestTaskId {} requestDiffTask {}  ", previousTaskId, requestTaskId, requestDiffTask);
            if (!requestDiffTask.isEmpty()) {
                throw new InsightsCustomException(" For Grafana PDF type Report Template, Modifying Task is not allowed.");
            }
        }
        Set<InsightsWorkflowTaskSequence> taskSequenceSet = workfowserice.setSequence(taskArray, workFlowObject);
        workFlowObject.setTaskSequenceEntity(taskSequenceSet);
        if (!assessmentReportJson.get(AssessmentReportAndWorkflowConstants.EMAILDETAILS).isJsonNull()) {
            emailDetails = assessmentReportJson.get(AssessmentReportAndWorkflowConstants.EMAILDETAILS).getAsJsonObject();
            InsightsEmailTemplates emailTemplateConfig = workflowService.createEmailTemplateObject(emailDetails, workFlowObject);
            workFlowObject.setEmailConfig(emailTemplateConfig);
        } else {
            workFlowObject.setEmailConfig(null);
        }
        String username = assessmentReportJson.get(AssessmentReportAndWorkflowConstants.USERNAME).getAsString();
        String orgname = assessmentReportJson.get(AssessmentReportAndWorkflowConstants.ORGNAME).getAsString();
        assessmentConfig.setUserName(username);
        assessmentConfig.setOrgName(orgname);
        assessmentConfig.setWorkflowConfig(workFlowObject);
        reportConfigDAL.updateAssessmentReportConfiguration(assessmentConfig, assessmentReportId);
        return assessmentReportId;
    } catch (Exception e) {
        log.error("Error in updating the report.", e);
        throw new InsightsCustomException(e.getMessage());
    }
}
Also used : InsightsConfigFilesDAL(com.cognizant.devops.platformdal.filemanagement.InsightsConfigFilesDAL) JsonObject(com.google.gson.JsonObject) Arrays(java.util.Arrays) InsightsWorkflowConfiguration(com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration) NoResultException(javax.persistence.NoResultException) Autowired(org.springframework.beans.factory.annotation.Autowired) InsightsUtils(com.cognizant.devops.platformcommons.core.util.InsightsUtils) ReportChartCollection(com.cognizant.devops.platformcommons.constants.ReportChartCollection) Gson(com.google.gson.Gson) PlatformServiceUtil(com.cognizant.devops.platformservice.rest.util.PlatformServiceUtil) InsightsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig) InsightsReportsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig) Set(java.util.Set) Collectors(java.util.stream.Collectors) ApplicationConfigProvider(com.cognizant.devops.platformcommons.config.ApplicationConfigProvider) FileNotFoundException(java.io.FileNotFoundException) ValidationUtils(com.cognizant.devops.platformcommons.core.util.ValidationUtils) List(java.util.List) AssessmentReportAndWorkflowConstants(com.cognizant.devops.platformcommons.constants.AssessmentReportAndWorkflowConstants) PlatformServiceConstants(com.cognizant.devops.platformcommons.constants.PlatformServiceConstants) JsonArray(com.google.gson.JsonArray) Logger(org.apache.logging.log4j.Logger) InsightsEmailTemplates(com.cognizant.devops.platformdal.assessmentreport.InsightsEmailTemplates) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) FilenameUtils(org.apache.commons.io.FilenameUtils) InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) ByteArrayOutputStream(java.io.ByteArrayOutputStream) InsightsWorkflowTaskSequence(com.cognizant.devops.platformdal.workflow.InsightsWorkflowTaskSequence) InsightsAssessmentConfiguration(com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentConfiguration) JsonUtils(com.cognizant.devops.platformcommons.core.util.JsonUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) JsonElement(com.google.gson.JsonElement) VisualizationUtilEnum(com.cognizant.devops.platformcommons.core.enums.VisualizationUtilEnum) InsightsWorkflowTask(com.cognizant.devops.platformdal.workflow.InsightsWorkflowTask) InsightsReportTemplateConfigFiles(com.cognizant.devops.platformdal.assessmentreport.InsightsReportTemplateConfigFiles) Service(org.springframework.stereotype.Service) LinkedList(java.util.LinkedList) GrafanaHandler(com.cognizant.devops.platformcommons.dal.grafana.GrafanaHandler) LinkedHashSet(java.util.LinkedHashSet) ReportConfigDAL(com.cognizant.devops.platformdal.assessmentreport.ReportConfigDAL) InsightsConfigFiles(com.cognizant.devops.platformdal.filemanagement.InsightsConfigFiles) WorkflowServiceImpl(com.cognizant.devops.platformservice.workflow.service.WorkflowServiceImpl) KpiConfigEnum(com.cognizant.devops.platformcommons.core.enums.KpiConfigEnum) Files(java.nio.file.Files) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) InputStreamReader(java.io.InputStreamReader) File(java.io.File) FileDetailsEnum(com.cognizant.devops.platformcommons.core.enums.FileDetailsEnum) WorkflowDAL(com.cognizant.devops.platformdal.workflow.WorkflowDAL) InsightsAssessmentReportTemplate(com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate) WorkflowTaskEnum(com.cognizant.devops.platformcommons.core.enums.WorkflowTaskEnum) MultipartFile(org.springframework.web.multipart.MultipartFile) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) LogManager(org.apache.logging.log4j.LogManager) StringEscapeUtils(org.apache.commons.lang.StringEscapeUtils) ContentConfigEnum(com.cognizant.devops.platformcommons.core.enums.ContentConfigEnum) InputStream(java.io.InputStream) InsightsWorkflowTaskSequence(com.cognizant.devops.platformdal.workflow.InsightsWorkflowTaskSequence) JsonObject(com.google.gson.JsonObject) NoResultException(javax.persistence.NoResultException) FileNotFoundException(java.io.FileNotFoundException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) IOException(java.io.IOException) InsightsAssessmentConfiguration(com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentConfiguration) WorkflowServiceImpl(com.cognizant.devops.platformservice.workflow.service.WorkflowServiceImpl) JsonArray(com.google.gson.JsonArray) InsightsEmailTemplates(com.cognizant.devops.platformdal.assessmentreport.InsightsEmailTemplates) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsWorkflowConfiguration(com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 5 with InsightsEmailTemplates

use of com.cognizant.devops.platformdal.assessmentreport.InsightsEmailTemplates in project Insights by CognizantOneDevOps.

the class UpshiftAssessmentTestData method saveWorkflowConfig.

private InsightsWorkflowConfiguration saveWorkflowConfig(String workflowId, boolean isActive, boolean reoccurence, String schedule, String reportStatus, String workflowType, JsonArray taskList, long startdate, JsonObject emailDetails, boolean runImmediate) throws InsightsCustomException {
    InsightsWorkflowConfiguration workflowConfig = workflowDAL.getWorkflowByWorkflowId(workflowId);
    if (workflowConfig != null) {
        throw new InsightsCustomException("Workflow already exists for with assessment report id " + workflowConfig.getAssessmentConfig().getId());
    }
    workflowConfig = new InsightsWorkflowConfiguration();
    workflowConfig.setWorkflowId(workflowId);
    workflowConfig.setActive(isActive);
    if (schedule.equals(WorkflowTaskEnum.WorkflowSchedule.ONETIME.toString())) {
        workflowConfig.setNextRun(0L);
    } else if (schedule.equals(WorkflowTaskEnum.WorkflowSchedule.BI_WEEKLY_SPRINT.toString()) || schedule.equals(WorkflowTaskEnum.WorkflowSchedule.TRI_WEEKLY_SPRINT.toString())) {
        workflowConfig.setNextRun(InsightsUtils.getNextRunTime(startdate, schedule, true));
    } else {
        workflowConfig.setNextRun(InsightsUtils.getNextRunTime(InsightsUtils.getCurrentTimeInSeconds(), schedule, true));
    }
    workflowConfig.setLastRun(0L);
    workflowConfig.setReoccurence(reoccurence);
    workflowConfig.setScheduleType(schedule);
    workflowConfig.setStatus(reportStatus);
    workflowConfig.setWorkflowType(workflowType);
    workflowConfig.setRunImmediate(runImmediate);
    Set<InsightsWorkflowTaskSequence> sequneceEntitySet = setSequence(taskList, workflowConfig);
    // Attach TaskSequence to workflow
    workflowConfig.setTaskSequenceEntity(sequneceEntitySet);
    if (emailDetails != null) {
        InsightsEmailTemplates emailTemplateConfig = createEmailTemplateObject(emailDetails, workflowConfig);
        workflowConfig.setEmailConfig(emailTemplateConfig);
    }
    return workflowConfig;
}
Also used : InsightsEmailTemplates(com.cognizant.devops.platformdal.assessmentreport.InsightsEmailTemplates) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Aggregations

InsightsEmailTemplates (com.cognizant.devops.platformdal.assessmentreport.InsightsEmailTemplates)13 InsightsCustomException (com.cognizant.devops.platformcommons.exception.InsightsCustomException)6 InsightsWorkflowConfiguration (com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration)6 InsightsWorkflowTaskSequence (com.cognizant.devops.platformdal.workflow.InsightsWorkflowTaskSequence)6 JsonObject (com.google.gson.JsonObject)4 JsonArray (com.google.gson.JsonArray)3 InsightsAssessmentReportTemplate (com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate)2 WorkflowServiceImpl (com.cognizant.devops.platformservice.workflow.service.WorkflowServiceImpl)2 Gson (com.google.gson.Gson)2 JsonElement (com.google.gson.JsonElement)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 ApplicationConfigProvider (com.cognizant.devops.platformcommons.config.ApplicationConfigProvider)1 AssessmentReportAndWorkflowConstants (com.cognizant.devops.platformcommons.constants.AssessmentReportAndWorkflowConstants)1 PlatformServiceConstants (com.cognizant.devops.platformcommons.constants.PlatformServiceConstants)1 ReportChartCollection (com.cognizant.devops.platformcommons.constants.ReportChartCollection)1 ContentConfigEnum (com.cognizant.devops.platformcommons.core.enums.ContentConfigEnum)1 FileDetailsEnum (com.cognizant.devops.platformcommons.core.enums.FileDetailsEnum)1 KpiConfigEnum (com.cognizant.devops.platformcommons.core.enums.KpiConfigEnum)1