use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel in project CzechIdMng by bcvsolutions.
the class IdmNotificationConfigurationDisabledTest method testNotDisabledError.
@Test
@Transactional
public void testNotDisabledError() {
assertEquals(0, idmNotificationRepository.count());
NotificationLevel level = NotificationLevel.ERROR;
IdmNotificationTemplateDto template = createTestTemplate("Idm test notification", "disabled test");
IdmIdentityDto identity = getHelper().createIdentity("Test_disable_notifications" + System.currentTimeMillis());
configs.add(createNotificationConfiguration(TOPIC, level, IdmConsoleLog.NOTIFICATION_TYPE, template.getId(), false));
configs.add(createNotificationConfiguration(TOPIC, level, IdmEmailLog.NOTIFICATION_TYPE, template.getId(), false));
IdmMessageDto message = new IdmMessageDto();
message.setTemplate(template);
message.setLevel(level);
notificationManager.send(TOPIC, message, identity);
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setNotificationType(IdmNotificationLog.class);
assertEquals(2, notificationLogService.find(filter, null).getTotalElements());
deleteNotificationConfig();
}
use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel in project CzechIdMng by bcvsolutions.
the class IdmNotificationConfigurationDisabledTest method testDisabledErrorWebsocket.
@Test
@Transactional
public void testDisabledErrorWebsocket() {
assertEquals(0, idmNotificationRepository.count());
NotificationLevel level = NotificationLevel.ERROR;
IdmNotificationTemplateDto template = createTestTemplate("Idm test notification", "disabled test");
IdmIdentityDto identity = getHelper().createIdentity("Test_disable_notifications" + System.currentTimeMillis());
configs.add(createNotificationConfiguration(TOPIC, level, IdmConsoleLog.NOTIFICATION_TYPE, template.getId(), true));
IdmMessageDto message = new IdmMessageDto();
message.setTemplate(template);
message.setLevel(level);
notificationManager.send(TOPIC, message, identity);
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setNotificationType(IdmNotificationLog.class);
assertEquals(0, notificationLogService.find(filter, null).getTotalElements());
deleteNotificationConfig();
}
use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel in project CzechIdMng by bcvsolutions.
the class IdmNotificationConfigurationDisabledTest method testNotDisabledErrorEmail.
@Test
@Transactional
public void testNotDisabledErrorEmail() {
assertEquals(0, idmNotificationRepository.count());
NotificationLevel level = NotificationLevel.ERROR;
IdmNotificationTemplateDto template = createTestTemplate("Idm test notification", "disabled test");
IdmIdentityDto identity = getHelper().createIdentity("Test_disable_notifications" + System.currentTimeMillis());
configs.add(createNotificationConfiguration(TOPIC, level, IdmEmailLog.NOTIFICATION_TYPE, template.getId(), false));
IdmMessageDto message = new IdmMessageDto();
message.setTemplate(template);
message.setLevel(level);
notificationManager.send(TOPIC, message, identity);
IdmNotificationFilter filter = new IdmNotificationFilter();
filter.setNotificationType(IdmNotificationLog.class);
assertEquals(1, notificationLogService.find(filter, null).getTotalElements());
deleteNotificationConfig();
}
use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel in project CzechIdMng by bcvsolutions.
the class DefaultMonitoringManager method getLastResults.
@Override
public Page<IdmMonitoringResultDto> getLastResults(IdmMonitoringResultFilter filter, Pageable pageable, BasePermission... permission) {
// all instances => last results should be visible on each instance
IdmMonitoringFilter monitoringFilter = new IdmMonitoringFilter();
if (filter != null) {
monitoringFilter.setId(filter.getMonitoring());
}
monitoringFilter.setDisabled(Boolean.FALSE);
//
List<IdmMonitoringDto> monitorings = monitoringService.find(monitoringFilter, PageRequest.of(0, Integer.MAX_VALUE, Sort.by(IdmMonitoring_.seq.getName())), PermissionUtils.isEmpty(permission) ? null : IdmBasePermission.AUTOCOMPLETE).getContent();
//
// last results sorted by monitoring order
List<IdmMonitoringResultDto> results = new ArrayList<>(monitorings.size());
for (IdmMonitoringDto monitoring : monitorings) {
MonitoringEvaluator evaluator = getEvaluator(monitoring);
if (evaluator == null) {
LOG.debug("Monitoring evaluator for motitoring configuration [{}] not exists.", monitoring.getId());
continue;
}
IdmMonitoringResultDto lastResult = getLastResult(monitoring.getId(), permission);
if (lastResult == null) {
continue;
}
// filter by level
NotificationLevel lastResultLevel = lastResult.getLevel();
List<NotificationLevel> levels = filter == null ? null : filter.getLevels();
if (CollectionUtils.isNotEmpty(levels) && !levels.contains(lastResultLevel)) {
continue;
}
lastResult.setTrimmed(true);
results.add(lastResult);
}
//
// pageable is required internally
Pageable internalPageable;
if (pageable == null) {
internalPageable = PageRequest.of(0, Integer.MAX_VALUE);
} else {
internalPageable = pageable;
}
//
// Sort by level desc
results.sort((r1, r2) -> {
return ObjectUtils.compare(r2.getLevel(), r1.getLevel());
});
//
// "naive" pagination
int first = internalPageable.getPageNumber() * internalPageable.getPageSize();
int last = internalPageable.getPageSize() + first;
List<IdmMonitoringResultDto> page = results.subList(first < results.size() ? first : results.size() > 0 ? results.size() - 1 : 0, last < results.size() ? last : results.size());
//
return new PageImpl<>(page, internalPageable, results.size());
}
use of eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel 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;
}
Aggregations