Search in sources :

Example 76 with IdmNotificationFilter

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

the class DefaultNotificationServiceIntegrationTest method testSendNotificationToAlias.

@Test
public void testSendNotificationToAlias() {
    final IdmIdentityDto originalRecipient = getHelper().createIdentity((GuardedString) null);
    NotificationConfigurationDto config = new NotificationConfigurationDto();
    config.setTopic(getHelper().createName());
    config.setNotificationType(IdmConsoleLog.NOTIFICATION_TYPE);
    config.setRecipients("one,two,two,two");
    config.setRedirect(false);
    // 
    // we are using repository directly - validations are on the service layer
    config = notificationConfigurationService.save(config);
    // 
    String subject = getHelper().createName();
    List<IdmNotificationLogDto> notifications = notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setLevel(NotificationLevel.SUCCESS).setMessage("message").setSubject(subject).build(), originalRecipient);
    // 
    Assert.assertEquals(2, notifications.size());
    Assert.assertTrue(notifications.stream().anyMatch(n -> {
        return n.getRecipients().size() == 1 && originalRecipient.getId().equals(n.getRecipients().get(0).getIdentityRecipient());
    }));
    Assert.assertTrue(notifications.stream().anyMatch(n -> {
        return n.getRecipients().size() == 2 && n.getRecipients().stream().anyMatch(r -> "one".equals(r.getRealRecipient())) && n.getRecipients().stream().anyMatch(r -> "two".equals(r.getRealRecipient()));
    }));
    // 
    // test by filter
    IdmNotificationFilter filter = new IdmNotificationFilter();
    filter.setText(subject);
    // envelope only
    filter.setNotificationType(IdmNotificationLog.class);
    notifications = notificationLogService.find(filter, null).getContent();
    // 
    Assert.assertEquals(2, notifications.size());
    Assert.assertTrue(notifications.stream().anyMatch(n -> {
        return n.getRecipients().size() == 1 && originalRecipient.getId().equals(n.getRecipients().get(0).getIdentityRecipient());
    }));
    Assert.assertTrue(notifications.stream().anyMatch(n -> {
        return n.getRecipients().size() == 2 && n.getRecipients().stream().anyMatch(r -> "one".equals(r.getRealRecipient())) && n.getRecipients().stream().anyMatch(r -> "two".equals(r.getRealRecipient()));
    }));
    // 
    // target sender
    filter.setNotificationType(IdmConsoleLog.class);
    notifications = notificationLogService.find(filter, null).getContent();
    // 
    Assert.assertEquals(2, notifications.size());
    Assert.assertTrue(notifications.stream().anyMatch(n -> {
        return n.getRecipients().size() == 1 && originalRecipient.getId().equals(n.getRecipients().get(0).getIdentityRecipient());
    }));
    Assert.assertTrue(notifications.stream().anyMatch(n -> {
        return n.getRecipients().size() == 2 && n.getRecipients().stream().allMatch(r -> IdmConsoleLog.NOTIFICATION_TYPE.equals(r.getRealRecipient()));
    }));
}
Also used : Arrays(java.util.Arrays) IdmNotificationRecipientService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationRecipientService) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) NotificationState(eu.bcvsolutions.idm.core.notification.api.domain.NotificationState) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmNotificationConfiguration(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration) IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmNotificationAttachmentFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmEmailLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmEmailLogService) Page(org.springframework.data.domain.Page) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) IdmEmailLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmEmailLogRepository) IdmNotificationTemplateService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationTemplateService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmConsoleLog(eu.bcvsolutions.idm.core.notification.entity.IdmConsoleLog) IdmNotificationLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationLogRepository) IdmNotificationConfigurationRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationConfigurationRepository) IdmNotificationConfigurationService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationConfigurationService) Lists(com.google.common.collect.Lists) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) InitTestDataProcessor(eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) EmailNotificationSender(eu.bcvsolutions.idm.core.notification.api.service.EmailNotificationSender) Before(org.junit.Before) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) IdmNotificationRecipientFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter) IdmNotificationLog(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationLog) IdmNotificationLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationLogService) IdmEmailLog(eu.bcvsolutions.idm.core.notification.entity.IdmEmailLog) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) IdmNotificationAttachmentService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationAttachmentService) Transactional(org.springframework.transaction.annotation.Transactional) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 77 with IdmNotificationFilter

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

