Search in sources :

Example 11 with IdmMessageDto

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;
}
Also used : Arrays(java.util.Arrays) Autowired(org.springframework.beans.factory.annotation.Autowired) IdmJwtAuthentication(eu.bcvsolutions.idm.core.security.api.domain.IdmJwtAuthentication) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) Lists(com.google.common.collect.Lists) IdmAuthorityUtils(eu.bcvsolutions.idm.core.security.api.utils.IdmAuthorityUtils) SecurityMockMvcRequestPostProcessors.authentication(org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.authentication) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) InitTestData(eu.bcvsolutions.idm.InitTestData) NotificationLevel(eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel) MediaTypes(org.springframework.hateoas.MediaTypes) ObjectWriter(com.fasterxml.jackson.databind.ObjectWriter) IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) StringWriter(java.io.StringWriter) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) IOException(java.io.IOException) Test(org.junit.Test) Collectors(java.util.stream.Collectors) MockMvcRequestBuilders(org.springframework.test.web.servlet.request.MockMvcRequestBuilders) List(java.util.List) BaseDtoController(eu.bcvsolutions.idm.core.api.rest.BaseDtoController) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmIdentityService(eu.bcvsolutions.idm.core.api.service.IdmIdentityService) Authentication(org.springframework.security.core.Authentication) Assert.assertEquals(org.junit.Assert.assertEquals) IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto)

Example 12 with IdmMessageDto

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

Example 13 with IdmMessageDto

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

Example 14 with IdmMessageDto

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

Example 15 with IdmMessageDto

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

Aggregations

IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)22 Test (org.junit.Test)14 AbstractUnitTest (eu.bcvsolutions.idm.test.api.AbstractUnitTest)10 DefaultResultModel (eu.bcvsolutions.idm.core.api.dto.DefaultResultModel)6 ResultModel (eu.bcvsolutions.idm.core.api.dto.ResultModel)6 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)6 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)5 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)5 IdmNotificationDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto)3 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)3 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)3 ArrayList (java.util.ArrayList)3 IdmNotificationRecipientDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto)2 StringWriter (java.io.StringWriter)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 Lists (com.google.common.collect.Lists)1 InitTestData (eu.bcvsolutions.idm.InitTestData)1 DefaultEventResult (eu.bcvsolutions.idm.core.api.event.DefaultEventResult)1 ResultCodeException (eu.bcvsolutions.idm.core.api.exception.ResultCodeException)1