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;
}
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");
}
}
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;
}
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;
}
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());
}
}
Aggregations