the class DefaultNotificationServiceIntegrationTest method testFilterByTopic.

@Test
public void testFilterByTopic() {
    IdmNotificationTemplateDto template = createTestTemplate();
    IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
    NotificationConfigurationDto config = createConfig();
    // 
    notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), identity);
    IdmNotificationFilter filter = new IdmNotificationFilter();
    // Test there is just one filtered log record.
    filter.setTopic(config.getTopic());
    List<IdmNotificationLogDto> notifications = notificationLogService.find(filter, null).getContent();
    // 
    Assert.assertEquals(2, notifications.size());
    Assert.assertTrue(notifications.stream().anyMatch(n -> n.getType().equals(IdmNotificationLog.NOTIFICATION_TYPE)));
    Assert.assertTrue(notifications.stream().anyMatch(n -> n.getType().equals(IdmEmailLog.NOTIFICATION_TYPE)));
    // Test there is none log record after setting the filter to non-existing value.
    filter.setTopic("nonexistingTopic-147258369");
    assertEquals(0, notificationLogService.find(filter, null).getTotalElements());
}
Also used : Arrays(java.util.Arrays) IdmNotificationRecipientService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationRecipientService) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) NotificationState(eu.bcvsolutions.idm.core.notification.api.domain.NotificationState) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmNotificationConfiguration(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration) IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmNotificationAttachmentFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmEmailLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmEmailLogService) Page(org.springframework.data.domain.Page) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) IdmEmailLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmEmailLogRepository) IdmNotificationTemplateService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationTemplateService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmConsoleLog(eu.bcvsolutions.idm.core.notification.entity.IdmConsoleLog) IdmNotificationLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationLogRepository) IdmNotificationConfigurationRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationConfigurationRepository) IdmNotificationConfigurationService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationConfigurationService) Lists(com.google.common.collect.Lists) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) InitTestDataProcessor(eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) EmailNotificationSender(eu.bcvsolutions.idm.core.notification.api.service.EmailNotificationSender) Before(org.junit.Before) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) IdmNotificationRecipientFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter) IdmNotificationLog(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationLog) IdmNotificationLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationLogService) IdmEmailLog(eu.bcvsolutions.idm.core.notification.entity.IdmEmailLog) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) IdmNotificationAttachmentService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationAttachmentService) Transactional(org.springframework.transaction.annotation.Transactional) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) 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) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 78 with IdmNotificationFilter

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

the class DefaultNotificationServiceIntegrationTest method testReferentialIntegrity.

