Search in sources :

Example 1 with IdmNotificationTemplateDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.

the class DefaultIdmNotificationTemplateService method typeToDto.

/**
 * Transform type to dto, if second parameter is null it will be created new
 * dto.
 *
 * @param type
 * @param template
 * @return
 */
private IdmNotificationTemplateDto typeToDto(IdmNotificationTemplateType type, IdmNotificationTemplateDto template) {
    if (template == null) {
        template = new IdmNotificationTemplateDto();
    }
    // 
    if (type == null) {
        return template;
    }
    // transform type to DTO
    template.setCode(type.getCode());
    template.setName(type.getName());
    template.setBodyHtml(type.getBodyHtml());
    template.setBodyText(type.getBodyText());
    template.setModule(type.getModuleId());
    template.setSubject(type.getSubject());
    template.setUnmodifiable(type.isSystemTemplate());
    template.setParameter(type.getParameter());
    return template;
}
Also used : IdmNotificationTemplateDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)

Example 2 with IdmNotificationTemplateDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.

the class DefaultNotificationServiceIntegrationTest method sendWildCardsWithTemplateAndOwnText.

@Test
public void sendWildCardsWithTemplateAndOwnText() {
    String topic = "testTopic-" + System.currentTimeMillis();
    String textMessage = "testMessageText-" + System.currentTimeMillis();
    String textTemplate = "testMessageTemplate-" + System.currentTimeMillis();
    // 
    IdmNotificationTemplateDto template = new IdmNotificationTemplateDto();
    template.setName(textTemplate);
    template.setCode(textTemplate);
    template.setBodyHtml(textTemplate);
    template.setBodyText(textTemplate);
    template.setSubject(textTemplate);
    template = notificationTemplateService.save(template);
    // 
    IdmIdentityDto identity = helper.createIdentity();
    // create config, for email, topic, template and without level = wildcard
    NotificationConfigurationDto config = new NotificationConfigurationDto();
    // topic
    config.setTopic(topic);
    // template
    config.setTemplate(template.getId());
    // email
    config.setNotificationType(IdmEmailLog.NOTIFICATION_TYPE);
    config = notificationConfigurationService.save(config);
    // 
    // set all text into message
    List<IdmNotificationLogDto> notifications = notificationManager.send(topic, new IdmMessageDto.Builder().setLevel(// set level
    NotificationLevel.SUCCESS).setHtmlMessage(textMessage).setTextMessage(textMessage).setSubject(textMessage).build(), identity);
    // 
    assertEquals(1, notifications.size());
    // 
    IdmNotificationLogDto notification = notifications.get(0);
    // topic has own template, but in message is set text
    assertEquals(textMessage, notification.getMessage().getHtmlMessage());
    assertEquals(textMessage, notification.getMessage().getSubject());
    assertEquals(textMessage, notification.getMessage().getTextMessage());
}
Also used : NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) 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)

Example 3 with IdmNotificationTemplateDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.

the class DefaultNotificationServiceIntegrationTest method testFilterByDate.

@Test
@Transactional
public void testFilterByDate() {
    assertEquals(0, idmNotificationRepository.count());
    IdmNotificationTemplateDto template = createTestTemplate("Idm notification", "subject");
    IdmIdentityDto identity = identityService.getByUsername(InitTestData.TEST_USER_1);
    DateTime from = new DateTime().minusDays(1);
    DateTime till = new DateTime().minusDays(1);
    notificationManager.send(TOPIC, new IdmMessageDto.Builder().setTemplate(template).build(), identity);
    notificationManager.send(TOPIC, new IdmMessageDto.Builder().setTemplate(template).build(), identity);
    IdmNotificationFilter filter = new IdmNotificationFilter();
    filter.setNotificationType(IdmNotificationLog.class);
    assertEquals(2, notificationLogService.find(filter, null).getTotalElements());
    filter.setFrom(from);
    assertEquals(2, notificationLogService.find(filter, null).getTotalElements());
    filter.setFrom(null);
    filter.setTill(till);
    assertEquals(0, notificationLogService.find(filter, null).getTotalElements());
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) 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) DateTime(org.joda.time.DateTime) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with IdmNotificationTemplateDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.

the class DefaultNotificationServiceIntegrationTest method testEmailFilterBySender.

@Test
@Transactional
public void testEmailFilterBySender() {
    // create templates
    IdmNotificationTemplateDto template = createTestTemplate("Idm notification", "subject");
    IdmNotificationFilter filter = new IdmNotificationFilter();
    filter.setSender(InitTestData.TEST_USER_2);
    assertEquals(0, emailLogService.find(filter, null).getTotalElements());
    filter.setSender(InitTestData.TEST_USER_1);
    assertEquals(0, emailLogService.find(filter, null).getTotalElements());
    // send some email
    IdmIdentityDto identity = identityService.getByUsername(InitTestData.TEST_USER_1);
    IdmIdentityDto identity2 = identityService.getByUsername(InitTestData.TEST_USER_2);
    emailService.send(TOPIC, new IdmMessageDto.Builder().setTemplate(template).build(), identity);
    filter.setSender(null);
    assertEquals(1, emailLogService.find(filter, null).getTotalElements());
    filter.setSender(identity2.getUsername());
    assertEquals(0, emailLogService.find(filter, null).getTotalElements());
    filter.setSender(null);
    filter.setRecipient(identity.getUsername());
    assertEquals(1, emailLogService.find(filter, null).getTotalElements());
}
Also used : IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) 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 5 with IdmNotificationTemplateDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto in project CzechIdMng by bcvsolutions.

the class DefaultNotificationServiceIntegrationTest method sendWildCardsWithTemplateWithoutText.

@Test
public void sendWildCardsWithTemplateWithoutText() {
    String topic = "testTopic-" + System.currentTimeMillis();
    String textTemplate = "testMessageTemplate-" + System.currentTimeMillis();
    // 
    IdmNotificationTemplateDto template = new IdmNotificationTemplateDto();
    template.setName(textTemplate);
    template.setCode(textTemplate);
    template.setBodyHtml(textTemplate);
    template.setBodyText(textTemplate);
    template.setSubject(textTemplate);
    template = notificationTemplateService.save(template);
    // 
    IdmIdentityDto identity = helper.createIdentity();
    // create config, for email, topic, template and without level = wildcard
    NotificationConfigurationDto config = new NotificationConfigurationDto();
    // topic
    config.setTopic(topic);
    // template
    config.setTemplate(template.getId());
    // email
    config.setNotificationType(IdmEmailLog.NOTIFICATION_TYPE);
    config = notificationConfigurationService.save(config);
    // 
    List<IdmNotificationLogDto> notifications = notificationManager.send(topic, new IdmMessageDto.Builder().setLevel(// set level
    NotificationLevel.SUCCESS).build(), identity);
    // 
    assertEquals(1, notifications.size());
    // 
    IdmNotificationLogDto notification = notifications.get(0);
    // topic has own template and in message isnt set text
    assertEquals(textTemplate, notification.getMessage().getHtmlMessage());
    assertEquals(textTemplate, notification.getMessage().getSubject());
    assertEquals(textTemplate, notification.getMessage().getTextMessage());
}
Also used : NotificationConfigurationDto(eu.bcvsolutions.idm.core.notification.api.dto.NotificationConfigurationDto) IdmNotificationLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) 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)

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