Search in sources :

Example 1 with InsightsReportTemplateConfigFiles

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

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

the class FusionChartHandler method setReportExecutionFolder.

public void setReportExecutionFolder(InsightsAssessmentConfigurationDTO assessmentReportDTO) throws IOException {
    List<InsightsReportTemplateConfigFiles> records = reportConfigDAL.getReportTemplateConfigFileByReportId(assessmentReportDTO.getReportId());
    for (InsightsReportTemplateConfigFiles record : records) {
        String filePath = assessmentReportDTO.getPdfReportDirPath() + File.separator + record.getFileName();
        File file = new File(filePath);
        if (!file.exists()) {
            FileUtils.writeByteArrayToFile(file, record.getFileData());
        }
    }
}
Also used : InsightsReportTemplateConfigFiles(com.cognizant.devops.platformdal.assessmentreport.InsightsReportTemplateConfigFiles) File(java.io.File)

Example 3 with InsightsReportTemplateConfigFiles

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

the class AssesmentReportServiceImpl method uploadReportTemplateFile.

/**
 * Method to upload Report Template file
 *
 * @param reportId
 * @param reportEntity
 * @param fileType
 * @param file
 * @throws IOException
 */
private void uploadReportTemplateFile(int reportId, InsightsAssessmentReportTemplate reportEntity, String fileType, String filename, byte[] file) {
    InsightsReportTemplateConfigFiles templateFile = reportConfigDAL.getReportTemplateConfigFileByFileNameAndReportId(filename, reportEntity.getReportId());
    if (templateFile == null) {
        InsightsReportTemplateConfigFiles record = new InsightsReportTemplateConfigFiles();
        record.setFileName(filename);
        record.setFileData(file);
        record.setFileType(fileType);
        record.setReportId(reportId);
        reportConfigDAL.saveReportTemplateConfigFiles(record);
    } else {
        templateFile.setFileData(file);
        reportConfigDAL.updateReportTemplateConfigFiles(templateFile);
    }
}
Also used : InsightsReportTemplateConfigFiles(com.cognizant.devops.platformdal.assessmentreport.InsightsReportTemplateConfigFiles)

Example 4 with InsightsReportTemplateConfigFiles

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

the class AssesmentReportServiceImpl method saveDashbaordInGrafana.

private String saveDashbaordInGrafana(String userName, String reportName, InsightsAssessmentReportTemplate reportTemplate) throws InsightsCustomException {
    String responseorg = null;
    try {
        List<InsightsReportTemplateConfigFiles> records = reportConfigDAL.getReportTemplateConfigFileByReportId(reportTemplate.getReportId());
        JsonObject requestOrg = new JsonObject();
        for (InsightsReportTemplateConfigFiles insightsReportTemplateConfigFiles : records) {
            if (insightsReportTemplateConfigFiles.getFileName().equalsIgnoreCase(AssessmentReportAndWorkflowConstants.DASHBOARDTEMPLATEJSON)) {
                String dashboardJson = new String(insightsReportTemplateConfigFiles.getFileData());
                requestOrg = JsonUtils.parseStringAsJsonObject(dashboardJson);
            }
        }
        requestOrg.get(AssessmentReportAndWorkflowConstants.DASHBOARD).getAsJsonObject().addProperty(AssessmentReportAndWorkflowConstants.TITLE, reportName);
        JsonArray panelArray = requestOrg.get("dashboard").getAsJsonObject().get("panels").getAsJsonArray();
        for (JsonElement jsonElement : panelArray) {
            String vQuery = jsonElement.getAsJsonObject().getAsJsonArray(AssessmentReportAndWorkflowConstants.TARGETS).get(0).getAsJsonObject().get(AssessmentReportAndWorkflowConstants.QUERYTEXT).getAsString();
            vQuery = vQuery.replace("{assessmentReportName}", "'" + reportName + "'");
            jsonElement.getAsJsonObject().getAsJsonArray(AssessmentReportAndWorkflowConstants.TARGETS).get(0).getAsJsonObject().addProperty(AssessmentReportAndWorkflowConstants.QUERYTEXT, vQuery);
        }
        log.debug(" requestOrg {} ", requestOrg);
        responseorg = grafanaUtilities.createOrgAndSaveDashboardInGrafana(requestOrg, userName);
        log.debug(" responseorg {} ", responseorg);
    } catch (Exception e) {
        log.error("Error while saving dashboard in Grafana.", e);
        throw new InsightsCustomException(e.getMessage());
    }
    return responseorg;
}
Also used : JsonArray(com.google.gson.JsonArray) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) JsonElement(com.google.gson.JsonElement) JsonObject(com.google.gson.JsonObject) InsightsReportTemplateConfigFiles(com.cognizant.devops.platformdal.assessmentreport.InsightsReportTemplateConfigFiles) NoResultException(javax.persistence.NoResultException) FileNotFoundException(java.io.FileNotFoundException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) IOException(java.io.IOException)

