Search in sources :

Example 46 with IdmNotificationFilter

use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.

the class DeleteNotificationTaskExecutorIntegrationTest method testDeleteOldSentNotifications.

@Test
public void testDeleteOldSentNotifications() {
    // prepare provisioning operations
    ZonedDateTime createdOne = ZonedDateTime.now().minusDays(2);
    String subject = UUID.randomUUID().toString();
    IdmNotificationLogDto operationOne = createDto(subject, createdOne, NotificationState.ALL);
    // all other variants for not removal
    createDto(subject, LocalDate.now().atStartOfDay(ZoneId.systemDefault()).plusMinutes(1), NotificationState.ALL);
    createDto(subject, LocalDate.now().atStartOfDay(ZoneId.systemDefault()).plusMinutes(1), NotificationState.NOT);
    createDto(subject, LocalDate.now().atStartOfDay(ZoneId.systemDefault()).plusMinutes(1), NotificationState.ALL);
    createDto(subject, ZonedDateTime.now().minusDays(2), NotificationState.PARTLY);
    createDto(subject, LocalDate.now().atStartOfDay(ZoneId.systemDefault()).minusHours(22), NotificationState.ALL);
    // 
    Assert.assertEquals(createdOne, operationOne.getCreated());
    IdmNotificationFilter filter = new IdmNotificationFilter();
    filter.setText(subject);
    List<IdmNotificationLogDto> notifications = service.find(filter, null).getContent();
    Assert.assertEquals(6, notifications.size());
    // 
    DeleteNotificationTaskExecutor taskExecutor = new DeleteNotificationTaskExecutor();
    Map<String, Object> properties = new HashMap<>();
    properties.put(DeleteNotificationTaskExecutor.PARAMETER_NUMBER_OF_DAYS, 1);
    properties.put(DeleteNotificationTaskExecutor.PARAMETER_SENT_ONLY, true);
    AutowireHelper.autowire(taskExecutor);
    taskExecutor.init(properties);
    // 
    longRunningTaskManager.execute(taskExecutor);
    // 
    notifications = service.find(filter, null).getContent();
    Assert.assertEquals(5, notifications.size());
    Assert.assertTrue(notifications.stream().allMatch(a -> !a.getId().equals(operationOne.getId())));
}
Also used : IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) LongRunningTaskManager(eu.bcvsolutions.idm.core.scheduler.api.service.LongRunningTaskManager) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) HashMap(java.util.HashMap) Test(org.junit.Test) UUID(java.util.UUID) ZoneId(java.time.ZoneId) NotificationState(eu.bcvsolutions.idm.core.notification.api.domain.NotificationState) IdmNotificationLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationLogService) AutowireHelper(eu.bcvsolutions.idm.core.api.utils.AutowireHelper) List(java.util.List) LocalDate(java.time.LocalDate) Map(java.util.Map) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) Assert(org.junit.Assert) ZonedDateTime(java.time.ZonedDateTime) HashMap(java.util.HashMap) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) Test(org.junit.Test) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)

Example 47 with IdmNotificationFilter

use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.

the class DefaultRptReportManagerIntegrationTest method testSendConfiguredNotificationAfterEnd.

