Search in sources :

Example 1 with InsightsAssessmentReportTemplate

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

the class WorkflowTestData method saveAssessmentReport.

public String saveAssessmentReport(String workflowid, String mqChannel, String assessmentReport, String mqChannel2) throws InsightsCustomException {
    JsonObject emailDetails = null;
    try {
        int taskId = getTaskId(mqChannel);
        int task2Id = 0;
        if (mqChannel2 != null) {
            task2Id = getTaskId(mqChannel2);
        }
        JsonObject assessmentReportJson = addTask(taskId, assessmentReport, task2Id);
        int reportId = assessmentReportJson.get("reportTemplate").getAsInt();
        InsightsAssessmentReportTemplate reportTemplate = (InsightsAssessmentReportTemplate) reportConfigDAL.getActiveReportTemplateByReportId(reportId);
        String workflowType = WorkflowTaskEnum.WorkflowType.REPORT.getValue();
        String reportName = assessmentReportJson.get("reportName").getAsString();
        boolean isActive = true;
        String schedule = assessmentReportJson.get("schedule").getAsString();
        String emailList = assessmentReportJson.get("emailList").getAsString();
        String datasource = assessmentReportJson.get("datasource").getAsString();
        boolean reoccurence = assessmentReportJson.get("isReoccuring").getAsBoolean();
        // boolean reoccurence =
        // assessmentReportJson.get("isReoccuring").getAsBoolean();
        long epochStartDate = 0;
        long epochEndDate = 0;
        String reportStatus = WorkflowTaskEnum.WorkflowStatus.NOT_STARTED.toString();
        JsonArray taskList = assessmentReportJson.get("tasklist").getAsJsonArray();
        String asseementreportdisplayname = assessmentReportJson.get("asseementreportdisplayname").getAsString();
        if (!assessmentReportJson.get("emailDetails").isJsonNull()) {
            emailDetails = assessmentReportJson.get("emailDetails").getAsJsonObject();
        }
        // workflowId = WorkflowTaskEnum.WorkflowType.REPORT.getValue() + "_"
        // + InsightsUtils.getCurrentTimeInSeconds();
        InsightsAssessmentConfiguration assessmentConfig = new InsightsAssessmentConfiguration();
        InsightsWorkflowConfiguration workflowConfig = saveWorkflowConfig(workflowid, isActive, reoccurence, schedule, reportStatus, workflowType, taskList, epochStartDate, epochEndDate, emailDetails, Boolean.FALSE);
        assessmentConfig.setActive(isActive);
        assessmentConfig.setEmails(emailList);
        assessmentConfig.setInputDatasource(datasource);
        assessmentConfig.setAsseementreportname(reportName);
        assessmentConfig.setStartDate(epochStartDate);
        assessmentConfig.setEndDate(epochEndDate);
        assessmentConfig.setReportTemplateEntity(reportTemplate);
        assessmentConfig.setWorkflowConfig(workflowConfig);
        workflowConfig.setAssessmentConfig(assessmentConfig);
        reportConfigDAL.saveInsightsAssessmentConfig(assessmentConfig);
    } catch (InsightsCustomException e) {
        log.error(e);
    }
    return workflowid;
}
Also used : JsonArray(com.google.gson.JsonArray) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsAssessmentReportTemplate(com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate) InsightsWorkflowConfiguration(com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration) JsonObject(com.google.gson.JsonObject) InsightsAssessmentConfiguration(com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentConfiguration)

Example 2 with InsightsAssessmentReportTemplate

use of com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate 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 3 with InsightsAssessmentReportTemplate

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

the class AssessmentReportServiceTest method testSaveReportTemplate.

@Test(priority = 14)
public void testSaveReportTemplate() throws InsightsCustomException {
    try {
        reportIdForList = assessmentService.saveTemplateReport(reportTemplateJson);
        InsightsAssessmentReportTemplate report = (InsightsAssessmentReportTemplate) reportConfigDAL.getReportTemplateByReportId(reportIdForList);
        assessmentReportDataInit();
        Assert.assertNotNull(report);
        Assert.assertTrue(report.getReportsKPIConfig().size() > 0);
    } catch (AssertionError e) {
        Assert.fail(e.getMessage());
    }
}
Also used : InsightsAssessmentReportTemplate(com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate) Test(org.testng.annotations.Test)