Example 5 with InsightsReportTemplateConfigFiles

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

the class AssessmentReportsTestData method uploadReportTemplateDesignFiles.

public String uploadReportTemplateDesignFiles(int reportId) throws InsightsCustomException {
    String returnMessage = "";
    try {
        InsightsAssessmentReportTemplate reportEntity = (InsightsAssessmentReportTemplate) reportConfigDAL.getReportTemplateByReportId(reportId);
        if (reportEntity == null) {
            throw new InsightsCustomException(" Report template not exists in database " + reportId);
        } else {
            for (String eachFile : templateDesignFilesArray) {
                String fileType = FilenameUtils.getExtension(eachFile).toUpperCase();
                File file = new File(classLoader.getResource("Report_SONAR_JENKINS_PROD/" + eachFile).getFile());
                InsightsReportTemplateConfigFiles templateFile = reportConfigDAL.getReportTemplateConfigFileByFileNameAndReportId(file.getName(), reportId);
                if (templateFile == null) {
                    InsightsReportTemplateConfigFiles record = new InsightsReportTemplateConfigFiles();
                    record.setFileName(file.getName());
                    record.setFileData(FileUtils.readFileToByteArray(file));
                    record.setFileType(fileType);
                    record.setReportId(reportId);
                    reportConfigDAL.saveReportTemplateConfigFiles(record);
                } else {
                    templateFile.setFileData(FileUtils.readFileToByteArray(file));
                    reportConfigDAL.updateReportTemplateConfigFiles(templateFile);
                }
            }
            returnMessage = "File uploaded";
        }
    } catch (Exception ex) {
        log.error("Error in Report Template files upload {} ", ex.getMessage());
        throw new InsightsCustomException(ex.getMessage());
    }
    return returnMessage;
}
Also used : InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException) InsightsAssessmentReportTemplate(com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate) File(java.io.File) InsightsReportTemplateConfigFiles(com.cognizant.devops.platformdal.assessmentreport.InsightsReportTemplateConfigFiles) IOException(java.io.IOException) InsightsCustomException(com.cognizant.devops.platformcommons.exception.InsightsCustomException)

Aggregations

InsightsReportTemplateConfigFiles (com.cognizant.devops.platformdal.assessmentreport.InsightsReportTemplateConfigFiles)5 InsightsCustomException (com.cognizant.devops.platformcommons.exception.InsightsCustomException)2 InsightsAssessmentReportTemplate (com.cognizant.devops.platformdal.assessmentreport.InsightsAssessmentReportTemplate)2 File (java.io.File)2 IOException (java.io.IOException)2 AgentConfig (com.cognizant.devops.platformdal.agentConfig.AgentConfig)1 InsightsContentConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsContentConfig)1 InsightsKPIConfig (com.cognizant.devops.platformdal.assessmentreport.InsightsKPIConfig)1 InsightsReportVisualizationContainer (com.cognizant.devops.platformdal.assessmentreport.InsightsReportVisualizationContainer)1 AutoMLConfig (com.cognizant.devops.platformdal.autoML.AutoMLConfig)1 CorrelationConfiguration (com.cognizant.devops.platformdal.correlationConfig.CorrelationConfiguration)1 InsightsConfigFiles (com.cognizant.devops.platformdal.filemanagement.InsightsConfigFiles)1 WebHookConfig (com.cognizant.devops.platformdal.webhookConfig.WebHookConfig)1 InsightsWorkflowConfiguration (com.cognizant.devops.platformdal.workflow.InsightsWorkflowConfiguration)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonObject (com.google.gson.JsonObject)1 FileNotFoundException (java.io.FileNotFoundException)1 Annotation (java.lang.annotation.Annotation)1 Field (java.lang.reflect.Field)1