use of com.cognizant.devops.platformservice.workflow.service.WorkflowServiceImpl in project Insights by CognizantOneDevOps.
the class UpshiftAssessmentServiceImpl method saveUpshiftAssessment.
@Override
public void saveUpshiftAssessment(String executionId, MultipartFile file) throws InsightsCustomException {
try {
int id = -1;
WorkflowServiceImpl workflowService = new WorkflowServiceImpl();
boolean runImmediate = true;
boolean reoccurence = false;
boolean isActive = true;
String email = "dummy@test.com";
String workflowType = WorkflowTaskEnum.WorkflowType.UPSHIFTASSESSMENT.getValue();
String schedule = WorkflowTaskEnum.WorkflowSchedule.ONETIME.name();
String workflowStatus = WorkflowTaskEnum.UpshiftAssessmentStatus.NOT_STARTED.name();
String workflowId = workflowType + "_" + InsightsUtils.getCurrentTimeInSeconds();
JsonArray taskList = new JsonArray();
JsonArray workflowList = workflowService.getTaskList(workflowType);
workflowList.forEach(task -> taskList.add(workflowService.createTaskJson(task.getAsJsonObject().get(AssessmentReportAndWorkflowConstants.TASK_ID).getAsInt(), task.getAsJsonObject().get("dependency").getAsInt())));
JsonObject emailDetailsJson = getEmailDetails("Insights Upshift assessment", email);
InsightsWorkflowConfiguration workflowConfig = workflowService.saveWorkflowConfig(workflowId, isActive, reoccurence, schedule, workflowStatus, workflowType, taskList, 0, emailDetailsJson, runImmediate);
UpshiftAssessmentConfig upshiftAssessmentConfig = new UpshiftAssessmentConfig();
byte[] fileBytes;
fileBytes = file.getBytes();
String fileString = new String(fileBytes, StandardCharsets.ISO_8859_1);
Map<?, ?> map = new Gson().fromJson(fileString, Map.class);
String upshiftUuid = map.get("upshiftUuid").toString();
UpshiftAssessmentConfig checkDuplicate = upshiftAssessmentConfigDAL.fetchUpshiftAssessmentByUuid(upshiftUuid);
if (checkDuplicate != null) {
log.warn("Received duplicate assessment {}", upshiftUuid);
return;
}
upshiftAssessmentConfig.setFileName(file.getName());
upshiftAssessmentConfig.setFile(fileBytes);
upshiftAssessmentConfig.setEmail(email);
upshiftAssessmentConfig.setUpshiftUuid(upshiftUuid);
upshiftAssessmentConfig.setCreatedDate(InsightsUtils.getCurrentTimeInEpochMilliSeconds());
upshiftAssessmentConfig.setStatus(workflowStatus);
upshiftAssessmentConfig.setWorkflowConfig(workflowConfig);
upshiftAssessmentConfig.setJenkinsExecId(executionId);
id = upshiftAssessmentConfigDAL.saveUpshiftAssessment(upshiftAssessmentConfig);
log.debug(id);
} catch (Exception e) {
throw new InsightsCustomException("Unable to save file");
}
}
use of com.cognizant.devops.platformservice.workflow.service.WorkflowServiceImpl 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.platformservice.workflow.service.WorkflowServiceImpl in project Insights by CognizantOneDevOps.
the class GrafanaPdfServiceImpl method saveGrafanaDashboardConfig.
/**
* Used to store grafana dashboard configuration
*
*@param dasboardDetails
*@return
*@throws InsightsCustomException
*/
@Override
public void saveGrafanaDashboardConfig(JsonObject dashboardDetails) throws InsightsCustomException {
int id = -1;
WorkflowServiceImpl workflowService = new WorkflowServiceImpl();
boolean runImmediate = Boolean.TRUE;
boolean reoccurence = Boolean.FALSE;
boolean isActive = Boolean.TRUE;
try {
String workflowType = WorkflowTaskEnum.WorkflowType.GRAFANADASHBOARDPDFREPORT.getValue();
JsonElement scheduleType = dashboardDetails.get(SCHEDULE_TYPE);
String schedule = scheduleType == null ? WorkflowTaskEnum.WorkflowSchedule.ONETIME.name() : scheduleType.getAsString();
if (!schedule.equals(WorkflowTaskEnum.WorkflowSchedule.ONETIME.name())) {
reoccurence = Boolean.TRUE;
}
String workflowStatus = WorkflowTaskEnum.WorkflowStatus.NOT_STARTED.name();
String workflowId = WorkflowTaskEnum.WorkflowType.GRAFANADASHBOARDPDFREPORT.getValue() + "_" + InsightsUtils.getCurrentTimeInSeconds();
boolean emailEnabled = dashboardDetails.has(EMAIL_DETAILS);
JsonObject emailDetails = null;
JsonObject emailDetailsJson = null;
if (emailEnabled) {
emailDetails = dashboardDetails.get(EMAIL_DETAILS).getAsJsonObject();
emailDetailsJson = getEmailDetails(emailDetails);
}
JsonArray taskList = new JsonArray();
JsonArray workflowList = workflowService.getTaskList(workflowType);
log.debug("Grafana task list from table==={}", workflowList);
for (JsonElement task : workflowList) {
JsonObject taskJson = task.getAsJsonObject();
String componentName = task.getAsJsonObject().get("componentName").getAsString();
if (!(!emailEnabled && componentName.contains("ReportEmailSubscriber"))) {
taskList.add(workflowService.createTaskJson(taskJson.get(AssessmentReportAndWorkflowConstants.TASK_ID).getAsInt(), taskJson.get("dependency").getAsInt()));
}
}
log.debug("Grafana task list====={}", taskList);
InsightsWorkflowConfiguration workflowConfig = workflowService.saveWorkflowConfig(workflowId, isActive, reoccurence, schedule, workflowStatus, WorkflowTaskEnum.WorkflowType.GRAFANADASHBOARDPDFREPORT.getValue(), taskList, 0, emailDetailsJson, runImmediate);
GrafanaDashboardPdfConfig grafanaDashboardConfig = new GrafanaDashboardPdfConfig();
grafanaDashboardConfig.setDashboardJson(dashboardDetails.toString());
grafanaDashboardConfig.setTitle(dashboardDetails.get("title").getAsString());
grafanaDashboardConfig.setPdfType(dashboardDetails.get("pdfType").getAsString());
grafanaDashboardConfig.setVariables(dashboardDetails.get("variables").getAsString());
grafanaDashboardConfig.setWorkflowConfig(workflowConfig);
grafanaDashboardConfig.setSource(dashboardDetails.get("source").getAsString());
grafanaDashboardConfig.setScheduleType(dashboardDetails.get(SCHEDULE_TYPE) == null ? WorkflowTaskEnum.WorkflowSchedule.ONETIME.name() : dashboardDetails.get(SCHEDULE_TYPE).getAsString());
grafanaDashboardConfig.setCreatedDate(InsightsUtils.getCurrentTimeInEpochMilliSeconds());
grafanaUtilities.generateGrafanaToken(dashboardDetails.get(ORGANISATION).getAsInt());
id = grafanaDashboardConfigDAL.saveGrafanaDashboardConfig(grafanaDashboardConfig);
log.debug(id);
} catch (Exception e) {
throw new InsightsCustomException(e.getMessage());
}
}
use of com.cognizant.devops.platformservice.workflow.service.WorkflowServiceImpl in project Insights by CognizantOneDevOps.
the class GrafanaPdfServiceImpl method updateGrafanaDashboardDetails.
/**
* Used to update grafana dashboard config details
*
*@param dashboardDetails
*@return
*@throws InsightsCustomException
*/
@Override
public void updateGrafanaDashboardDetails(JsonObject dashboardDetails) throws InsightsCustomException {
WorkflowServiceImpl workflowService = new WorkflowServiceImpl();
boolean runImmediate = Boolean.TRUE;
boolean reoccurence = Boolean.FALSE;
boolean isActive = Boolean.TRUE;
try {
String workflowType = WorkflowTaskEnum.WorkflowType.GRAFANADASHBOARDPDFREPORT.getValue();
String schedule = dashboardDetails.get(SCHEDULE_TYPE).getAsString();
String workflowStatus = WorkflowTaskEnum.WorkflowStatus.NOT_STARTED.name();
if (!schedule.equals(WorkflowTaskEnum.WorkflowSchedule.ONETIME.name())) {
reoccurence = Boolean.TRUE;
}
GrafanaDashboardPdfConfig grafanaDashboardPdfConfig = grafanaDashboardConfigDAL.getWorkflowById(dashboardDetails.get("id").getAsInt());
InsightsWorkflowConfiguration workflowConfig = grafanaDashboardPdfConfig.getWorkflowConfig();
boolean emailEnabled = dashboardDetails.has(EMAIL_DETAILS);
JsonObject emailDetails = null;
JsonObject emailDetailsJson = null;
if (emailEnabled) {
emailDetails = dashboardDetails.get(EMAIL_DETAILS).getAsJsonObject();
emailDetailsJson = getEmailDetails(emailDetails);
}
JsonArray taskList = new JsonArray();
JsonArray workflowList = workflowService.getTaskList(workflowType);
log.debug("Grafana task list from table===={}", workflowList);
for (JsonElement task : workflowList) {
JsonObject taskJson = task.getAsJsonObject();
String componentName = task.getAsJsonObject().get("componentName").getAsString();
if (!(!emailEnabled && componentName.contains("ReportEmailSubscriber"))) {
taskList.add(workflowService.createTaskJson(taskJson.get(AssessmentReportAndWorkflowConstants.TASK_ID).getAsInt(), taskJson.get("dependency").getAsInt()));
}
}
log.debug("Grafana task list====={}", taskList);
Set<InsightsWorkflowTaskSequence> taskSequenceSet = workflowService.setSequence(taskList, workflowConfig);
workflowConfig.setTaskSequenceEntity(taskSequenceSet);
if (emailEnabled) {
InsightsEmailTemplates emailTemplateConfig = workflowService.createEmailTemplateObject(emailDetailsJson, workflowConfig);
workflowConfig.setEmailConfig(emailTemplateConfig);
}
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(0, schedule, true));
} else {
workflowConfig.setNextRun(InsightsUtils.getNextRunTime(InsightsUtils.getCurrentTimeInSeconds(), schedule, true));
}
workflowConfig.setLastRun(0L);
workflowConfig.setReoccurence(reoccurence);
workflowConfig.setScheduleType(schedule);
workflowConfig.setStatus(workflowStatus);
workflowConfig.setWorkflowType(workflowType);
workflowConfig.setRunImmediate(runImmediate);
grafanaDashboardPdfConfig.setDashboardJson(dashboardDetails.toString());
grafanaDashboardPdfConfig.setTitle(dashboardDetails.get("title").getAsString());
grafanaDashboardPdfConfig.setPdfType(dashboardDetails.get("pdfType").getAsString());
grafanaDashboardPdfConfig.setVariables(dashboardDetails.get("variables").getAsString());
grafanaDashboardPdfConfig.setWorkflowConfig(workflowConfig);
grafanaDashboardPdfConfig.setSource(dashboardDetails.get("source").getAsString());
grafanaDashboardPdfConfig.setScheduleType(schedule);
grafanaDashboardPdfConfig.setCreatedDate(InsightsUtils.getCurrentTimeInEpochMilliSeconds());
grafanaDashboardConfigDAL.updateGrafanaDashboardConfig(grafanaDashboardPdfConfig);
} catch (Exception e) {
throw new InsightsCustomException(e.getMessage());
}
}
Aggregations