Search in sources :

Example 1 with InsightsContentConfig

use of com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig in project Insights by CognizantOneDevOps.

the class ReportKPISubscriber method executeContent.

private void executeContent(List<Integer> contentList, List<JsonObject> failedJobs) throws InterruptedException, ExecutionException {
    List<Callable<Integer>> contentListToExecute = new ArrayList<>();
    ReportPostgresDataHandler contentProcessing = new ReportPostgresDataHandler();
    int assessmentId = workflowConfig.getAssessmentConfig().getId();
    String assessmentReportName = workflowConfig.getAssessmentConfig().getAsseementreportname();
    int reportTemplateId = workflowConfig.getAssessmentConfig().getReportTemplateEntity().getReportId();
    for (int contentId : contentList) {
        InsightsContentConfig contentConfig = contentProcessing.getContentConfig(contentId);
        ContentConfigDefinition contentConfigDefinition = contentProcessing.convertJsonToContentConfig(contentConfig);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", contentConfigDefinition.getExecutionId(), contentConfigDefinition.getWorkflowId(), contentConfigDefinition.getReportId(), "", contentConfigDefinition.getKpiId(), contentConfigDefinition.getCategory(), 0, "ContentId :" + contentConfigDefinition.getContentId() + "ContentName :" + contentConfigDefinition.getContentName() + "action :" + contentConfigDefinition.getAction() + "ContentResult :" + contentConfigDefinition.getNoOfResult());
        if (contentConfigDefinition != null) {
            contentConfigDefinition.setExecutionId(executionId);
            contentConfigDefinition.setSchedule(WorkflowTaskEnum.WorkflowSchedule.valueOf(workflowConfig.getScheduleType()));
            contentConfigDefinition.setWorkflowId(workflowConfig.getWorkflowId());
            contentConfigDefinition.setReportId(reportTemplateId);
            contentConfigDefinition.setAssessmentId(assessmentId);
            contentConfigDefinition.setAssessmentReportName(assessmentReportName);
            contentListToExecute.add(new ContentExecutor(contentConfigDefinition));
        } else {
            log.error("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", contentConfigDefinition.getExecutionId(), contentConfigDefinition.getWorkflowId(), contentConfigDefinition.getReportId(), "-", contentConfigDefinition.getKpiId(), contentConfigDefinition.getCategory(), 0, "ContentId :" + contentConfigDefinition.getContentId() + "ContentName :" + contentConfigDefinition.getContentName() + "action :" + contentConfigDefinition.getAction() + "ContentResult :" + contentConfigDefinition.getNoOfResult() + " Content execution failed");
            throw new InsightsJobFailedException("Content execution failed");
        }
    }
    /* segregate entire content execution list into defined chunks */
    List<List<Callable<Integer>>> contentChunkList = WorkflowThreadPool.getChunk(contentListToExecute, 3);
    /* submit each chunk to threadpool in a loop */
    executeContentChunks(contentChunkList, failedJobs);
}
Also used : ContentExecutor(com.cognizant.devops.platformreports.assessment.content.ContentExecutor) InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) ReportPostgresDataHandler(com.cognizant.devops.platformreports.assessment.dal.ReportPostgresDataHandler) ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) ArrayList(java.util.ArrayList) List(java.util.List) ContentConfigDefinition(com.cognizant.devops.platformreports.assessment.datamodel.ContentConfigDefinition)

Example 2 with InsightsContentConfig

use of com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig in project Insights by CognizantOneDevOps.

the class AssesmentReportServiceImpl method saveContentDefinition.

/**
 * Used to store individual content definition
 *
 * @param registerContentJson
 * @return
 * @throws InsightsCustomException
 */
public int saveContentDefinition(JsonObject registerContentJson) throws InsightsCustomException {
    int contentId = -1;
    Gson gson = new Gson();
    try {
        InsightsContentConfig contentConfig = new InsightsContentConfig();
        int kpiId = registerContentJson.get(AssessmentReportAndWorkflowConstants.KPIID).getAsInt();
        contentId = registerContentJson.get(AssessmentReportAndWorkflowConstants.CONTENTID).getAsInt();
        boolean isActive = registerContentJson.get(AssessmentReportAndWorkflowConstants.ISACTIVE).getAsBoolean();
        String contentName = registerContentJson.get(AssessmentReportAndWorkflowConstants.CONTENT_NAME).getAsString();
        String contentString = gson.toJson(registerContentJson);
        contentConfig.setContentId(contentId);
        InsightsKPIConfig kpiConfig = reportConfigDAL.getKPIConfig(kpiId);
        if (kpiConfig == null) {
            throw new InsightsCustomException("KPI not exists");
        }
        InsightsContentConfig contentDBConfig = reportConfigDAL.getContentConfig(contentId);
        if (contentDBConfig != null) {
            throw new InsightsCustomException("Content Definition already exists");
        }
        String category = kpiConfig.getCategory();
        contentConfig.setKpiConfig(kpiConfig);
        contentConfig.setActive(isActive);
        contentConfig.setContentJson(contentString);
        contentConfig.setContentName(contentName);
        contentConfig.setCategory(category);
        reportConfigDAL.saveContentConfig(contentConfig);
    } catch (Exception e) {
        log.error(e);
        throw new InsightsCustomException(e.getMessage());
    }
    return contentId;
}
Also used : InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) InsightsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig) Gson(com.google.gson.Gson) NoResultException(javax.persistence.NoResultException) FileNotFoundException(java.io.FileNotFoundException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) IOException(java.io.IOException)

