use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel in project CzechIdMng by bcvsolutions.
the class MonitoringReportXlsxRenderer method render.
@Override
public InputStream render(RptReportDto report) {
try {
// read json stream
JsonParser jParser = getMapper().getFactory().createParser(getReportData(report));
XSSFWorkbook workbook = new XSSFWorkbook();
CreationHelper createHelper = workbook.getCreationHelper();
XSSFSheet sheet = workbook.createSheet("Report");
sheet.setDefaultColumnWidth(15);
// header
XSSFFont headerFont = workbook.createFont();
headerFont.setBold(true);
headerFont.setFontHeightInPoints((short) 15);
//
Row row = sheet.createRow(2);
row.setHeightInPoints((short) 20);
Cell cell = row.createCell(0);
XSSFRichTextString headerColumn = new XSSFRichTextString();
headerColumn.append("Detail", headerFont);
cell.setCellValue(headerColumn);
cell = row.createCell(1);
headerColumn = new XSSFRichTextString();
headerColumn.append("Level", headerFont);
cell.setCellValue(headerColumn);
cell = row.createCell(2);
headerColumn = new XSSFRichTextString();
headerColumn.append("Result message", headerFont);
cell.setCellValue(headerColumn);
cell = row.createCell(3);
headerColumn = new XSSFRichTextString();
headerColumn.append("Value", headerFont);
cell.setCellValue(headerColumn);
cell = row.createCell(4);
headerColumn = new XSSFRichTextString();
headerColumn.append("Monitoring type", headerFont);
cell.setCellValue(headerColumn);
//
int rowNum = 3;
NotificationLevel summaryLevel = NotificationLevel.SUCCESS;
//
XSSFCellStyle errorStyle = workbook.createCellStyle();
errorStyle.setFillForegroundColor(IndexedColors.RED.getIndex());
errorStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
//
XSSFCellStyle warningStyle = workbook.createCellStyle();
warningStyle.setFillForegroundColor(IndexedColors.LIGHT_ORANGE.getIndex());
warningStyle.setFillPattern(FillPatternType.SOLID_FOREGROUND);
//
XSSFCellStyle defaultStyle = workbook.createCellStyle();
// json is array of identities
if (jParser.nextToken() == JsonToken.START_ARRAY) {
// write single identity
while (jParser.nextToken() == JsonToken.START_OBJECT) {
RptMonitoringResultDto monitoringResult = getMapper().readValue(jParser, RptMonitoringResultDto.class);
String[] monitoringEvaluatorType = StringUtils.split(monitoringResult.getEvaluatorType(), '.');
String frontendUrl = configurationService.getFrontendUrl(String.format("monitoring/monitoring-results/%s", monitoringResult.getId()));
NotificationLevel level = monitoringResult.getLevel();
//
XSSFCellStyle cellStyle = null;
if (level == NotificationLevel.ERROR) {
cellStyle = errorStyle;
} else if (level == NotificationLevel.WARNING) {
cellStyle = warningStyle;
} else {
cellStyle = defaultStyle;
}
//
if (summaryLevel.ordinal() < level.ordinal()) {
summaryLevel = level;
}
//
row = sheet.createRow(rowNum++);
cell = row.createCell(0);
cell.setCellValue(frontendUrl);
Hyperlink link = createHelper.createHyperlink(XSSFHyperlink.LINK_URL);
link.setAddress(frontendUrl);
cell.setHyperlink(link);
cell.setCellValue("Show detail");
cell = row.createCell(1);
cell.setCellStyle(cellStyle);
cell.setCellValue(level.name());
cell = row.createCell(2);
cell.setCellValue(monitoringResult.getResultMessage());
cell = row.createCell(3);
cell.setCellValue(monitoringResult.getValue());
cell = row.createCell(4);
cell.setCellValue(String.format("%s - %s", monitoringEvaluatorType[monitoringEvaluatorType.length - 1], monitoringResult.getEvaluatorDescription()));
}
}
// set auto size column
for (int index = 0; index <= 4; index++) {
sheet.autoSizeColumn(index);
}
//
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0, 4));
row = sheet.createRow(0);
row.setHeightInPoints((short) 20);
cell = row.createCell(0);
headerColumn = new XSSFRichTextString();
if (summaryLevel == NotificationLevel.ERROR) {
headerColumn.append("Status CzechIdM - monitoring contains errors", headerFont);
} else if (summaryLevel == NotificationLevel.WARNING) {
headerColumn.append("Status CzechIdM - monitoring contains warnings", headerFont);
} else {
headerColumn.append("Status CzechIdM - monitoring is ok", headerFont);
}
cell.setCellValue(headerColumn);
//
// close json stream
jParser.close();
// close and return input stream
return getInputStream(workbook);
} catch (IOException ex) {
throw new ReportRenderException(report.getName(), ex);
}
}
use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel in project CzechIdMng by bcvsolutions.
the class IdmNotificationConfigurationDisabledTest method testNotDisabledErrorWebsocket.
@Test
@Transactional
public void testNotDisabledErrorWebsocket() {
assertEquals(0, idmNotificationRepository.count());
NotificationLevel level = NotificationLevel.ERROR;
IdmNotificationTemplateDto template = createTestTemplate("Idm test notification", "disabled test");
IdmIdentityDto identity = getHelper().createIdentity("Test_disable_notifications" + System.currentTimeMillis());
configs.add(createNotificationConfiguration(TOPIC, level, IdmConsoleLog.NOTIFICATION_TYPE, template.getId(), false));
IdmMessageDto message = new IdmMessageDto();
message.setTemplate(template);
message.setLevel(level);
notificationManager.send(TOPIC, message, identity);
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setNotificationType(IdmNotificationLog.class);
assertEquals(1, notificationLogService.find(filter, null).getTotalElements());
deleteNotificationConfig();
}
use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel in project CzechIdMng by bcvsolutions.
the class IdmNotificationConfigurationDisabledTest method testNotDisabled.
@Test
@Transactional
public void testNotDisabled() {
assertEquals(0, idmNotificationRepository.count());
NotificationLevel level = NotificationLevel.ERROR;
IdmNotificationTemplateDto template = createTestTemplate("Idm test notification", "disabled test");
IdmIdentityDto identity = getHelper().createIdentity("Test_disable_notifications" + System.currentTimeMillis());
configs.add(createNotificationConfiguration(TOPIC, null, IdmConsoleLog.NOTIFICATION_TYPE, template.getId(), false));
configs.add(createNotificationConfiguration(TOPIC, null, IdmEmailLog.NOTIFICATION_TYPE, template.getId(), false));
IdmMessageDto message = new IdmMessageDto();
message.setTemplate(template);
message.setLevel(level);
notificationManager.send(TOPIC, message, identity);
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setNotificationType(IdmNotificationLog.class);
assertEquals(2, notificationLogService.find(filter, null).getTotalElements());
deleteNotificationConfig();
}
use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel in project CzechIdMng by bcvsolutions.
the class IdmNotificationConfigurationDisabledTest method testDisabledErrorEmail.
@Test
@Transactional
public void testDisabledErrorEmail() {
assertEquals(0, idmNotificationRepository.count());
NotificationLevel level = NotificationLevel.ERROR;
IdmNotificationTemplateDto template = createTestTemplate("Idm test notification", "disabled test");
IdmIdentityDto identity = getHelper().createIdentity("Test_disable_notifications" + System.currentTimeMillis());
configs.add(createNotificationConfiguration(TOPIC, level, IdmEmailLog.NOTIFICATION_TYPE, template.getId(), true));
IdmMessageDto message = new IdmMessageDto();
message.setTemplate(template);
message.setLevel(level);
notificationManager.send(TOPIC, message, identity);
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setNotificationType(IdmNotificationLog.class);
assertEquals(0, notificationLogService.find(filter, null).getTotalElements());
deleteNotificationConfig();
}
use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel in project CzechIdMng by bcvsolutions.
the class IdmNotificationConfigurationDisabledTest method testOneDisabledError.
@Test
@Transactional
public void testOneDisabledError() {
assertEquals(0, idmNotificationRepository.count());
NotificationLevel level = NotificationLevel.ERROR;
IdmNotificationTemplateDto template = createTestTemplate("Idm test notification", "disabled test");
IdmIdentityDto identity = getHelper().createIdentity("Test_disable_notifications" + System.currentTimeMillis());
configs.add(createNotificationConfiguration(TOPIC, level, IdmConsoleLog.NOTIFICATION_TYPE, template.getId(), false));
configs.add(createNotificationConfiguration(TOPIC, level, IdmEmailLog.NOTIFICATION_TYPE, template.getId(), true));
IdmMessageDto message = new IdmMessageDto();
message.setTemplate(template);
message.setLevel(level);
notificationManager.send(TOPIC, message, identity);
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setNotificationType(IdmNotificationLog.class);
assertEquals(1, notificationLogService.find(filter, null).getTotalElements());
deleteNotificationConfig();
}
Aggregations