Search in sources :

Example 1 with InsightsReportsKPIConfig

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;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) InsightsReportsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig) InsightsAssessmentReportTemplate(com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate) JsonObject(com.google.gson.JsonObject) Gson(com.google.gson.Gson) AddressException(javax.mail.internet.AddressException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) JsonArray(com.google.gson.JsonArray) JsonElement(com.google.gson.JsonElement) InsightsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig)

Example 2 with InsightsReportsKPIConfig

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);
}
Also used : InsightsReportsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig)

Example 3 with InsightsReportsKPIConfig

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;
}
Also used : JsonArray(com.google.gson.JsonArray) InsightsReportsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig) JsonElement(com.google.gson.JsonElement) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject)

Example 4 with InsightsReportsKPIConfig

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);
}
Also used : JsonArray(com.google.gson.JsonArray) InsightsReportsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig) PDFKPIVisualizationProcesser(com.cognizant.devops.platformreports.assessment.pdf.PDFKPIVisualizationProcesser) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) ArrayList(java.util.ArrayList) List(java.util.List) Callable(java.util.concurrent.Callable)

Example 5 with InsightsReportsKPIConfig

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;
}
Also used : InsightsReportsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) NoResultException(javax.persistence.NoResultException) FileNotFoundException(java.io.FileNotFoundException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) IOException(java.io.IOException)

Aggregations

InsightsReportsKPIConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig)12 JsonObject (com.google.gson.JsonObject)9 InsightsCustomException (com.cognizant.devops.platformcommons.exception.InsightsCustomException)7 JsonArray (com.google.gson.JsonArray)7 ArrayList (java.util.ArrayList)7 InsightsKPIConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig)6 IOException (java.io.IOException)6 JsonElement (com.google.gson.JsonElement)5 NoResultException (javax.persistence.NoResultException)5 FileNotFoundException (java.io.FileNotFoundException)4 LinkedHashSet (java.util.LinkedHashSet)4 InsightsAssessmentReportTemplate (com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate)3 InsightsContentConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig)1 InsightsWorkflowConfiguration (com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration)1 PDFKPIVisualizationProcesser (com.cognizant.devops.platformreports.assessment.pdf.PDFKPIVisualizationProcesser)1 InsightsJobFailedException (com.cognizant.devops.platformreports.exception.InsightsJobFailedException)1 Gson (com.google.gson.Gson)1 List (java.util.List)1 Callable (java.util.concurrent.Callable)1 ExecutionException (java.util.concurrent.ExecutionException)1