Search in sources :

Example 76 with IdmNotificationTemplateDto

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();
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) IdmNotificationFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 77 with IdmNotificationTemplateDto

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());
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) AbstractUnitTest(eu.bcvsolutions.idm.test.api.AbstractUnitTest) Test(org.junit.Test)

Example 78 with IdmNotificationTemplateDto

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;
}
Also used : IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) SysProvisioningBreakItems(eu.bcvsolutions.idm.acc.dto.SysProvisioningBreakItems)

Example 79 with IdmNotificationTemplateDto

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();
}
Also used : IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)

Example 80 with IdmNotificationTemplateDto

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);
    }
}
Also used : IdmNotificationTemplateFilter(eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationTemplateFilter) IdmBulkActionDto(eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto) IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto) UUID(java.util.UUID) HashSet(java.util.HashSet) AbstractBulkActionTest(eu.bcvsolutions.idm.test.api.AbstractBulkActionTest) Test(org.junit.Test)

Aggregations

IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)87 Test (org.junit.Test)68 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)53 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)42 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)42 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)31 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)23 NotificationConfigurationDto (eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto)19 Transactional (org.springframework.transaction.annotation.Transactional)18 DefaultAttachmentManagerIntegrationTest (eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest)17 NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)14 IdmBulkActionDto (eu.bcvsolutions.idm.core.api.bulk.action.dto.IdmBulkActionDto)13 GuardedString (eu.bcvsolutions.idm.core.security.api.domain.GuardedString)12 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)11 UUID (java.util.UUID)9 AbstractBulkActionTest (eu.bcvsolutions.idm.test.api.AbstractBulkActionTest)8 ZonedDateTime (java.time.ZonedDateTime)8 IdmNotificationDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto)7 IdmNotificationTemplateService (eu.bcvsolutions.idm.core.notification.api.service.IdmNotificationTemplateService)7 HashSet (java.util.HashSet)7