use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.
the class FusionChartHandler method modifyHtmlTemplate.
private void modifyHtmlTemplate(InsightsAssessmentConfigurationDTO assessmentReportDTO) {
String templateHtmlPath = assessmentReportDTO.getPdfReportDirPath() + File.separator + assessmentReportDTO.getReportFilePath() + AssessmentReportAndWorkflowConstants.HTMLEXTENSION;
log.debug("Worlflow Detail ==== templateHtmlPath {} ", templateHtmlPath);
try {
long startTime = System.nanoTime();
File render = new File(templateHtmlPath);
Document document = Jsoup.parse(render, "UTF-8");
String originalHTml = document.toString();
processHtmlContent(assessmentReportDTO, document);
String modifiedHtml = document.toString();
if (!originalHTml.equalsIgnoreCase(modifiedHtml)) {
try (PrintWriter printWriter = new PrintWriter(new FileWriter(templateHtmlPath))) {
printWriter.print(modifiedHtml);
}
}
long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
log.debug("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", assessmentReportDTO.getExecutionId(), assessmentReportDTO.getWorkflowId(), assessmentReportDTO.getConfigId(), "-", "-", "-", processingTime, "reportId: " + assessmentReportDTO.getReportId() + "reportName: " + assessmentReportDTO.getReportName());
} catch (FileNotFoundException e) {
log.error("Worlflow Detail ==== Unable to update html template , report template html file not found", e);
throw new InsightsJobFailedException("Unable to update html template, report template html file not found " + assessmentReportDTO.getReportFilePath() + AssessmentReportAndWorkflowConstants.HTMLEXTENSION);
} catch (Exception e) {
log.error("Worlflow Detail ==== unable to modify html and content data ", e);
throw new InsightsJobFailedException("unable to modify html and content data " + e);
}
}
use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.
the class FusionChartHandler method exportPDFFile.
private void exportPDFFile(JsonArray finalTemplateJson, InsightsAssessmentConfigurationDTO assessmentReportDTO, InsightsReportPdfTableConfig insightsReportPdfTableConfig) {
Path zipPathVeriable = null;
try {
long startTime = System.nanoTime();
String url = ApplicationConfigProvider.getInstance().getAssessmentReport().getFusionExportAPIUrl();
String zipPath = assessmentReportDTO.getPdfReportDirPath() + ".zip";
Path sourceFolderPath = Paths.get(assessmentReportDTO.getPdfReportDirPath());
zipPathVeriable = Paths.get(zipPath);
Path zipData = getPDFZipFolder(sourceFolderPath, zipPathVeriable);
if (zipData.toFile().exists()) {
log.debug("Worlflow Detail ==== Zip file created {} ", zipPath);
} else {
throw new InsightsCustomException("Worlflow Detail ==== Zip file not created ");
}
String exportedFilePath = assessmentReportDTO.getPdfReportDirPath() + File.separator + assessmentReportDTO.getAsseementreportname() + "." + ReportEngineUtils.REPORT_TYPE;
assessmentReportDTO.setPdfExportedFilePath(exportedFilePath);
String fusionFilePath = assessmentReportDTO.getPdfReportDirPath() + File.separator + assessmentReportDTO.getAsseementreportname() + "_Fusion." + ReportEngineUtils.REPORT_TYPE;
String templateFilePathInZip = assessmentReportDTO.getReportFilePath() + AssessmentReportAndWorkflowConstants.HTMLEXTENSION;
String dashboardLogoPathInzip = "image.webp";
Map<String, String> multipartFiles = new HashMap<>();
multipartFiles.put("payload", zipPath);
String chartConfigJson = new Gson().toJson(finalTemplateJson);
Map<String, String> formDataMultiPartMap = new HashMap<>();
formDataMultiPartMap.put("chartConfig", chartConfigJson);
formDataMultiPartMap.put("templateFilePath", templateFilePathInZip);
formDataMultiPartMap.put("dashboardLogo", dashboardLogoPathInzip);
formDataMultiPartMap.put("dashboardHeading", assessmentReportDTO.getAsseementreportdisplayname());
formDataMultiPartMap.put("type", ReportEngineUtils.REPORT_TYPE);
formDataMultiPartMap.put("templateFormat", "A3");
formDataMultiPartMap.put("footerEnabled", "true");
formDataMultiPartMap.put("footerComponents", "{\"pageNumber\":{\"style\":\"margin-left:105px;\",\"format\": \"{{current}}\"},\"date\":{\"style\":\"float:right;margin-right:105px;\"}}");
Map<String, String> headers = new HashMap<>();
boolean fileUploadStatus = multiPartHandler.uploadMultipartFile(url, multipartFiles, formDataMultiPartMap, headers, ReportEngineUtils.REPORT_MEDIA_TYPE, fusionFilePath);
if (fileUploadStatus) {
log.debug("Worlflow Detail ==== pdf File Saved {} ", fusionFilePath);
long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
log.debug("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", assessmentReportDTO.getExecutionId(), assessmentReportDTO.getWorkflowId(), assessmentReportDTO.getConfigId(), "-", "-", "-", processingTime, "reportId: " + assessmentReportDTO.getReportId() + "reportName: " + assessmentReportDTO.getReportName() + "VisualizationUtil" + assessmentReportDTO.getVisualizationutil() + "FusionFilePath :" + fusionFilePath);
String fusion = assessmentReportDTO.getPdfReportDirPath() + File.separator + assessmentReportDTO.getAsseementreportname() + "_Fusion." + ReportEngineUtils.REPORT_TYPE;
String open = assessmentReportDTO.getPdfReportDirPath() + File.separator + assessmentReportDTO.getAsseementreportname() + "_Open." + ReportEngineUtils.REPORT_TYPE;
File openFile = new File(open);
if (openFile.exists()) {
PDDocument fusionPages = PDDocument.load(new File(fusion));
PDDocument openPages = PDDocument.load(new File(open));
PDDocument f = new PdfReportTableUtil().footer(assessmentReportDTO, openPages, fusionPages.getPages().getCount(), insightsReportPdfTableConfig);
f.save(new File(open));
PDFMergerUtility merger = new PDFMergerUtility();
merger.setDestinationFileName(exportedFilePath);
merger.addSource(new File(fusion));
merger.addSource(open);
merger.mergeDocuments(null);
} else {
PDFMergerUtility merger = new PDFMergerUtility();
merger.setDestinationFileName(exportedFilePath);
merger.addSource(new File(fusion));
merger.mergeDocuments(null);
}
} else {
log.error("Worlflow Detail ==== Error while created pdf file {}", exportedFilePath);
log.error("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", assessmentReportDTO.getExecutionId(), assessmentReportDTO.getWorkflowId(), assessmentReportDTO.getConfigId(), "-", "-", "-", 0, "reportId: " + assessmentReportDTO.getReportId() + "reportName: " + assessmentReportDTO.getReportName() + "VisualizationUtil" + assessmentReportDTO.getVisualizationutil() + "FusionFilePath :" + fusionFilePath + "Error while created pdf file");
throw new InsightsJobFailedException("Unable to generate pdf, Please check pdf export server connectivity ");
}
} catch (Exception e) {
log.error("Worlflow Detail ==== Error while created pdf ", e);
throw new InsightsJobFailedException(e.getMessage());
} finally {
try {
if (zipPathVeriable != null) {
Files.delete(zipPathVeriable);
}
} catch (Exception e) {
log.error(" Worlflow Detail ==== unable to delete file, It might not created ");
}
}
}
use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.
the class UpshiftAssessmentRelationExecutionSubscriber method handleTaskExecution.
@Override
public void handleTaskExecution(byte[] body) throws IOException {
UpshiftAssessmentConfig upshiftAssessmentConfig = null;
try {
long startTime = System.nanoTime();
String incomingTaskMessage = new String(body, StandardCharsets.UTF_8);
log.debug("Worlflow Detail ==== UpshiftAssessmentExecutionSubscriber started ... " + "routing key message handleDelivery ===== {} ", incomingTaskMessage);
JsonObject incomingTaskMessageJson = JsonUtils.parseStringAsJsonObject(incomingTaskMessage);
String workflowId = incomingTaskMessageJson.get("workflowId").getAsString();
workflowConfig = workflowDAL.getWorkflowConfigByWorkflowId(workflowId);
log.debug("Worlflow Detail ==== scheduleType {} ", workflowConfig.getScheduleType());
upshiftAssessmentConfig = upshiftAssessmentConfigDAL.fetchUpshiftAssessmentDetailsByWorkflowId(workflowId);
createRelationship(upshiftAssessmentConfig.getUpshiftUuid());
log.debug("Total nodes related: {}", numOfNodesRelated);
updateReportStatus(upshiftAssessmentConfig, WorkflowTaskEnum.UpshiftAssessmentStatus.COMPLETED.name());
long processingTime = TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime);
log.debug("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", "-", workflowConfig.getWorkflowId(), upshiftAssessmentConfig.getId(), workflowConfig.getWorkflowType(), "-", "-", processingTime, "UpshiftUuid :" + upshiftAssessmentConfig.getUpshiftUuid() + "CreatedDate :" + upshiftAssessmentConfig.getCreatedDate() + "UpdatedDate :" + upshiftAssessmentConfig.getUpdatedDate() + "fileName :" + upshiftAssessmentConfig.getFileName() + "status :" + upshiftAssessmentConfig.getStatus() + " UpshiftAssessmentExecutionSubscriber");
} catch (Exception e) {
log.error("Worlflow Detail ==== GrafanaPDFExecutionSubscriber Completed with error ", e);
updateReportStatus(upshiftAssessmentConfig, WorkflowTaskEnum.UpshiftAssessmentStatus.ERROR.name());
log.error("Type=TaskExecution executionId={} workflowId={} ConfigId={} WorkflowType={} KpiId={} Category={} ProcessingTime={} message={}", "-", workflowConfig.getWorkflowId(), upshiftAssessmentConfig.getId(), workflowConfig.getWorkflowType(), "-", "-", 0, "UpshiftUuid :" + upshiftAssessmentConfig.getUpshiftUuid() + "CreatedDate :" + upshiftAssessmentConfig.getCreatedDate() + "UpdatedDate :" + upshiftAssessmentConfig.getUpdatedDate() + "fileName :" + upshiftAssessmentConfig.getFileName() + "status :" + upshiftAssessmentConfig.getStatus() + " UpshiftAssessmentExecutionSubscriber" + e.getMessage());
throw new InsightsJobFailedException(e.getMessage());
}
}
use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.
the class UpshiftAssessmentHandler method createObjectNode.
/**
* If data type is jsonobject, create node and process the child elements
* @param parentId
* @param name
* @param uuid
* @param input
*/
private void createObjectNode(String uuid, String parentId, String name, JsonObject input) {
try {
String primKey = String.valueOf(System.currentTimeMillis());
List<JsonObject> dataList = new ArrayList<>();
JsonObject nodeProperties = new JsonObject();
nodeProperties.addProperty("insightsTime", primKey);
nodeProperties.addProperty("insightsParentKey", parentId);
nodeProperties.addProperty("insightsVSMReporttype", name);
nodeProperties.addProperty("toolName", "UPSHIFT");
nodeProperties.addProperty("upshiftUuid", uuid);
nodeProperties.addProperty("categoryName", "INSIGHTSUPSHIFT");
dataList.add(nodeProperties);
if (createNode(name, dataList)) {
flag = Boolean.FALSE;
}
for (Map.Entry<?, ?> entry : input.entrySet()) {
JsonElement element = JsonUtils.parseString(gson.toJson(entry.getValue()));
if (element.isJsonPrimitive() && updateNode(primKey, entry.getKey().toString(), element.getAsString())) {
flag = Boolean.FALSE;
} else if (element.isJsonObject()) {
createObjectNode(uuid, primKey, entry.getKey().toString(), element.getAsJsonObject());
} else if (element.isJsonArray()) {
parseJsonArray(uuid, primKey, entry.getKey().toString(), element.getAsJsonArray());
}
}
} catch (InsightsCustomException e) {
log.error(e.getStackTrace());
throw new InsightsJobFailedException(e.getMessage());
}
}
use of com.cognizant.devops.platformreports.exception.InsightsJobFailedException in project Insights by CognizantOneDevOps.
the class ReportGraphDataHandler method saveData.
@Override
public void saveData(List<JsonObject> resultList) {
try {
String query = "UNWIND $props AS properties " + "CREATE (n:" + ReportEngineUtils.NEO4J_RESULT_LABEL + ") " + "SET n = properties";
JsonObject graphResponse = graphDBHandler.bulkCreateNodes(resultList, null, query);
parseGraphResponseForError(graphResponse);
} catch (InsightsCustomException e) {
log.error("Error while saving neo4j record {} ", e.getMessage());
throw new InsightsJobFailedException("Error while saving neo4j record " + e.getMessage());
} catch (Exception e) {
log.error("Error while saving neo4j record {} ", e.getMessage());
throw new InsightsJobFailedException("Error while saving neo4j record " + e.getMessage());
}
}
Aggregations