@Test
public void testReferentialIntegrity() {
    // delete recipients and children
    NotificationConfigurationDto config = createConfig();
    IdmNotificationTemplateDto template = createTestTemplate();
    IdmIdentityDto identityOne = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto identityTwo = getHelper().createIdentity((GuardedString) null);
    IdmIdentityDto identitySender = getHelper().createIdentity((GuardedString) null);
    List<IdmNotificationLogDto> notifications = notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), identitySender, Lists.newArrayList(identityOne, identityTwo));
    Assert.assertEquals(1, notifications.size());
    List<IdmNotificationLogDto> notificationOthers = notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setTemplate(template).build(), identitySender, Lists.newArrayList(identityOne, identityTwo));
    Assert.assertEquals(1, notificationOthers.size());
    IdmNotificationLogDto notificationOther = notificationLogService.get(notificationOthers.get(0));
    // 
    IdmNotificationLogDto notification = notificationLogService.get(notifications.get(0));
    Assert.assertNotNull(notification);
    Assert.assertEquals(identitySender.getId(), notification.getIdentitySender());
    IdmNotificationFilter notificationFilter = new IdmNotificationFilter();
    notificationFilter.setParent(notification.getId());
    List<IdmEmailLogDto> emails = emailLogService.find(notificationFilter, null).getContent();
    Assert.assertEquals(1, emails.size());
    IdmEmailLogDto emailNotification = emails.get(0);
    Assert.assertEquals(notification.getId(), emailNotification.getParent());
    // 
    IdmNotificationRecipientFilter recipientFilter = new IdmNotificationRecipientFilter();
    recipientFilter.setNotification(notification.getId());
    List<IdmNotificationRecipientDto> notificationRecipients = recipientService.find(recipientFilter, null).getContent();
    Assert.assertEquals(2, notificationRecipients.size());
    Assert.assertTrue(notificationRecipients.stream().anyMatch(r -> r.getIdentityRecipient().equals(identityOne.getId())));
    Assert.assertTrue(notificationRecipients.stream().anyMatch(r -> r.getIdentityRecipient().equals(identityTwo.getId())));
    recipientFilter.setNotification(emailNotification.getId());
    List<IdmNotificationRecipientDto> emailRecipients = recipientService.find(recipientFilter, null).getContent();
    Assert.assertEquals(2, emailRecipients.size());
    Assert.assertTrue(emailRecipients.stream().anyMatch(r -> r.getIdentityRecipient().equals(identityOne.getId())));
    Assert.assertTrue(emailRecipients.stream().anyMatch(r -> r.getIdentityRecipient().equals(identityTwo.getId())));
    // 
    // sender is removed from notifications when sender identity was deleted
    IdmNotificationFilter senderFilter = new IdmNotificationFilter();
    senderFilter.setIdentitySender(identitySender.getId());
    List<IdmNotificationLogDto> notificationLogDtos = notificationLogService.find(senderFilter, null).getContent();
    Assert.assertFalse(notificationLogDtos.isEmpty());
    notificationLogDtos.forEach(notif -> {
        Assert.assertEquals(identitySender.getId(), notif.getIdentitySender());
    });
    identityService.delete(identitySender);
    Assert.assertNull(identityService.get(identitySender.getId()));
    // shouldn't throw despite the fact that identitySender contained in notificationLogDtos has been deleted
    notificationLogDtos = notificationLogService.find(senderFilter, null).getContent();
    // 
    // create notifications and attachments
    // other owner
    IdmAttachmentDto attachmentOther = attachmentManager.save(DefaultAttachmentManagerIntegrationTest.prepareDto());
    IdmAttachmentDto attachment = DefaultAttachmentManagerIntegrationTest.prepareDto();
    attachment.setOwnerType(null);
    attachment.setInputData(IOUtils.toInputStream("mock content"));
    attachment = attachmentManager.saveAttachment(notification, attachment);
    // 
    IdmNotificationAttachmentDto notificationAttachment = new IdmNotificationAttachmentDto();
    notificationAttachment.setAttachment(attachment.getId());
    notificationAttachment.setName(attachment.getName());
    notificationAttachment.setNotification(notification.getId());
    notificationAttachment = notificationAttachmentService.save(notificationAttachment);
    Assert.assertNotNull(attachmentManager.get(attachment));
    Assert.assertNotNull(notificationAttachmentService.get(notificationAttachment));
    // 
    IdmNotificationAttachmentDto notificationAttachmentOther = new IdmNotificationAttachmentDto();
    notificationAttachmentOther.setAttachment(attachmentOther.getId());
    notificationAttachmentOther.setName(attachmentOther.getName());
    notificationAttachmentOther.setNotification(notificationOther.getId());
    notificationAttachmentOther = notificationAttachmentService.save(notificationAttachmentOther);
    Assert.assertNotNull(attachmentManager.get(attachmentOther));
    Assert.assertNotNull(notificationAttachmentService.get(notificationAttachmentOther));
    // 
    // delete parent notification
    notificationLogService.delete(notification);
    // 
    // all removed
    Assert.assertNull(notificationLogService.get(notification));
    Assert.assertNull(notificationLogService.get(emailNotification));
    recipientFilter.setNotification(notification.getId());
    Assert.assertTrue(recipientService.find(recipientFilter, null).getContent().isEmpty());
    recipientFilter.setNotification(emailNotification.getId());
    Assert.assertTrue(recipientService.find(recipientFilter, null).getContent().isEmpty());
    Assert.assertNull(attachmentManager.get(attachment));
    Assert.assertNotNull(attachmentManager.get(attachmentOther));
    Assert.assertNull(notificationAttachmentService.get(notificationAttachment));
    Assert.assertNotNull(notificationAttachmentService.get(notificationAttachmentOther));
    // 
    notificationLogService.delete(notificationOther);
}
Also used : Arrays(java.util.Arrays) IdmNotificationRecipientService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationRecipientService) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) NotificationState(eu.bcvsolutions.idm.core.notification.api.domain.NotificationState) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmNotificationConfiguration(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration) IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmNotificationAttachmentFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmEmailLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmEmailLogService) Page(org.springframework.data.domain.Page) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) IdmEmailLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmEmailLogRepository) IdmNotificationTemplateService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationTemplateService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmConsoleLog(eu.bcvsolutions.idm.core.notification.entity.IdmConsoleLog) IdmNotificationLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationLogRepository) IdmNotificationConfigurationRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationConfigurationRepository) IdmNotificationConfigurationService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationConfigurationService) Lists(com.google.common.collect.Lists) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) InitTestDataProcessor(eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) EmailNotificationSender(eu.bcvsolutions.idm.core.notification.api.service.EmailNotificationSender) Before(org.junit.Before) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) IdmNotificationRecipientFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter) IdmNotificationLog(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationLog) IdmNotificationLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationLogService) IdmEmailLog(eu.bcvsolutions.idm.core.notification.entity.IdmEmailLog) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) IdmNotificationAttachmentService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationAttachmentService) Transactional(org.springframework.transaction.annotation.Transactional) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IdmNotificationRecipientFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter) IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 79 with IdmNotificationFilter

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

