use of com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig 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.InsightsReportsKPIConfig 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.InsightsReportsKPIConfig in project Insights by CognizantOneDevOps.
the class HyperLedgerExecutionSubscriber method fetchLedgerRecords.
/**
* @param incomingTaskMessageJson
* @param ledgerStartDate
* @param ledgerEndDate
* @return
* @throws InsightsCustomException
* @throws JsonSyntaxException
*/
private List<JsonObject> fetchLedgerRecords(String ledgerStartDate, String ledgerEndDate) throws InsightsCustomException {
String toolName;
String dbQuery;
String assets = null;
List<JsonObject> ledgerList = new ArrayList<>();
Set<InsightsReportsKPIConfig> kpiconfig = workflowConfig.getAssessmentConfig().getReportTemplateEntity().getReportsKPIConfig();
for (InsightsReportsKPIConfig insightsReportsKPIConfig : kpiconfig) {
toolName = insightsReportsKPIConfig.getKpiConfig().getToolname();
dbQuery = insightsReportsKPIConfig.getKpiConfig().getdBQuery();
if (dbQuery.isEmpty()) {
assets = insightsAuditImpl.getAllAssets(ledgerStartDate, ledgerEndDate, toolName);
log.debug("Worlflow Detail ==== result {} ", assets);
JsonElement msgData = JsonUtils.parseString(assets);
JsonArray msgArray = msgData.getAsJsonObject().get("msg").getAsJsonArray();
fetchAssetHistory(msgArray, ledgerList, false);
} else {
getLedgerRecordsByAssetID(dbQuery, ledgerList);
}
}
return ledgerList;
}
use of com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig in project Insights by CognizantOneDevOps.
the class PDFExecutionSubscriber method getKPIVisualizationReportObject.
private void getKPIVisualizationReportObject(Set<InsightsReportsKPIConfig> reportsKPIConfigSet) throws InterruptedException, ExecutionException {
List<JsonObject> failedJobs = new ArrayList<>();
List<Callable<JsonObject>> kpiListToExecute = new ArrayList<>();
JsonArray resultArray = new JsonArray();
for (InsightsReportsKPIConfig reportKpiConfig : reportsKPIConfigSet) {
PDFKPIVisualizationProcesser pdfProcesser = new PDFKPIVisualizationProcesser(reportKpiConfig, assessmentReportDTO);
kpiListToExecute.add(pdfProcesser);
}
/* segregate entire KPI execution list into defined chunks */
List<List<Callable<JsonObject>>> kpiChunkList = WorkflowThreadPool.getChunk(kpiListToExecute, 3);
/* submit each chunk to threadpool in a loop */
executeKpiChunks(kpiChunkList, failedJobs, resultArray);
if (!failedJobs.isEmpty()) {
updateFailedTaskStatusLog(failedJobs, assessmentReportDTO);
}
assessmentReportDTO.setVisualizationResult(resultArray);
}
use of com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig in project Insights by CognizantOneDevOps.
the class AssesmentReportServiceImpl method deleteContentDefinition.
/**
* Used to delete individual Content definition
*
* @param registerkpiJson
* @return
* @throws InsightsCustomException
*/
public boolean deleteContentDefinition(JsonObject deleteContentJson) throws InsightsCustomException {
int contentId = -1;
boolean isRecordDeleted = Boolean.FALSE;
try {
contentId = deleteContentJson.get(AssessmentReportAndWorkflowConstants.CONTENTID).getAsInt();
InsightsContentConfig contentExistingConfig = reportConfigDAL.getContentConfig(contentId);
if (contentExistingConfig == null) {
throw new InsightsCustomException("Content definition not exists");
} else {
List<InsightsReportsKPIConfig> reportKPIList = reportConfigDAL.getActiveReportTemplateByKPIId(contentExistingConfig.getKpiConfig().getId());
if (reportKPIList.isEmpty()) {
reportConfigDAL.deleteContentbyContentID(contentId);
isRecordDeleted = Boolean.TRUE;
} else {
throw new InsightsCustomException("Content definition attached to report template");
}
}
} catch (Exception e) {
log.error(e);
throw new InsightsCustomException(e.getMessage());
}
return isRecordDeleted;
}
Aggregations