Search in sources :

Example 6 with InsightsContentConfig

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

the class AssessmentReportsTestData method saveContentDefinition.

public int saveContentDefinition(JsonObject contentJson) throws InsightsCustomException {
    InsightsContentConfig contentConfig = new InsightsContentConfig();
    Gson gson = new Gson();
    int kpiId = contentJson.get("kpiId").getAsInt();
    int contentId = contentJson.get("contentId").getAsInt();
    try {
        InsightsContentConfig existingContentConfig = reportConfigDAL.getContentConfig(contentId);
        if (existingContentConfig == null) {
            boolean contentisActive = contentJson.get("isActive").getAsBoolean();
            String contentName = contentJson.get("contentName").getAsString();
            String contentString = gson.toJson(contentJson);
            contentConfig.setContentId(contentId);
            InsightsKPIConfig kpiConfig = reportConfigDAL.getKPIConfig(kpiId);
            String contentCategory = kpiConfig.getCategory();
            contentConfig.setKpiConfig(kpiConfig);
            contentConfig.setActive(contentisActive);
            contentConfig.setContentJson(contentString);
            contentConfig.setContentName(contentName);
            contentConfig.setCategory(contentCategory);
            reportConfigDAL.saveContentConfig(contentConfig);
        }
    } catch (Exception e) {
        log.error(e);
    }
    return contentId;
}
Also used : InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) InsightsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig) Gson(com.google.gson.Gson) IOException(java.io.IOException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Example 7 with InsightsContentConfig

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

the class CommonDALUtils method changeAnnotationValue.

/**
 * This method use for changing annotation value/base data type of some table so that It is compilable with other database
 * @throws NoSuchFieldException
 * @throws SecurityException
 * @throws ClassNotFoundException
 */
public static void changeAnnotationValue() throws NoSuchFieldException, SecurityException, ClassNotFoundException {
    Map<Object, String> classMap = new HashMap<>();
    classMap.put(new InsightsConfigFiles(), "fileData");
    classMap.put(new InsightsReportTemplateConfigFiles(), "fileData");
    classMap.put(new InsightsReportVisualizationContainer(), "attachmentData");
    classMap.put(new AutoMLConfig(), "file");
    classMap.put(new AutoMLConfig(), "mojoDeployedZip");
    for (Map.Entry<Object, String> entry : classMap.entrySet()) {
        Field field = entry.getKey().getClass().getDeclaredField(entry.getValue());
        Annotation annotations = field.getAnnotations()[0];
        Object handler = Proxy.getInvocationHandler(annotations);
        log.debug("Field : {}", field.getName());
        field.setAccessible(true);
        Field f;
        try {
            f = handler.getClass().getDeclaredField("memberValues");
        } catch (NoSuchFieldException | SecurityException e) {
            throw new IllegalStateException(e);
        }
        f.setAccessible(true);
        Map<String, Object> memberValues;
        try {
            memberValues = (Map<String, Object>) f.get(handler);
        } catch (IllegalArgumentException | IllegalAccessException e) {
            throw new IllegalStateException(e);
        }
        Object oldValue = memberValues.get("columnDefinition");
        memberValues.put("columnDefinition", "BLOB");
    }
    Map<Object, String> classBooleanMap = new HashMap<>();
    classBooleanMap.put(new AgentConfig(), "vault");
    classBooleanMap.put(new AgentConfig(), "iswebhook");
    classBooleanMap.put(new CorrelationConfiguration(), "enableCorrelation");
    classBooleanMap.put(new CorrelationConfiguration(), "isSelfRelation");
    classBooleanMap.put(new InsightsAssessmentReportTemplate(), "isActive");
    classBooleanMap.put(new InsightsContentConfig(), "isActive");
    classBooleanMap.put(new InsightsKPIConfig(), "isActive");
    classBooleanMap.put(new AutoMLConfig(), "isActive");
    classBooleanMap.put(new WebHookConfig(), "subscribeStatus");
    classBooleanMap.put(new WebHookConfig(), "isUpdateRequired");
    classBooleanMap.put(new WebHookConfig(), "isEventProcessing");
    classBooleanMap.put(new InsightsWorkflowConfiguration(), "isActive");
    classBooleanMap.put(new InsightsWorkflowConfiguration(), "runImmediate");
    classBooleanMap.put(new InsightsWorkflowConfiguration(), "reoccurence");
    for (Map.Entry<Object, String> entry : classBooleanMap.entrySet()) {
        Field field = entry.getKey().getClass().getDeclaredField(entry.getValue());
        Annotation annotations = field.getAnnotations()[0];
        Object handler = Proxy.getInvocationHandler(annotations);
        log.debug("Field :{} ", field.getName());
        field.setAccessible(true);
        Field f;
        try {
            f = handler.getClass().getDeclaredField("memberValues");
        } catch (NoSuchFieldException | SecurityException e) {
            throw new IllegalStateException(e);
        }
        f.setAccessible(true);
        Map<String, Object> memberValues;
        try {
            memberValues = (Map<String, Object>) f.get(handler);
        } catch (IllegalArgumentException | IllegalAccessException e) {
            throw new IllegalStateException(e);
        }
        Object oldValue = memberValues.get("columnDefinition");
        memberValues.put("columnDefinition", "INT");
    }
}
Also used : InsightsReportVisualizationContainer(com.cognizant.devops.platformdal.assessmentreport.InsightsReportVisualizationContainer) HashMap(java.util.HashMap) InsightsAssessmentReportTemplate(com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate) CorrelationConfiguration(com.cognizant.devops.platformdal.correlationConfig.CorrelationConfiguration) Field(java.lang.reflect.Field) AgentConfig(com.cognizant.devops.platformdal.agentConfig.AgentConfig) InsightsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig) AutoMLConfig(com.cognizant.devops.platformdal.autoML.AutoMLConfig) InsightsConfigFiles(com.cognizant.devops.platformdal.filemanagement.InsightsConfigFiles) InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) WebHookConfig(com.cognizant.devops.platformdal.webhookConfig.WebHookConfig) InsightsReportTemplateConfigFiles(com.cognizant.devops.platformdal.assessmentreport.InsightsReportTemplateConfigFiles) Annotation(java.lang.annotation.Annotation) InsightsWorkflowConfiguration(com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with InsightsContentConfig

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

the class KPIExecutor method call.

@Override
public JsonObject call() throws Exception {
    JsonObject response = new JsonObject();
    JsonArray failedjobs = new JsonArray();
    int kpiId = ReportEngineEnum.StatusCode.ERROR.getValue();
    long startTime = System.nanoTime();
    try {
        kpiId = executeKPIJob(_kpiConfigDTO);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", _kpiConfigDTO.getExecutionId(), _kpiConfigDTO.getWorkflowId(), _kpiConfigDTO.getReportId(), "-", _kpiConfigDTO.getKpiId(), _kpiConfigDTO.getCategory(), 0, "usecasename: " + _kpiConfigDTO.getUsecaseName() + "schedule: " + _kpiConfigDTO.getSchedule());
    } catch (InsightsJobFailedException e) {
        response.addProperty(STATUS, "Failure");
        failedjobs.add(_kpiConfigDTO.getKpiId());
        response.add("kpiArray", failedjobs);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", _kpiConfigDTO.getExecutionId(), _kpiConfigDTO.getWorkflowId(), _kpiConfigDTO.getReportId(), "-", _kpiConfigDTO.getKpiId(), _kpiConfigDTO.getCategory(), 0, "usecasename: " + _kpiConfigDTO.getUsecaseName() + "schedule: " + _kpiConfigDTO.getSchedule());
    }
    if (kpiId != ReportEngineEnum.StatusCode.ERROR.getValue()) {
        ReportConfigDAL reportConfigAL = new ReportConfigDAL();
        List<InsightsContentConfig> contentConfigList = reportConfigAL.getActiveContentConfigByKPIId(_kpiConfigDTO.getKpiId());
        if (!contentConfigList.isEmpty()) {
            /* Execute content on the same thread */
            failedjobs = ContentExecutor.executeContentJob(contentConfigList, _kpiConfigDTO);
        }
        /* If none of the kpi or content is failed then simply return Status as success */
        if (failedjobs.size() > 0) {
            response.addProperty(STATUS, "Failure");
            response.add("contentArray", failedjobs);
        } else {
            response.addProperty(STATUS, "Success");
        }
        long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
        log.debug("Type=TaskExecution  executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", _kpiConfigDTO.getExecutionId(), _kpiConfigDTO.getWorkflowId(), _kpiConfigDTO.getReportId(), "-", _kpiConfigDTO.getKpiId(), _kpiConfigDTO.getCategory(), processingTime, "usecasename: " + _kpiConfigDTO.getUsecaseName() + " schedule: " + _kpiConfigDTO.getSchedule());
    }
    return response;
}
Also used : JsonArray(com.google.gson.JsonArray) InsightsJobFailedException(com.cognizant.devops.platformreports.exception.InsightsJobFailedException) InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) ReportConfigDAL(com.cognizant.devops.platformdal.assessmentreport.ReportConfigDAL) JsonObject(com.google.gson.JsonObject)

