Search in sources :

Example 6 with NotificationLevel

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);
    }
}
Also used : CreationHelper(org.apache.poi.ss.usermodel.CreationHelper) RptMonitoringResultDto(eu.bcvsolutions.idm.rpt.dto.RptMonitoringResultDto) ReportRenderException(eu.bcvsolutions.idm.rpt.api.exception.ReportRenderException) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) IOException(java.io.IOException) XSSFRichTextString(org.apache.poi.xssf.usermodel.XSSFRichTextString) XSSFSheet(org.apache.poi.xssf.usermodel.XSSFSheet) XSSFCellStyle(org.apache.poi.xssf.usermodel.XSSFCellStyle) XSSFFont(org.apache.poi.xssf.usermodel.XSSFFont) XSSFWorkbook(org.apache.poi.xssf.usermodel.XSSFWorkbook) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) Row(org.apache.poi.ss.usermodel.Row) CellRangeAddress(org.apache.poi.ss.util.CellRangeAddress) Cell(org.apache.poi.ss.usermodel.Cell) JsonParser(com.fasterxml.jackson.core.JsonParser) XSSFHyperlink(org.apache.poi.xssf.usermodel.XSSFHyperlink) Hyperlink(org.apache.poi.ss.usermodel.Hyperlink)

Example 7 with NotificationLevel

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();
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 8 with NotificationLevel

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();
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 9 with NotificationLevel

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();
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 10 with NotificationLevel

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();
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)16 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)10 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)10 Test (org.junit.Test)10 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)9 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)9 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)9 Transactional (org.springframework.transaction.annotation.Transactional)9 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 JsonParser (com.fasterxml.jackson.core.JsonParser)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 Lists (com.google.common.collect.Lists)1 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)1 ConfigurationMap (eu.bcvsolutions.idm.core.api.domain.ConfigurationMap)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1 BaseDtoController (eu.bcvsolutions.idm.core.api.rest.BaseDtoController)1 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)1 InitTestDataProcessor (eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor)1