Example 3 with InsightsContentConfig

use of com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig in project Insights by CognizantOneDevOps.

the class AssesmentReportServiceImpl method updateContentDefinition.

/**
 * Used to store update content definition
 *
 * @param registerContentJson
 * @return
 * @throws InsightsCustomException
 */
public int updateContentDefinition(JsonObject updateContentJson) throws InsightsCustomException {
    int contentId = -1;
    Gson gson = new Gson();
    try {
        InsightsContentConfig contentConfig = new InsightsContentConfig();
        int kpiId = updateContentJson.get(AssessmentReportAndWorkflowConstants.KPIID).getAsInt();
        contentId = updateContentJson.get(AssessmentReportAndWorkflowConstants.CONTENTID).getAsInt();
        boolean isActive = updateContentJson.get(AssessmentReportAndWorkflowConstants.ISACTIVE).getAsBoolean();
        String contentName = updateContentJson.get(AssessmentReportAndWorkflowConstants.CONTENT_NAME).getAsString();
        String contentString = gson.toJson(updateContentJson);
        contentConfig.setContentId(contentId);
        InsightsKPIConfig kpiConfig = reportConfigDAL.getKPIConfig(kpiId);
        if (kpiConfig == null) {
            throw new InsightsCustomException("KPI defination not exists");
        }
        InsightsContentConfig contentDBConfig = reportConfigDAL.getContentConfig(contentId);
        if (contentDBConfig == null) {
            throw new InsightsCustomException("Content Definition does not  exists");
        } else {
            String category = kpiConfig.getCategory();
            contentDBConfig.setKpiConfig(kpiConfig);
            contentDBConfig.setActive(isActive);
            contentDBConfig.setContentJson(contentString);
            contentDBConfig.setContentName(contentName);
            contentDBConfig.setCategory(category);
            reportConfigDAL.updateContentConfig(contentDBConfig);
        }
    } catch (Exception e) {
        log.error(e);
        throw new InsightsCustomException(e.getMessage());
    }
    return contentId;
}
Also used : InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) InsightsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig) Gson(com.google.gson.Gson) NoResultException(javax.persistence.NoResultException) FileNotFoundException(java.io.FileNotFoundException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) IOException(java.io.IOException)

Example 4 with InsightsContentConfig

use of com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig 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)

Example 5 with InsightsContentConfig

use of com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig in project Insights by CognizantOneDevOps.

the class AssesmentReportServiceImpl method getAllActiveContentList.

/**
 * API use to return all active Content list
 *
 * @return
 * @throws InsightsCustomException
 */
public List<JsonObject> getAllActiveContentList() throws InsightsCustomException {
    List<InsightsContentConfig> kpiconfigList = new ArrayList<>();
    List<JsonObject> contentCustomList = new ArrayList<>();
    try {
        kpiconfigList = reportConfigDAL.getAllActiveContentList();
        kpiconfigList.stream().forEach(contentDBData -> {
            JsonObject contentData = JsonUtils.parseStringAsJsonObject(contentDBData.getContentJson());
            contentData.addProperty("kpiName", contentDBData.getKpiConfig().getKpiName());
            contentData.addProperty("contentId", contentDBData.getContentId());
            contentData.addProperty("contentName", contentDBData.getContentName());
            contentData.addProperty("kpiId", contentDBData.getKpiConfig().getKpiId());
            contentData.addProperty("category", contentDBData.getKpiConfig().getCategory());
            contentCustomList.add(contentData);
        });
        return contentCustomList;
    } catch (Exception e) {
        log.error("Error getting all kpiList...", e);
        throw new InsightsCustomException(e.toString());
    }
}
Also used : InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) ArrayList(java.util.ArrayList) JsonObject(com.google.gson.JsonObject) NoResultException(javax.persistence.NoResultException) FileNotFoundException(java.io.FileNotFoundException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) IOException(java.io.IOException)

Aggregations

InsightsContentConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig)13 InsightsCustomException (com.cognizant.devops.platformcommons.exception.InsightsCustomException)7 InsightsKPIConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig)6 IOException (java.io.IOException)6 FileNotFoundException (java.io.FileNotFoundException)5 NoResultException (javax.persistence.NoResultException)5 Gson (com.google.gson.Gson)4 JsonObject (com.google.gson.JsonObject)4 InsightsJobFailedException (com.cognizant.devops.platformreports.exception.InsightsJobFailedException)3 JsonArray (com.google.gson.JsonArray)3 ReportPostgresDataHandler (com.cognizant.devops.platformreports.assessment.dal.ReportPostgresDataHandler)2 ContentConfigDefinition (com.cognizant.devops.platformreports.assessment.datamodel.ContentConfigDefinition)2 ArrayList (java.util.ArrayList)2 Test (org.testng.annotations.Test)2 AgentConfig (com.cognizant.devops.platformdal.agentConfig.AgentConfig)1 InsightsAssessmentReportTemplate (com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate)1 InsightsReportTemplateConfigFiles (com.cognizant.devops.platformdal.assessmentreport.InsightsReportTemplateConfigFiles)1 InsightsReportVisualizationContainer (com.cognizant.devops.platformdal.assessmentreport.InsightsReportVisualizationContainer)1 InsightsReportsKPIConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig)1 ReportConfigDAL (com.cognizant.devops.platformdal.assessmentreport.ReportConfigDAL)1