the class DefaultNotificationServiceIntegrationTest method testSendNotificationToAliasWithRedirect.

@Test
public void testSendNotificationToAliasWithRedirect() {
    final IdmIdentityDto originalRecipient = getHelper().createIdentity((GuardedString) null);
    NotificationConfigurationDto config = new NotificationConfigurationDto();
    config.setTopic(getHelper().createName());
    config.setNotificationType(IdmConsoleLog.NOTIFICATION_TYPE);
    config.setRecipients("one,two,two,two");
    config.setRedirect(true);
    // 
    // we are using repository directly - validations are on the service layer
    config = notificationConfigurationService.save(config);
    // 
    String subject = getHelper().createName();
    List<IdmNotificationLogDto> notifications = notificationManager.send(config.getTopic(), new IdmMessageDto.Builder().setLevel(NotificationLevel.SUCCESS).setMessage("message").setSubject(subject).build(), originalRecipient);
    // 
    Assert.assertEquals(1, notifications.size());
    Assert.assertTrue(notifications.stream().anyMatch(n -> {
        return n.getRecipients().size() == 2 && n.getRecipients().stream().anyMatch(r -> "one".equals(r.getRealRecipient())) && n.getRecipients().stream().anyMatch(r -> "two".equals(r.getRealRecipient()));
    }));
    // 
    // test by filter
    IdmNotificationFilter filter = new IdmNotificationFilter();
    filter.setText(subject);
    // envelope only
    filter.setNotificationType(IdmNotificationLog.class);
    notifications = notificationLogService.find(filter, null).getContent();
    // 
    Assert.assertEquals(1, notifications.size());
    Assert.assertTrue(notifications.stream().anyMatch(n -> {
        return n.getRecipients().size() == 2 && n.getRecipients().stream().anyMatch(r -> "one".equals(r.getRealRecipient())) && n.getRecipients().stream().anyMatch(r -> "two".equals(r.getRealRecipient()));
    }));
    // 
    // target sender
    filter.setNotificationType(IdmConsoleLog.class);
    notifications = notificationLogService.find(filter, null).getContent();
    // 
    Assert.assertEquals(1, notifications.size());
    Assert.assertTrue(notifications.stream().anyMatch(n -> {
        return n.getRecipients().size() == 2 && n.getRecipients().stream().anyMatch(r -> IdmConsoleLog.NOTIFICATION_TYPE.equals(r.getRealRecipient()));
    }));
}
Also used : Arrays(java.util.Arrays) IdmNotificationRecipientService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationRecipientService) NotificationManager(eu.bcvsolutions.idm.core.notification.api.service.NotificationManager) ZonedDateTime(java.time.ZonedDateTime) Autowired(org.springframework.beans.factory.annotation.Autowired) NotificationState(eu.bcvsolutions.idm.core.notification.api.domain.NotificationState) ResultCodeException(eu.bcvsolutions.idm.core.api.exception.ResultCodeException) IdmNotificationConfiguration(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationConfiguration) IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmNotificationAttachmentFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationAttachmentFilter) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmEmailLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmEmailLogService) Page(org.springframework.data.domain.Page) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) IdmEmailLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmEmailLogRepository) IdmNotificationTemplateService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationTemplateService) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmNotificationAttachmentDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationAttachmentDto) IdmAttachmentDto(eu.bcvsolutions.idm.core.ecm.api.dto.IdmAttachmentDto) IdmConsoleLog(eu.bcvsolutions.idm.core.notification.entity.IdmConsoleLog) IdmNotificationLogRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationLogRepository) IdmNotificationConfigurationRepository(eu.bcvsolutions.idm.core.notification.repository.IdmNotificationConfigurationRepository) IdmNotificationConfigurationService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationConfigurationService) Lists(com.google.common.collect.Lists) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) InitTestDataProcessor(eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) EmailNotificationSender(eu.bcvsolutions.idm.core.notification.api.service.EmailNotificationSender) Before(org.junit.Before) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) AttachmentManager(eu.bcvsolutions.idm.core.ecm.api.service.AttachmentManager) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Test(org.junit.Test) IdmNotificationRecipientFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter) IdmNotificationLog(eu.bcvsolutions.idm.core.notification.entity.IdmNotificationLog) IdmNotificationLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationLogService) IdmEmailLog(eu.bcvsolutions.idm.core.notification.entity.IdmEmailLog) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) Assert(org.junit.Assert) Assert.assertEquals(org.junit.Assert.assertEquals) IdmNotificationAttachmentService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationAttachmentService) Transactional(org.springframework.transaction.annotation.Transactional) NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 80 with IdmNotificationFilter

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

the class DefaultNotificationServiceIntegrationTest method testParentFilterText.

@Test
public void testParentFilterText() {
    IdmNotificationFilter filter = new IdmNotificationFilter();
    IdmNotificationDto notification = new IdmNotificationDto();
    IdmNotificationDto parentNotification = new IdmNotificationDto();
    // prepare template and message
    IdmNotificationTemplateDto template2 = createTestTemplate();
    IdmMessageDto message2 = new IdmMessageDto.Builder().setTemplate(template2).build();
    // set parent
    parentNotification.setMessage(message2);
    IdmNotificationLogDto logDto = notificationManager.send(parentNotification);
    notification.setParent(logDto.getMessage().getId());
    // 
    // send message
    IdmNotificationTemplateDto template = createTestTemplate();
    IdmMessageDto message = new IdmMessageDto.Builder().setTemplate(template).build();
    notification.setMessage(message);
    notificationManager.send(notification);
    // set filter
    filter.setParent(logDto.getId());
    Page<IdmNotificationLogDto> result = notificationLogService.find(filter, null);
    assertEquals("Wrong sender", logDto.getId(), result.getContent().get(0).getParent());
}
Also used : IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

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