Example 9 with InsightsContentConfig

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

the class AssesmentReportServiceImpl method createDashboardJson.

private JsonObject createDashboardJson(JsonObject templateReportJson) throws InsightsCustomException {
    JsonObject dashboardTemplateJson = null;
    try {
        dashboardTemplateJson = fetchTemplateJson("Dashboard.json");
        JsonArray kpiConfigArray = templateReportJson.get(AssessmentReportAndWorkflowConstants.KPICONFIGS).getAsJsonArray();
        JsonArray panelsArray = new JsonArray();
        int panelId = 0;
        for (JsonElement eachKpiConfig : kpiConfigArray) {
            JsonObject kpiObject = eachKpiConfig.getAsJsonObject();
            int kpiId = kpiObject.get(AssessmentReportAndWorkflowConstants.KPIID).getAsInt();
            List<InsightsContentConfig> contentList = reportConfigDAL.getActiveContentConfigByKPIId(kpiId);
            // Add panel for KPI
            panelId = panelId + 1;
            JsonArray vConfigs = kpiObject.get("visualizationConfigs").getAsJsonArray();
            String vtype = vConfigs.get(0).getAsJsonObject().get(AssessmentReportAndWorkflowConstants.VTYPE).getAsString();
            vtype = vtype.substring(0, vtype.lastIndexOf('_'));
            String vQuery = vConfigs.get(0).getAsJsonObject().get(AssessmentReportAndWorkflowConstants.VQUERY).getAsString();
            vQuery = vQuery.replace("{kpiId}", String.valueOf(kpiId));
            InsightsKPIConfig kpiConfig = reportConfigDAL.getKPIConfig(kpiId);
            JsonObject panelTemplateJson = preparePanelJson(vtype, vQuery, kpiConfig.getKpiName(), panelId);
            panelsArray.add(panelTemplateJson);
            // Add panel for content
            panelId = panelId + 1;
            vtype = "content";
            String panelName = "Observation of ".concat(kpiConfig.getKpiName());
            boolean isContentEmpty = contentList.isEmpty();
            JsonObject panelContentTemplateJson = prepareContentPanelJson(vtype, panelName, isContentEmpty, kpiId, panelId);
            panelsArray.add(panelContentTemplateJson);
        }
        dashboardTemplateJson.get("dashboard").getAsJsonObject().add("panels", panelsArray);
        log.debug("dashboard json ==={}", dashboardTemplateJson);
    } catch (Exception e) {
        log.error("Error while preparing dashboard JSON ====", e);
        throw new InsightsCustomException(e.getMessage());
    }
    return dashboardTemplateJson;
}
Also used : JsonArray(com.google.gson.JsonArray) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) JsonElement(com.google.gson.JsonElement) InsightsKPIConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig) JsonObject(com.google.gson.JsonObject) NoResultException(javax.persistence.NoResultException) FileNotFoundException(java.io.FileNotFoundException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) IOException(java.io.IOException)

Example 10 with InsightsContentConfig

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

the class AssessmentReportServiceTest method testsaveContentDefinition.

@Test(priority = 4)
public void testsaveContentDefinition() throws InsightsCustomException, IOException {
    try {
        int response = assessmentService.saveContentDefinition(registerContentJson);
        InsightsContentConfig content = reportConfigDAL.getContentConfig(registerContentJson.get("contentId").getAsInt());
        Assert.assertNotNull(content);
        Assert.assertNotNull(content.getKpiConfig().getKpiId());
        Assert.assertEquals(content.getContentId().intValue(), registerContentJson.get("contentId").getAsInt());
    } catch (AssertionError e) {
        Assert.fail(e.getMessage());
    }
}
Also used : InsightsContentConfig(com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig) Test(org.testng.annotations.Test)

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