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();
}
}
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);
}
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())));
}
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();
}
Aggregations