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;
}
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;
}
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());
}
}
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());
}
}
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;
}
Aggregations