Search in sources :

Example 1 with InsightsReportVisualizationContainer

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

the class WorkflowServiceImpl method getReportPDF.

/**
 * Method to get Report PDF
 *
 * @param pdfDetailsJson
 * @return byte[]
 * @throws InsightsCustomException
 */
public byte[] getReportPDF(JsonObject pdfDetailsJson) throws InsightsCustomException {
    byte[] pdfContent = null;
    try {
        String workflowId = pdfDetailsJson.get(AssessmentReportAndWorkflowConstants.WORKFLOW_ID).getAsString();
        long executionId = pdfDetailsJson.get("executionId").getAsLong();
        InsightsReportVisualizationContainer reportVisObject = workflowConfigDAL.getReportVisualizationContainerByWorkflowAndExecutionId(workflowId, executionId);
        if (reportVisObject != null) {
            pdfContent = reportVisObject.getAttachmentData();
        } else {
            throw new InsightsCustomException("PDF not generated");
        }
    } catch (Exception e) {
        log.error("Error while updating report status.", e);
        throw new InsightsCustomException(e.toString());
    }
    return pdfContent;
}
Also used : InsightsReportVisualizationContainer(com.cognizant.devops.platformdal.assessmentreport.InsightsReportVisualizationContainer) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Example 2 with InsightsReportVisualizationContainer

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

the class ReportEmailSubscriber method updateEmailHistoryWithStatus.

/**
 * Method to update Email History record status
 *
 * @param executionId
 * @param status
 */
private void updateEmailHistoryWithStatus(long executionId, String status) {
    InsightsReportVisualizationContainer emailHistoryConfig = workflowDAL.getEmailExecutionHistoryByExecutionId(executionId);
    if (emailHistoryConfig != null) {
        emailHistoryConfig.setStatus(status);
        emailHistoryConfig.setExecutionTime(InsightsUtils.getCurrentTimeInEpochMilliSeconds());
        workflowDAL.updateEmailExecutionHistory(emailHistoryConfig);
    }
}
Also used : InsightsReportVisualizationContainer(com.cognizant.devops.platformdal.assessmentreport.InsightsReportVisualizationContainer)

Example 3 with InsightsReportVisualizationContainer

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

the class ReportEmailSubscriber method updateEmailHistoryWithEmailTemplateValues.

/**
 * Method to update values in Email History table
 *
 * @param incomingTaskMessage
 * @param emailTemplate
 * @return
 */
private MailReport updateEmailHistoryWithEmailTemplateValues(JsonObject incomingTaskMessage, InsightsEmailTemplates emailTemplate) {
    try {
        workflowId = incomingTaskMessage.get(AssessmentReportAndWorkflowConstants.WORKFLOW_ID).getAsString();
        executionId = incomingTaskMessage.get(AssessmentReportAndWorkflowConstants.EXECUTIONID).getAsLong();
        InsightsWorkflowConfiguration workflowConfig = workflowDAL.getWorkflowConfigByWorkflowId(workflowId);
        Map<String, String> valuesMap = new HashMap<>();
        if (workflowConfig.getAssessmentConfig() != null) {
            valuesMap.put("ReportDisplayName", workflowConfig.getAssessmentConfig().getAsseementReportDisplayName());
        }
        valuesMap.put("TimeOfReportGeneration", InsightsUtils.specficTimeFormat(executionId, "yyyy-MM-dd"));
        valuesMap.put("Schedule", workflowConfig.getScheduleType());
        StringSubstitutor sub = new StringSubstitutor(valuesMap, "{", "}");
        InsightsReportVisualizationContainer emailHistoryConfig = workflowDAL.getEmailExecutionHistoryByExecutionId(incomingTaskMessage.get(AssessmentReportAndWorkflowConstants.EXECUTIONID).getAsLong());
        if (emailHistoryConfig != null) {
            emailHistoryConfig.setMailFrom(emailTemplate.getMailFrom());
            emailHistoryConfig.setMailTo(emailTemplate.getMailTo());
            emailHistoryConfig.setMailCC(emailTemplate.getMailCC());
            emailHistoryConfig.setMailBCC(emailTemplate.getMailBCC());
            if (emailHistoryConfig.getMailBody() == null) {
                emailHistoryConfig.setMailBody(sub.replace(emailTemplate.getMailBody()));
            }
            emailHistoryConfig.setSubject(sub.replace(emailTemplate.getSubject()));
            emailHistoryConfig.setStatus(WorkflowTaskEnum.EmailStatus.IN_PROGRESS.toString());
            emailHistoryConfig.setMailId(emailTemplate.getId());
            workflowDAL.updateEmailExecutionHistory(emailHistoryConfig);
            return collectInfoFromDataBase(incomingTaskMessage, emailHistoryConfig);
        } else {
            throw new InsightsJobFailedException("No record found in Email History table");
        }
    } catch (InsightsJobFailedException e) {
        throw new InsightsJobFailedException(e.getMessage());
    } catch (Exception e) {
        log.error("Workflow Detail ==== ReportEmailSubscriber Incorrect email format found ===== ", e);
        throw new InsightsJobFailedException("Error while updating values to Email History ");
    }
}
Also used : InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsReportVisualizationContainer(com.cognizant.devops.platformdal.assessmentreport.InsightsReportVisualizationContainer) HashMap(java.util.HashMap) StringSubstitutor(org.apache.commons.text.StringSubstitutor) InsightsWorkflowConfiguration(com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) AddressException(javax.mail.internet.AddressException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 4 with InsightsReportVisualizationContainer

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

the class SystemNotificationDetailSubscriber method setDetailsInEmailHistory.

/**
 * Method to save Email details in Email History table
 *
 * @param incomingTaskMessageJson
 * @param mailBody
 */
private void setDetailsInEmailHistory(JsonObject incomingTaskMessageJson, String mailBody) {
    try {
        InsightsReportVisualizationContainer emailHistoryConfig = new InsightsReportVisualizationContainer();
        emailHistoryConfig.setExecutionId(incomingTaskMessageJson.get("executionId").getAsLong());
        emailHistoryConfig.setStatus(WorkflowTaskEnum.EmailStatus.NOT_STARTED.name());
        emailHistoryConfig.setWorkflowConfig(incomingTaskMessageJson.get("workflowId").getAsString());
        emailHistoryConfig.setMailBody(mailBody);
        emailHistoryConfig.setMailAttachmentName("");
        workflowDAL.saveEmailExecutionHistory(emailHistoryConfig);
    } catch (Exception e) {
        log.error("Worlflow Detail ==== Error setting Email details in Email History table");
        throw new InsightsJobFailedException("Worlflow Detail ==== Error setting Email details in Email History table");
    }
}
Also used : InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsReportVisualizationContainer(com.cognizant.devops.platformdal.assessmentreport.InsightsReportVisualizationContainer) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) IOException(java.io.IOException)