@Test
public void testSendConfiguredNotificationAfterEnd() throws Exception {
    IdmIdentityDto identity = getHelper().createIdentity();
    NotificationConfigurationDto config = createConfig(null, false);
    // 
    try {
        // report is sent to logged identity by default
        getHelper().login(identity);
        // 
        RptReportDto report = new RptReportDto();
        report.setExecutorName(TestReportExecutor.REPORT_NAME);
        IdmFormDto filter = new IdmFormDto();
        TestReportExecutor testReportExecutor = context.getAutowireCapableBeanFactory().createBean(TestReportExecutor.class);
        IdmFormDefinitionDto definition = testReportExecutor.getFormDefinition();
        IdmFormValueDto topic = new IdmFormValueDto(definition.getMappedAttributeByCode(AbstractReportExecutor.PROPERTY_TOPIC_REPORT_GENERATE_SUCCESS));
        topic.setValue(config.getTopic());
        filter.getValues().add(topic);
        filter.setFormDefinition(definition.getId());
        report.setFilter(filter);
        report = manager.generate(report);
        UUID reportId = report.getId();
        Assert.assertNotNull(reportId);
        Assert.assertNotNull(report.getData());
        // 
        try (InputStream is = attachmentManager.getAttachmentData(report.getData())) {
            Assert.assertEquals(mapper.writeValueAsString(TestReportExecutor.identities), IOUtils.toString(is));
        }
        reportService.delete(report);
        attachmentManager.deleteAttachments(report);
        // 
        // test notification is sent
        IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
        notificationFilter.setTopic(config.getTopic());
        notificationFilter.setRecipient(identity.getUsername());
        notificationFilter.setNotificationType(IdmNotificationLog.class);
        List<IdmNotificationLogDto> notifications = notificationService.find(notificationFilter, null).getContent();
        Assert.assertEquals(1, notifications.size());
    } finally {
        logout();
    }
}
Also used : NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) InputStream(java.io.InputStream) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 48 with IdmNotificationFilter

use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.

the class DefaultRptReportManagerIntegrationTest method testNotSendDefaultNotificationWithoutLoggedIdentityAfterEnd.

@Test
public void testNotSendDefaultNotificationWithoutLoggedIdentityAfterEnd() throws Exception {
    NotificationConfigurationDto config = createConfig(null, false);
    // 
    RptReportDto report = new RptReportDto();
    report.setExecutorName(TestReportExecutor.REPORT_NAME);
    IdmFormDto filter = new IdmFormDto();
    TestReportExecutor testReportExecutor = context.getAutowireCapableBeanFactory().createBean(TestReportExecutor.class);
    IdmFormDefinitionDto definition = testReportExecutor.getFormDefinition();
    IdmFormValueDto topic = new IdmFormValueDto(definition.getMappedAttributeByCode(AbstractReportExecutor.PROPERTY_TOPIC_REPORT_GENERATE_SUCCESS));
    topic.setValue(config.getTopic());
    filter.getValues().add(topic);
    filter.setFormDefinition(definition.getId());
    report.setFilter(filter);
    report = manager.generate(report);
    UUID reportId = report.getId();
    Assert.assertNotNull(reportId);
    Assert.assertNotNull(report.getData());
    // 
    try (InputStream is = attachmentManager.getAttachmentData(report.getData())) {
        Assert.assertEquals(mapper.writeValueAsString(TestReportExecutor.identities), IOUtils.toString(is));
    }
    reportService.delete(report);
    attachmentManager.deleteAttachments(report);
    // 
    // test notification is sent
    IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
    notificationFilter.setTopic(config.getTopic());
    notificationFilter.setNotificationType(IdmNotificationLog.class);
    List<IdmNotificationLogDto> notifications = notificationService.find(notificationFilter, null).getContent();
    Assert.assertEquals(1, notifications.size());
    Assert.assertEquals(NotificationState.NOT, notifications.get(0).getState());
}
Also used : NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) InputStream(java.io.InputStream) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) UUID(java.util.UUID) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 49 with IdmNotificationFilter

use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.

the class DefaultRptReportManagerIntegrationTest method testSendConfiguredRedirectNotificationAfterEnd.

