use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class IdmNotificationConfigurationDisabledTest method testOneDisabled.
@Test
@Transactional
public void testOneDisabled() {
assertEquals(0, idmNotificationRepository.count());
NotificationLevel level = NotificationLevel.ERROR;
IdmNotificationTemplateDto template = createTestTemplate("Idm test notification", "disabled test");
IdmIdentityDto identity = getHelper().createIdentity((GuardedString) null);
configs.add(createNotificationConfiguration(TOPIC, null, IdmConsoleLog.NOTIFICATION_TYPE, template.getId(), true));
configs.add(createNotificationConfiguration(TOPIC, null, 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.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class IdmMessageDtoUnitTest method testTemplate.
@Test
public void testTemplate() {
IdmNotificationTemplateDto template = new IdmNotificationTemplateDto();
template.setSubject(PARAMETER_SUBJECT);
template.setBodyText(PARAMETER_TEXT);
IdmMessageDto message = new IdmMessageDto.Builder().setTemplate(template).build();
//
Assert.assertEquals(PARAMETER_SUBJECT, message.getSubject());
Assert.assertEquals(PARAMETER_TEXT, message.getTextMessage());
Assert.assertEquals(PARAMETER_TEXT, message.getHtmlMessage());
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class ProvisioningBreakProcessor method processProvisioningBreak.
private synchronized boolean processProvisioningBreak(SysProvisioningOperationDto provisioningOperation, ProvisioningEventType operationType, SysSystemDto system, SysProvisioningBreakConfigDto breakConfig) {
boolean blocked = false;
Long currentTimeMillis = System.currentTimeMillis();
//
// get cache for system
SysProvisioningBreakItems cache = breakConfigService.getCacheProcessedItems(system.getId());
// calculate timestamp without period
Long timestampWithoutPeriod = currentTimeMillis - breakConfig.getPeriod(TimeUnit.MILLISECONDS);
// remove older records
cache.removeOlderRecordsThan(operationType, timestampWithoutPeriod);
// get actual count - processed items from timestampWithoutPeriod
int actualCount = cache.getSizeRecordsNewerThan(operationType, timestampWithoutPeriod);
//
if (isReachedDisableLimit(breakConfig, actualCount)) {
// check count is higher than disable limit
// block system for operation
blockSystemForOperation(operationType, system);
//
IdmNotificationTemplateDto template = null;
if (breakConfig.getDisableTemplate() == null) {
LOG.debug("Warning template for provisioning break id [{}] missing.", breakConfig.getId());
} else {
template = DtoUtils.getEmbedded(breakConfig, SysProvisioningBreakConfig_.disableTemplate);
}
//
sendMessage(AccModuleDescriptor.TOPIC_PROVISIONING_BREAK_DISABLE, system, actualCount, template, breakConfig, operationType, cache.getDiffBetweenActualAndLast(operationType, currentTimeMillis));
//
LOG.warn("System id: [{}] will be blocked for operation: [{}].", provisioningOperation.getSystem(), operationType.toString());
provisioningOperation = blockOperation(provisioningOperation, system);
blocked = true;
} else if (isReachedWarningLimit(breakConfig, actualCount)) {
// disabled may be null
if (breakConfig.getDisableLimit() == null) {
LOG.warn("Block for the system id [{}] and operation [{}] is not set. Operation counter [{}].", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), actualCount);
} else {
LOG.warn("To block the system id [{}] for operation [{}] remains [{}] operations + send message.", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), breakConfig.getDisableLimit() - actualCount);
}
IdmNotificationTemplateDto template = null;
if (breakConfig.getWarningTemplate() == null) {
LOG.debug("Warning template for provisioning break id [{}] missing.", breakConfig.getId());
} else {
template = DtoUtils.getEmbedded(breakConfig, SysProvisioningBreakConfig_.warningTemplate);
}
//
sendMessage(AccModuleDescriptor.TOPIC_PROVISIONING_BREAK_WARNING, system, actualCount, template, breakConfig, operationType, cache.getDiffBetweenActualAndLast(operationType, currentTimeMillis));
} else if (isMoreThanWarningLimit(breakConfig, actualCount)) {
// after overrun warning limit, isn't send any another notification - add at least log
if (breakConfig.getDisableLimit() == null) {
LOG.warn("Block for the system id [{}] and operation [{}] is not set. Operation counter [{}].", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), actualCount);
} else {
LOG.warn("To block the system id [{}] for operation [{}] remains [{}] operations.", provisioningOperation.getSystem(), provisioningOperation.getOperationType().toString(), breakConfig.getDisableLimit() - actualCount);
}
}
// remove all unless items in cache
cache.addItem(operationType, currentTimeMillis);
breakConfigService.saveCacheProcessedItems(provisioningOperation.getSystem(), cache);
return blocked;
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class AbstractModuleDescriptor method getNotificationTemplateId.
/**
* Returns notification template by given code
* @param code
* @return
* @throws IllegalArgumentException if template by given code is not found
*/
protected UUID getNotificationTemplateId(String code) {
Assert.hasLength(code, "Notification template code is required.");
//
IdmNotificationTemplateDto notificationTemplate = notificationTemplateService.getByCode(code);
if (notificationTemplate == null) {
throw new IllegalArgumentException(String.format("System template with code [%s] for module [%s] not found. Check template's path configuration [%s].", code, getId(), IdmNotificationTemplateService.TEMPLATE_FOLDER));
}
return notificationTemplate.getId();
}
use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.
the class NotificationTemplateDeleteBulkActionIntegrationTest method processBulkActionByFilter.
@Test
public void processBulkActionByFilter() {
templateService.init();
String desc = "script description" + getHelper().createName();
IdmNotificationTemplateDto template1 = templateService.getByCode(TEST_TEMPLATE);
IdmNotificationTemplateDto template2 = templateService.getByCode(TEST_TEMPLATE_TWO);
template1.setUnmodifiable(false);
template1.setSubject(desc);
template2.setUnmodifiable(false);
template2.setSubject(desc);
template1 = templateService.save(template1);
template2 = templateService.save(template2);
Set<UUID> templates = new HashSet<UUID>();
templates.add(template1.getId());
templates.add(template2.getId());
IdmNotificationTemplateFilter filter = new IdmNotificationTemplateFilter();
filter.setText(desc);
List<IdmNotificationTemplateDto> checkTemplates = templateService.find(filter, null).getContent();
assertEquals(2, checkTemplates.size());
IdmBulkActionDto bulkAction = this.findBulkAction(IdmNotificationTemplate.class, NotificationTemplateDeleteBulkAction.NAME);
bulkAction.setTransformedFilter(filter);
bulkAction.setFilter(toMap(filter));
IdmBulkActionDto processAction = bulkActionManager.processAction(bulkAction);
checkResultLrt(processAction, 2l, null, null);
for (UUID id : templates) {
IdmNotificationTemplateDto templateDto = templateService.get(id);
assertNull(templateDto);
}
}
Aggregations