use of eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto in project CzechIdMng by bcvsolutions.
the class NotificationRestTest method createTestNotification.
IdmNotificationDto createTestNotification(NotificationLevel level, String subject, String message, String topic, IdmIdentityDto sender, IdmIdentityDto... recipients) {
final IdmMessageDto msg = new IdmMessageDto();
msg.setHtmlMessage(message);
msg.setTextMessage(message);
msg.setLevel(level);
msg.setSubject(subject);
//
final List<IdmNotificationRecipientDto> rec = Arrays.stream(recipients).map(r -> {
final IdmNotificationRecipientDto res = new IdmNotificationRecipientDto();
res.setIdentityRecipient(r.getId());
res.setRealRecipient(r.getUsername());
return res;
}).collect(Collectors.toList());
//
final IdmNotificationDto result = new IdmNotificationDto();
result.setIdentitySender(sender.getId());
result.setRecipients(rec);
result.setTopic(topic);
result.setMessage(msg);
return result;
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto in project CzechIdMng by bcvsolutions.
the class ProvisioningBreakProcessor method sendMessage.
/**
* Send message with information about disabled system or warning
*
* @param topic
* @param system
* @param actualCount
* @param template
* @param breakConfigId
*/
private void sendMessage(String topic, SysSystemDto system, Integer actualCount, IdmNotificationTemplateDto template, SysProvisioningBreakConfigDto breakConfig, ProvisioningEventType operationType, Long duration) {
// Transform mills to sec and min for apache velocity
String minTime = "0";
String secTime = "0";
if (duration != null) {
minTime = String.format("%d", TimeUnit.MILLISECONDS.toMinutes(duration));
//
secTime = String.format("%d", TimeUnit.MILLISECONDS.toSeconds(duration) - TimeUnit.MINUTES.toSeconds(TimeUnit.MILLISECONDS.toMinutes(duration)));
}
//
List<IdmIdentityDto> recipients = null;
if (breakConfig.getGlobalConfiguration() == null || breakConfig.getGlobalConfiguration().equals(Boolean.FALSE)) {
recipients = breakRecipientService.getAllRecipients(breakConfig.getId());
} else {
recipients = breakRecipientService.getAllRecipientsForGlobalConfiguration(operationType);
}
IdmMessageDto message = new IdmMessageDto.Builder().setTemplate(template).addParameter("systemName", system.getName()).addParameter("operationName", operationType.name()).addParameter("actualCount", actualCount).addParameter("minTime", minTime).addParameter("secTime", secTime).build();
// send different notification level for warning and disable
if (topic.equals((AccModuleDescriptor.TOPIC_PROVISIONING_BREAK_WARNING))) {
message.setLevel(NotificationLevel.WARNING);
} else {
message.setLevel(NotificationLevel.ERROR);
}
//
notificationManager.send(topic, message, recipients);
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method parentFilterText.
@Test
public void parentFilterText() {
IdmNotificationFilter filter = new IdmNotificationFilter();
IdmNotificationDto notification = new IdmNotificationDto();
IdmNotificationDto parentNotification = new IdmNotificationDto();
// prepare template and message
IdmNotificationTemplateDto template2 = createTestTemplate("TestTemplate5", "testSubject5");
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("TestTemplate4", "testSubject4");
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());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method senderFilterTest.
@Test
public void senderFilterTest() {
IdmIdentityDto sender = helper.createIdentity();
IdmNotificationFilter filter = new IdmNotificationFilter();
IdmNotificationDto notification = new IdmNotificationDto();
notification.setIdentitySender(sender.getId());
//
// create templates
IdmNotificationTemplateDto template = createTestTemplate("TestTemplate3", "testSubject3");
IdmMessageDto message = new IdmMessageDto.Builder().setTemplate(template).build();
notification.setMessage(message);
notificationManager.send(notification);
//
// filter text BODY
filter.setSender(sender.getUsername());
Page<IdmNotificationLogDto> result = notificationLogService.find(filter, null);
assertEquals("Wrong sender", sender.getId(), result.getContent().get(0).getIdentitySender());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto in project CzechIdMng by bcvsolutions.
the class DefaultNotificationServiceIntegrationTest method stateFilterTest.
@Test
@Ignore
public void stateFilterTest() {
IdmIdentityDto identity1 = helper.createIdentity();
IdmIdentityDto identity2 = helper.createIdentity();
IdmIdentityDto identity3 = helper.createIdentity();
IdmIdentityDto identity4 = helper.createIdentity();
List<IdmIdentityDto> identities = Arrays.asList(identity1, identity2, identity3, identity4);
IdmNotificationTemplateDto template = createTestTemplate("TestTemplate6", "testSubject6");
IdmMessageDto message = new IdmMessageDto.Builder().setTemplate(template).build();
notificationManager.send(message, identities);
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setState(NotificationState.ALL);
Page<IdmNotificationLogDto> result = notificationLogService.find(filter, null);
assertEquals("Wrong state ALL", 1, result.getTotalElements());
filter.setState(NotificationState.NOT);
Page<IdmNotificationLogDto> result2 = notificationLogService.find(filter, null);
assertEquals("Wrong state NOT", 1, result2.getTotalElements());
filter.setState(NotificationState.PARTLY);
result = notificationLogService.find(filter, null);
assertEquals("Wrong state PARTLY", 0, result.getTotalElements());
}
Aggregations