@Test
public void testSendConfiguredRedirectNotificationAfterEnd() throws Exception {
    IdmIdentityDto identity = getHelper().createIdentity();
    String recipient = getHelper().createName() + "@test-bcvsolutions.eu";
    NotificationConfigurationDto config = createConfig(recipient, true);
    // 
    try {
        // report is sent to logged identity by default
        getHelper().login(identity);
        // 
        RptReportDto report = new RptReportDto();
        report.setExecutorName(TestReportExecutor.REPORT_NAME);
        IdmFormDto filter = new IdmFormDto();
        TestReportExecutor testReportExecutor = context.getAutowireCapableBeanFactory().createBean(TestReportExecutor.class);
        IdmFormDefinitionDto definition = testReportExecutor.getFormDefinition();
        IdmFormValueDto topic = new IdmFormValueDto(definition.getMappedAttributeByCode(AbstractReportExecutor.PROPERTY_TOPIC_REPORT_GENERATE_SUCCESS));
        topic.setValue(config.getTopic());
        filter.getValues().add(topic);
        filter.setFormDefinition(definition.getId());
        report.setFilter(filter);
        report = manager.generate(report);
        UUID reportId = report.getId();
        Assert.assertNotNull(reportId);
        Assert.assertNotNull(report.getData());
        // 
        try (InputStream is = attachmentManager.getAttachmentData(report.getData())) {
            Assert.assertEquals(mapper.writeValueAsString(TestReportExecutor.identities), IOUtils.toString(is));
        }
        reportService.delete(report);
        attachmentManager.deleteAttachments(report);
        // 
        // test notification is sent
        IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
        notificationFilter.setTopic(config.getTopic());
        notificationFilter.setRecipient(identity.getUsername());
        notificationFilter.setNotificationType(IdmNotificationLog.class);
        List<IdmNotificationLogDto> notifications = notificationService.find(notificationFilter, null).getContent();
        Assert.assertTrue(notifications.isEmpty());
        // 
        IdmNotificationRecipientFilter recipientFilter = new IdmNotificationRecipientFilter();
        recipientFilter.setRealRecipient(recipient);
        List<IdmNotificationRecipientDto> recipients = notificationRecipientService.find(recipientFilter, null).getContent();
        Assert.assertFalse(recipients.isEmpty());
        Assert.assertEquals(config.getTopic(), notificationService.get(recipients.get(0).getNotification()).getTopic());
    } finally {
        logout();
    }
}
Also used : NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) InputStream(java.io.InputStream) IdmFormDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto) IdmFormDefinitionDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) RptReportDto(eu.bcvsolutions.idm.rpt.api.dto.RptReportDto) IdmNotificationRecipientFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmFormValueDto(eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) UUID(java.util.UUID) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 50 with IdmNotificationFilter

use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter in project CzechIdMng by bcvsolutions.

the class DefaultNotificationServiceIntegrationTest method testEmailFilterBySent.

@Test
@Transactional
public void testEmailFilterBySent() {
    IdmIdentityDto identity = identityService.getByUsername(InitTestData.TEST_USER_1);
    IdmNotificationFilter filter = new IdmNotificationFilter();
    // 
    // create templates
    IdmNotificationTemplateDto template = createTestTemplate("Idm notification", "subject");
    // 
    emailService.send(new IdmMessageDto.Builder().setTemplate(template).build(), identity);
    filter.setSent(true);
    assertEquals(0, emailLogService.find(filter, null).getTotalElements());
    emailService.send(new IdmMessageDto.Builder().setTemplate(template).build(), identity);
    filter.setSent(false);
    assertEquals(2, emailLogService.find(filter, null).getTotalElements());
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)100 Test (org.junit.Test)97 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)89 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)80 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)65 List (java.util.List)37 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)34 IdmRoleDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleDto)33 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)31 ZonedDateTime (java.time.ZonedDateTime)31 AbstractCoreWorkflowIntegrationTest (eu.bcvsolutions.idm.core.AbstractCoreWorkflowIntegrationTest)29 IdmIdentityContractDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityContractDto)26 IdmRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmRoleRequestDto)26 WorkflowFilterDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowFilterDto)26 WorkflowTaskInstanceDto (eu.bcvsolutions.idm.core.workflow.model.dto.WorkflowTaskInstanceDto)26 IdmConceptRoleRequestDto (eu.bcvsolutions.idm.core.api.dto.IdmConceptRoleRequestDto)25 SysSystemDto (eu.bcvsolutions.idm.acc.dto.SysSystemDto)23 UUID (java.util.UUID)17 Transactional (org.springframework.transaction.annotation.Transactional)16 NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)14