Search in sources :

Example 1 with IdmNotificationDto

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

the class CustomMailActivityBehavior method execute.

/**
 * Sending email through {@link EmailNotificationSender}.
 */
@Override
public void execute(DelegateExecution execution) {
    LOG.trace("Sending email from workflow execution [{}]", execution.getId());
    IdmEmailLogDto emailLog = new IdmEmailLogDto();
    // recipients
    String[] tos = splitAndTrim(getStringFromField(to, execution));
    if (!ObjectUtils.isEmpty(tos)) {
        emailLog.setRecipients(Arrays.stream(tos).map(identityOrAddress -> {
            return prepareRecipient(identityOrAddress);
        }).collect(Collectors.toList()));
    }
    // sender
    emailLog.setIdentitySender(getIdentity(getStringFromField(from, execution)).getId());
    // message
    emailLog.setMessage(new IdmMessageDto.Builder().setSubject(getStringFromField(subject, execution)).setTextMessage(getStringFromField(text, execution)).setHtmlMessage(getStringFromField(html, execution)).build());
    IdmNotificationDto result = emailService.send(emailLog);
    LOG.trace("Email from workflow execution [{}] was sent with result [{}]", execution.getId(), result == null ? false : true);
    leave(execution);
}
Also used : IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)

Example 2 with IdmNotificationDto

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

the class NotificationRestTest method testSendNotification.

@Test
public void testSendNotification() throws Exception {
    final IdmIdentityDto sender = createTestIdentity();
    final IdmIdentityDto recipient = createTestIdentity();
    // 
    final IdmNotificationDto notif = createTestNotification(NotificationLevel.INFO, TEST_SUBJECT, TEST_MESSAGE, TEST_TOPIC, sender, recipient);
    final String jsonContent = jsonify(notif);
    // 
    MockHttpServletResponse response = getMockMvc().perform(MockMvcRequestBuilders.post(BaseDtoController.BASE_PATH + "/notifications").with(authentication(getAuthentication())).contentType(MediaTypes.HAL_JSON).content(jsonContent)).andReturn().getResponse();
    // 
    assertEquals(201, response.getStatus());
}
Also used : IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmIdentityDto(eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) Test(org.junit.Test)

Example 3 with IdmNotificationDto

use of eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto 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) InitTestDataProcessor(eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor) IdmNotificationRecipientDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto) AbstractRestTest(eu.bcvsolutions.idm.test.api.AbstractRestTest) 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 4 with IdmNotificationDto

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

the class DefaultNotificationServiceIntegrationTest method testSenderFilterTest.

@Test
public void testSenderFilterTest() {
    IdmIdentityDto sender = getHelper().createIdentity();
    IdmNotificationFilter filter = new IdmNotificationFilter();
    IdmNotificationDto notification = new IdmNotificationDto();
    notification.setIdentitySender(sender.getId());
    // 
    // create templates
    IdmNotificationTemplateDto template = createTestTemplate();
    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) DefaultAttachmentManagerIntegrationTest(eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest) AbstractIntegrationTest(eu.bcvsolutions.idm.test.api.AbstractIntegrationTest) Test(org.junit.Test)

Example 5 with IdmNotificationDto

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

the class CustomMailActivityBehavior method execute.

/**
 * Sending emails through {@link EmailNotificationSender}
 */
@Override
public void execute(ActivityExecution execution) {
    log.trace("Sending email from workflow execution [{}]", execution.getId());
    IdmEmailLogDto emailLog = new IdmEmailLogDto();
    // recipients
    String[] tos = splitAndTrim(getStringFromField(to, execution));
    if (!ObjectUtils.isEmpty(tos)) {
        emailLog.setRecipients(Arrays.stream(tos).map(identityOrAddress -> {
            return prepareRecipient(identityOrAddress);
        }).collect(Collectors.toList()));
    }
    // sender
    emailLog.setIdentitySender(getIdentity(getStringFromField(from, execution)).getId());
    // message
    emailLog.setMessage(new IdmMessageDto.Builder().setSubject(getStringFromField(subject, execution)).setTextMessage(getStringFromField(text, execution)).setHtmlMessage(getStringFromField(html, execution)).build());
    IdmNotificationDto result = emailService.send(emailLog);
    log.trace("Email from workflow execution [{}] was sent with result [{}]", execution.getId(), result == null ? false : true);
    leave(execution);
}
Also used : IdmNotificationDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto) IdmEmailLogDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto) IdmMessageDto(eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)

Aggregations

IdmNotificationDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationDto)8 IdmMessageDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmMessageDto)7 Test (org.junit.Test)6 IdmIdentityDto (eu.bcvsolutions.idm.core.api.dto.IdmIdentityDto)4 IdmNotificationLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationLogDto)4 IdmNotificationTemplateDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationTemplateDto)4 IdmNotificationFilter (eu.bcvsolutions.idm.core.notification.api.dto.filter.IdmNotificationFilter)4 AbstractIntegrationTest (eu.bcvsolutions.idm.test.api.AbstractIntegrationTest)4 DefaultAttachmentManagerIntegrationTest (eu.bcvsolutions.idm.core.ecm.service.impl.DefaultAttachmentManagerIntegrationTest)2 IdmEmailLogDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmEmailLogDto)2 AbstractRestTest (eu.bcvsolutions.idm.test.api.AbstractRestTest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ObjectWriter (com.fasterxml.jackson.databind.ObjectWriter)1 Lists (com.google.common.collect.Lists)1 BaseDtoController (eu.bcvsolutions.idm.core.api.rest.BaseDtoController)1 IdmIdentityService (eu.bcvsolutions.idm.core.api.service.IdmIdentityService)1 InitTestDataProcessor (eu.bcvsolutions.idm.core.model.event.processor.module.InitTestDataProcessor)1 NotificationLevel (eu.bcvsolutions.idm.core.notification.api.domain.NotificationLevel)1 IdmNotificationRecipientDto (eu.bcvsolutions.idm.core.notification.api.dto.IdmNotificationRecipientDto)1