use of com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig in project Insights by CognizantOneDevOps.
the class WorkflowTestData method saveKpiDefinition.
public int saveKpiDefinition(String kpiDefinition) {
int kpiId = -1;
try {
JsonObject kpiJson = JsonUtils.parseStringAsJsonObject(kpiDefinition);
InsightsKPIConfig kpiConfig = new InsightsKPIConfig();
kpiId = kpiJson.get("kpiId").getAsInt();
InsightsKPIConfig existingConfig = reportConfigDAL.getKPIConfig(kpiId);
if (existingConfig == null) {
boolean isActive = kpiJson.get("isActive").getAsBoolean();
String kpiName = kpiJson.get("name").getAsString();
String dBQuery = kpiJson.get("DBQuery").getAsString();
String resultField = kpiJson.get("resultField").getAsString();
String group = kpiJson.get("group").getAsString();
String toolName = kpiJson.get("toolName").getAsString();
String dataSource = kpiJson.get("datasource").getAsString();
String category = kpiJson.get("category").getAsString();
String usecase = kpiJson.get("usecase").getAsString();
String outputDatasource = kpiJson.get("outputDatasource").getAsString();
kpiConfig.setKpiId(kpiId);
kpiConfig.setActive(isActive);
kpiConfig.setKpiName(kpiName);
kpiConfig.setdBQuery(dBQuery);
kpiConfig.setResultField(resultField);
kpiConfig.setToolname(toolName);
kpiConfig.setGroupName(group);
kpiConfig.setDatasource(dataSource);
kpiConfig.setCategory(category);
kpiConfig.setOutputDatasource(outputDatasource);
kpiConfig.setUsecase(usecase);
reportConfigDAL.saveKpiConfig(kpiConfig);
}
} catch (Exception e) {
log.error(e);
}
return kpiId;
}
use of com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig in project Insights by CognizantOneDevOps.
the class WorkflowTestData method saveReportTemplate.
public int saveReportTemplate(String reportTemplate) {
int reportId = -1;
try {
JsonObject reportJson = JsonUtils.parseStringAsJsonObject(reportTemplate);
Gson gson = new Gson();
Set<InsightsReportsKPIConfig> reportsKPIConfigSet = new LinkedHashSet<>();
reportId = reportJson.get("reportId").getAsInt();
InsightsAssessmentReportTemplate reportEntity = (InsightsAssessmentReportTemplate) reportConfigDAL.getActiveReportTemplateByReportId(reportId);
if (reportEntity == null) {
String reportName = reportJson.get("reportName").getAsString();
boolean isActive = reportJson.get("isActive").getAsBoolean();
String description = reportJson.get("description").getAsString();
String file = reportJson.get("file").getAsString();
String visualizationutil = reportJson.get("visualizationutil").getAsString();
reportEntity = new InsightsAssessmentReportTemplate();
reportEntity.setReportId(reportId);
reportEntity.setActive(isActive);
reportEntity.setDescription(description);
reportEntity.setTemplateName(reportName);
reportEntity.setFile(file);
reportEntity.setVisualizationutil(visualizationutil);
JsonArray kpiConfigArray = reportJson.get("kpiConfigs").getAsJsonArray();
for (JsonElement eachKpiConfig : kpiConfigArray) {
JsonObject KpiObject = eachKpiConfig.getAsJsonObject();
int kpiId = KpiObject.get("kpiId").getAsInt();
String vConfig = gson.toJson(KpiObject.get("visualizationConfigs").getAsJsonArray());
InsightsKPIConfig kpiConfig = reportConfigDAL.getKPIConfig(kpiId);
if (kpiConfig != null) {
InsightsReportsKPIConfig reportsKPIConfig = new InsightsReportsKPIConfig();
reportsKPIConfig.setKpiConfig(kpiConfig);
reportsKPIConfig.setvConfig(vConfig);
reportsKPIConfig.setReportTemplateEntity(reportEntity);
reportsKPIConfigSet.add(reportsKPIConfig);
}
}
reportEntity.setReportsKPIConfig(reportsKPIConfigSet);
reportConfigDAL.saveReportConfig(reportEntity);
}
} catch (Exception e) {
log.error(e);
}
return reportId;
}
use of com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig in project Insights by CognizantOneDevOps.
the class ReportKPISubscriber method handleTaskExecution.
@Override
public void handleTaskExecution(byte[] body) throws IOException {
try {
long startTime = System.nanoTime();
List<JsonObject> failedJobs = new ArrayList<>();
List<InsightsKPIConfig> kpiConfigList = new ArrayList<>();
List<Integer> contentList = new ArrayList<>();
String message = new String(body, MQMessageConstants.MESSAGE_ENCODING);
log.debug("Worlflow Detail ==== ReportKPISubscriber routing key message handleDelivery ===== {} ", message);
JsonObject incomingTaskMessage = JsonUtils.parseStringAsJsonObject(message);
String workflowId = incomingTaskMessage.get("workflowId").getAsString();
executionId = incomingTaskMessage.get("executionId").getAsLong();
workflowConfig = workflowDAL.getWorkflowConfigByWorkflowId(workflowId);
/* kpi and content list */
boolean isWorkflowTaskRetry = incomingTaskMessage.get(WorkflowUtils.RETRY_JSON_PROPERTY).getAsBoolean();
if (isWorkflowTaskRetry) {
/* fill failed kpis and content for execution */
extractKPIAndContentRetryList(incomingTaskMessage, kpiConfigList, contentList);
/* execute content */
executeContent(contentList, failedJobs);
} else {
Set<InsightsReportsKPIConfig> reportsKPIConfigSet = workflowConfig.getAssessmentConfig().getReportTemplateEntity().getReportsKPIConfig();
reportsKPIConfigSet.forEach(reportKpi -> kpiConfigList.add(reportKpi.getKpiConfig()));
}
/* Execute Kpi */
log.debug("Worlflow Detail ==== ReportKPISubscriber before executeKPI ", kpiConfigList.size());
executeKPI(kpiConfigList, failedJobs);
if (!failedJobs.isEmpty()) {
updateFailedTaskStatusLog(failedJobs);
}
long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
log.debug("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, workflowId, workflowConfig.getAssessmentConfig().getId(), workflowConfig.getWorkflowType(), "-", "-", processingTime, "usecasename: " + "-" + " schedule: " + workflowConfig.getScheduleType());
} catch (InsightsJobFailedException e) {
log.error("Worlflow Detail ==== InsightsJobFailedException ==== ", e);
InsightsStatusProvider.getInstance().createInsightStatusNode("ReportKPI subscriber exception... " + e.getMessage(), PlatformServiceConstants.FAILURE);
log.error("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, "-", "-", "-", "-", "-", 0, "Exception: " + e.getMessage());
throw new InsightsJobFailedException("Some of the Kpi's or Contents failed to execute " + e.getMessage());
} catch (RejectedExecutionException e) {
log.error("Worlflow Detail ==== RejectedExecutionException ==== ", e);
InsightsStatusProvider.getInstance().createInsightStatusNode("ReportKPI subscriber exception " + e.getMessage(), PlatformServiceConstants.FAILURE);
log.error("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, "-", "-", "-", "-", "-", 0, "Exception:RejectedExecutionException " + e.getMessage());
throw new InsightsJobFailedException("some of the Kpi's or Contents failed to execute RejectedExecutionException " + e.getMessage());
} catch (Exception e) {
log.error("Worlflow Detail ==== handleTaskExecution ==== ", e);
InsightsStatusProvider.getInstance().createInsightStatusNode("ReportKPI subscriber exception " + e.getMessage(), PlatformServiceConstants.FAILURE);
log.error("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", executionId, "-", "-", "-", "-", "-", 0, "Exception:ReportKPI subscriber exception" + e.getMessage());
throw new InsightsJobFailedException("some of the Kpi's or Contents failed to execute Exception " + e.getMessage());
}
log.debug("Worlflow Detail ==== ReportKPISubscriber completed ");
InsightsStatusProvider.getInstance().createInsightStatusNode("ReportKPISubscriber completed", PlatformServiceConstants.SUCCESS);
}
use of com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig in project Insights by CognizantOneDevOps.
the class AssesmentReportServiceImpl method getKPIlistOfReportTemplate.
/**
* Fetch all the KPI List of the selected report template.
*
* @param configId
* @return
* @throws InsightsCustomException
*/
public JsonArray getKPIlistOfReportTemplate(String configId) throws InsightsCustomException {
try {
int id = Integer.parseInt(configId);
List<InsightsKPIConfig> listofkpis = reportConfigDAL.getKpiConfigByTemplateReportId(id);
JsonArray jsonarray = new JsonArray();
for (InsightsKPIConfig kpiDetail : listofkpis) {
JsonObject jsonobject = new JsonObject();
jsonobject.addProperty(AssessmentReportAndWorkflowConstants.KPIID, kpiDetail.getKpiId());
jsonobject.addProperty("kpiName", kpiDetail.getKpiName());
jsonarray.add(jsonobject);
}
return jsonarray;
} catch (Exception e) {
log.error("Error while deleting assesment report.", e);
throw new InsightsCustomException(e.toString());
}
}
use of com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig in project Insights by CognizantOneDevOps.
the class AssesmentReportServiceImpl method updateKpiDefinition.
/**
* Used to update individual KPI definition
*
* @param registerkpiJson
* @return
* @throws InsightsCustomException
*/
public int updateKpiDefinition(JsonObject updatekpiJson) throws InsightsCustomException {
int kpiId = -1;
try {
kpiId = updatekpiJson.get(AssessmentReportAndWorkflowConstants.KPIID).getAsInt();
InsightsKPIConfig kpiExistingConfig = reportConfigDAL.getKPIConfig(kpiId);
if (kpiExistingConfig == null) {
throw new InsightsCustomException("While update, KPI definition not exists");
} else {
boolean isActive = updatekpiJson.get(AssessmentReportAndWorkflowConstants.ISACTIVE).getAsBoolean();
String kpiName = updatekpiJson.get("name").getAsString();
String dBQuery = updatekpiJson.get("DBQuery").getAsString();
String resultField = updatekpiJson.get("resultField").getAsString();
String group = updatekpiJson.get("group").getAsString();
String toolName = updatekpiJson.get("toolName").getAsString();
String dataSource = updatekpiJson.get(AssessmentReportAndWorkflowConstants.DATASOURCE).getAsString();
String category = updatekpiJson.get(AssessmentReportAndWorkflowConstants.CATEGORY).getAsString();
String usecase = updatekpiJson.get("usecase").getAsString();
String outputDatasource = updatekpiJson.get(AssessmentReportAndWorkflowConstants.OUTPUTDATASOURCE).getAsString();
dBQuery = dBQuery.replace("#", "<").replace("~", ">");
kpiExistingConfig.setKpiId(kpiId);
kpiExistingConfig.setActive(isActive);
kpiExistingConfig.setKpiName(kpiName);
kpiExistingConfig.setdBQuery(dBQuery);
kpiExistingConfig.setResultField(resultField);
kpiExistingConfig.setToolname(toolName);
kpiExistingConfig.setGroupName(group);
kpiExistingConfig.setDatasource(dataSource);
kpiExistingConfig.setCategory(category);
kpiExistingConfig.setUsecase(usecase);
kpiExistingConfig.setOutputDatasource(outputDatasource);
reportConfigDAL.updateKpiConfig(kpiExistingConfig);
}
} catch (Exception e) {
log.error(e);
throw new InsightsCustomException(e.getMessage());
}
return kpiId;
}
Aggregations