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);
}
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());
}
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;
}
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());
}
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);
}
Aggregations