Example 4 with InsightsAssessmentReportTemplate

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

the class AssessmentReportServiceTest method testGrafanaPDFSaveReportTemplate.

@Test(priority = 45)
public void testGrafanaPDFSaveReportTemplate() throws InsightsCustomException {
    try {
        FileInputStream input = new FileInputStream(tableJson);
        MultipartFile multipartConfigFile = new MockMultipartFile("file", tableJson.getName(), "text/plain", IOUtils.toByteArray(input));
        String message = fileManagementService.uploadConfigurationFile(multipartConfigFile, "table", "JSON", "GRAFANA_PDF_TEMPLATE", false);
        assessmentService.saveKpiDefinition(registerGrafanakpiJson);
        assessmentService.saveContentDefinition(registerGrafanaContentJson);
        grafanaReportId = assessmentService.saveTemplateReport(grafanaPDFreportTemplateJson);
        InsightsAssessmentReportTemplate report = (InsightsAssessmentReportTemplate) reportConfigDAL.getReportTemplateByReportId(grafanaReportId);
        assessmentReportDataInit();
        Assert.assertNotNull(report);
        Assert.assertTrue(report.getReportsKPIConfig().size() > 0);
    } catch (AssertionError | IOException e) {
        Assert.fail(e.getMessage());
    }
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) InsightsAssessmentReportTemplate(com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Example 5 with InsightsAssessmentReportTemplate

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

the class ReportTemplateKPIContentServiceTest method testUploadReportTemplate.

@Test(priority = 13)
public void testUploadReportTemplate() throws InsightsCustomException, IOException {
    try {
        FileInputStream input = new FileInputStream(templateJsonFile);
        MultipartFile multipartFile = new MockMultipartFile("file", configFile.getName(), "text/plain", IOUtils.toByteArray(input));
        String response = assessmentService.uploadReportTemplate(multipartFile);
        uploadedTemplateId = Integer.parseInt(response.replaceAll("[^0-9]", ""));
        InsightsAssessmentReportTemplate report = (InsightsAssessmentReportTemplate) reportConfigDAL.getReportTemplateByReportId(uploadedTemplateId);
        Assert.assertNotNull(report);
        Assert.assertTrue(report.getReportsKPIConfig().size() > 0);
    } catch (AssertionError e) {
        Assert.fail(e.getMessage());
    }
}
Also used : MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MockMultipartFile(org.springframework.mock.web.MockMultipartFile) MultipartFile(org.springframework.web.multipart.MultipartFile) InsightsAssessmentReportTemplate(com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate) FileInputStream(java.io.FileInputStream) Test(org.testng.annotations.Test)

Aggregations

InsightsAssessmentReportTemplate (com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate)22 InsightsCustomException (com.cognizant.devops.platformcommons.exception.InsightsCustomException)14 JsonObject (com.google.gson.JsonObject)11 IOException (java.io.IOException)10 JsonArray (com.google.gson.JsonArray)9 Test (org.testng.annotations.Test)8 InsightsWorkflowConfiguration (com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration)5 JsonElement (com.google.gson.JsonElement)5 NoResultException (javax.persistence.NoResultException)5 InsightsKPIConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig)4 FileNotFoundException (java.io.FileNotFoundException)4 InsightsAssessmentConfiguration (com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentConfiguration)3 InsightsReportsKPIConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsReportsKPIConfig)3 LinkedHashSet (java.util.LinkedHashSet)3 MultipartFile (org.springframework.web.multipart.MultipartFile)3 InsightsReportTemplateConfigFiles (com.cognizant.devops.platformdal.assessmentreport.InsightsReportTemplateConfigFiles)2 FileInputStream (java.io.FileInputStream)2 MockMultipartFile (org.springframework.mock.web.MockMultipartFile)2 GetMapping (org.springframework.web.bind.annotation.GetMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2