Example 5 with InsightsReportVisualizationContainer

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

the class PDFExecutionSubscriber method setPDFDetailsInEmailHistory.

private void setPDFDetailsInEmailHistory(JsonObject incomingTaskMessageJson) {
    try {
        long startTime = System.nanoTime();
        String workflowId = incomingTaskMessageJson.get(AssessmentReportAndWorkflowConstants.WORKFLOW_ID).getAsString();
        InsightsReportVisualizationContainer emailHistoryConfig = new InsightsReportVisualizationContainer();
        emailHistoryConfig.setExecutionId(assessmentReportDTO.getExecutionId());
        emailHistoryConfig.setMailAttachmentName(assessmentReportDTO.getAsseementreportname());
        File attachedFile = new File(assessmentReportDTO.getPdfExportedFilePath());
        if (attachedFile.exists()) {
            emailHistoryConfig.setAttachmentData(FileUtils.readFileToByteArray(attachedFile));
        } else {
            throw new InsightsJobFailedException("Worlflow Detail ==== Error setting PDF details in Email History table");
        }
        if (incomingTaskMessageJson.get("nextTaskId").getAsInt() == -1) {
            emailHistoryConfig.setStatus(WorkflowTaskEnum.WorkflowStatus.COMPLETED.name());
            emailHistoryConfig.setExecutionTime(InsightsUtils.getCurrentTimeInEpochMilliSeconds());
        } else {
            emailHistoryConfig.setStatus(WorkflowTaskEnum.EmailStatus.NOT_STARTED.name());
        }
        emailHistoryConfig.setWorkflowConfig(workflowId);
        workflowDAL.saveEmailExecutionHistory(emailHistoryConfig);
        long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", assessmentReportDTO.getExecutionId(), assessmentReportDTO.getWorkflowId(), assessmentReportDTO.getConfigId(), "-", "-", "-", processingTime, "reportId: " + assessmentReportDTO.getReportId() + "reportName: " + assessmentReportDTO.getReportName() + "VisualizationUtil" + assessmentReportDTO.getVisualizationutil());
    } catch (Exception e) {
        log.error("Worlflow Detail ==== Error setting PDF details in Email History table");
        log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", assessmentReportDTO.getExecutionId(), assessmentReportDTO.getWorkflowId(), assessmentReportDTO.getConfigId(), "-", "-", "-", 0, "reportId: " + assessmentReportDTO.getReportId() + "reportName: " + assessmentReportDTO.getReportName() + "VisualizationUtil" + assessmentReportDTO.getVisualizationutil() + "Error setting PDF details in Email History table" + e.getMessage());
        throw new InsightsJobFailedException("Worlflow Detail ==== Error setting PDF details in Email History table");
    }
}
Also used : InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsReportVisualizationContainer(com.cognizant.devops.platformdal.assessmentreport.InsightsReportVisualizationContainer) File(java.io.File) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

InsightsReportVisualizationContainer (com.cognizant.devops.platformdal.assessmentreport.InsightsReportVisualizationContainer)11 InsightsWorkflowConfiguration (com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration)5 InsightsJobFailedException (com.cognizant.devops.platformreports.exception.InsightsJobFailedException)4 IOException (java.io.IOException)3 HashMap (java.util.HashMap)3 SkipException (org.testng.SkipException)3 Test (org.testng.annotations.Test)3 InsightsCustomException (com.cognizant.devops.platformcommons.exception.InsightsCustomException)2 ExecutionException (java.util.concurrent.ExecutionException)2 AgentConfig (com.cognizant.devops.platformdal.agentConfig.AgentConfig)1 InsightsAssessmentReportTemplate (com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate)1 InsightsContentConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig)1 InsightsKPIConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig)1 InsightsReportTemplateConfigFiles (com.cognizant.devops.platformdal.assessmentreport.InsightsReportTemplateConfigFiles)1 AutoMLConfig (com.cognizant.devops.platformdal.autoML.AutoMLConfig)1 CorrelationConfiguration (com.cognizant.devops.platformdal.correlationConfig.CorrelationConfiguration)1 InsightsConfigFiles (com.cognizant.devops.platformdal.filemanagement.InsightsConfigFiles)1 WebHookConfig (com.cognizant.devops.platformdal.webhookConfig.WebHookConfig)1 JsonObject (com.google.gson.JsonObject)1 File (java.io.File)1