Search in sources :

Example 6 with IdmNotificationRecipientFilter

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

the class DefaultRptReportManagerIntegrationTest method testSendConfiguredAdditionalNotificationAfterEnd.

@Test
public void testSendConfiguredAdditionalNotificationAfterEnd() throws Exception {
    IdmIdentityDto identity = getHelper().createIdentity();
    String recipient = getHelper().createName() + "@test-bcvsolutions.eu";
    NotificationConfigurationDto config = createConfig(recipient, 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());
        // 
        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 7 with IdmNotificationRecipientFilter

use of eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter 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 8 with IdmNotificationRecipientFilter

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

the class IdmNotificationRecipientControllerTest method testFindByText.

@Test
public void testFindByText() {
    IdmNotificationRecipientDto recipentOne = createDto();
    // other
    createDto();
    // 
    IdmNotificationRecipientFilter filter = new IdmNotificationRecipientFilter();
    filter.setText(recipentOne.getRealRecipient());
    List<IdmNotificationRecipientDto> attachments = find(filter);
    Assert.assertEquals(1, attachments.size());
    Assert.assertTrue(attachments.stream().anyMatch(r -> r.getId().equals(recipentOne.getId())));
}
Also used : IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) Autowired(org.springframework.beans.factory.annotation.Autowired) Test(org.junit.Test) IdmNotificationRecipientFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest) IdmNotificationLogService(eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationLogService) List(java.util.List) AbstractReadWriteDtoController(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) GuardedString(eu.bcvsolutions.idm.core.security.api.domain.GuardedString) Assert(org.junit.Assert) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) IdmNotificationRecipientFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter) Test(org.junit.Test) AbstractReadWriteDtoControllerRestTest(eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)

Example 9 with IdmNotificationRecipientFilter

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

the class IdmNotificationLogController method getRecipients.

/**
 * FIXME: Add response wrapper => raw list is returned now => all remove method at all => recipient controller should e used.
 */
@ResponseBody
@PreAuthorize("hasAuthority('" + NotificationGroupPermission.NOTIFICATION_READ + "')")
@RequestMapping(value = "/{backendId}/recipients", method = RequestMethod.GET)
@ApiOperation(value = "Notification recipients", nickname = "getNotificationRecipients", tags = { IdmNotificationLogController.TAG }, authorizations = { @Authorization(value = SwaggerConfig.AUTHENTICATION_BASIC, scopes = { @AuthorizationScope(scope = NotificationGroupPermission.NOTIFICATION_READ, description = "") }), @Authorization(value = SwaggerConfig.AUTHENTICATION_CIDMST, scopes = { @AuthorizationScope(scope = NotificationGroupPermission.NOTIFICATION_READ, description = "") }) })
public List<IdmNotificationRecipientDto> getRecipients(@PathVariable @NotNull String backendId) {
    IdmNotificationRecipientFilter filter = new IdmNotificationRecipientFilter();
    filter.setNotification(DtoUtils.toUuid(backendId));
    // 
    return notificationRecipientService.find(filter, null).getContent();
}
Also used : IdmNotificationRecipientFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter) ApiOperation(io.swagger.annotations.ApiOperation) PreAuthorize(org.springframework.security.access.prepost.PreAuthorize) ResponseBody(org.springframework.web.bind.annotation.ResponseBody) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

IdmNotificationRecipientFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationRecipientFilter)9 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)8 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)7 IdmNotificationRecipientDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto)7 Test (org.junit.Test)7 NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)5 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)5 IdmNotificationLogService (eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationLogService)5 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)5 List (java.util.List)5 Assert (org.junit.Assert)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 AbstractReadWriteDtoController (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoController)4 AbstractReadWriteDtoControllerRestTest (eu.bcvsolutions.idm.core.api.rest.AbstractReadWriteDtoControllerRestTest)4 NotificationConfigurationDto (eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto)3 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 IdmFormDefinitionDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDefinitionDto)2 IdmFormDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormDto)2 IdmFormValueDto (eu.bcvsolutions.idm.core.eav.api.dto.IdmFormValueDto)2