use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.
the class SMTPNotificationManagerTest method testEmailSendingWithParamsWithoutTemplate.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testEmailSendingWithParamsWithoutTemplate() {
PipelineUser user = new PipelineUser();
user.setUserName(USER_NAME);
user.setAttributes(Collections.singletonMap(EMAIL_KEY, EMAIL));
userRepository.save(user);
NotificationMessage message = new NotificationMessage();
message.setSubject(MESSAGE_SUBJECT);
message.setBody(MESSAGE_BODY_WITH_PARAM);
message.setTemplateParameters(Collections.singletonMap("name", USER_NAME));
message.setToUserId(user.getId());
message.setCopyUserIds(Collections.singletonList(user.getId()));
smtpNotificationManager.notifySubscribers(message);
MimeMessage[] receivedMessages = greenMail.getReceivedMessages();
assertTrue(receivedMessages.length == 2);
String filledMessage = PARSED_MESSAGE_BODY_WITH_PARAM.replace("$templateParameters.get(\"name\")", USER_NAME);
System.out.println(GreenMailUtil.getBody(receivedMessages[0]));
System.out.println(filledMessage);
assertTrue(GreenMailUtil.getBody(receivedMessages[0]).contains(filledMessage));
}
use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.
the class NotificationRepositoryTest method deleteByIdTest.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void deleteByIdTest() {
NotificationMessage message = new NotificationMessage();
NotificationTemplate template = new NotificationTemplate();
template.setSubject(SUBJECT);
template.setBody(BODY_WITHOUT_PARAM);
templateRepository.save(template);
message.setTemplate(template);
message.setToUserId(0L);
message.setCopyUserIds(Collections.singletonList(0L));
notificationRepository.save(message);
Long idToDelete = message.getId();
notificationRepository.deleteById(idToDelete);
Assert.assertNull(notificationRepository.findOne(idToDelete));
}
use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.
the class NotificationRepositoryTest method loadTest.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW)
public void loadTest() {
NotificationMessage message = new NotificationMessage();
NotificationTemplate template = new NotificationTemplate();
template.setSubject(SUBJECT);
template.setBody(BODY_WITH_PARAM);
templateRepository.save(template);
message.setTemplate(template);
message.setTemplateParameters(Collections.singletonMap(PARAM, Integer.toHexString(this.hashCode())));
message.setToUserId(0L);
message.setCopyUserIds(Collections.singletonList(0L));
notificationRepository.save(message);
List<NotificationMessage> messages = notificationRepository.loadNotification(new PageRequest(0, 5));
Assert.assertTrue(messages.size() == 1);
NotificationMessage loaded = messages.get(0);
Assert.assertEquals(Integer.toHexString(this.hashCode()), loaded.getTemplateParameters().get(PARAM));
Assert.assertEquals(BODY_WITH_PARAM, loaded.getTemplate().getBody());
Assert.assertEquals(SUBJECT, loaded.getTemplate().getSubject());
}
use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.
the class NotificationManager method notifyIssueComment.
@Transactional(propagation = Propagation.REQUIRED)
public void notifyIssueComment(IssueComment comment, Issue issue, String htmlText) {
NotificationSettings newIssueCommentSettings = notificationSettingsManager.load(NotificationType.NEW_ISSUE_COMMENT);
if (newIssueCommentSettings == null || !newIssueCommentSettings.isEnabled()) {
LOGGER.info(messageHelper.getMessage(MessageConstants.INFO_NOTIFICATION_TEMPLATE_NOT_CONFIGURED, "new issue"));
return;
}
NotificationMessage message = new NotificationMessage();
message.setTemplate(new NotificationTemplate(newIssueCommentSettings.getTemplateId()));
AbstractSecuredEntity entity = entityManager.load(issue.getEntity().getEntityClass(), issue.getEntity().getEntityId());
List<PipelineUser> referencedUsers = userManager.loadUsersByNames(Arrays.asList(entity.getOwner(), issue.getAuthor()));
List<Long> ccUserIds = getMentionedUsers(comment.getText());
referencedUsers.stream().filter(u -> u.getUserName().equals(entity.getOwner())).findFirst().ifPresent(owner -> ccUserIds.add(owner.getId()));
message.setCopyUserIds(ccUserIds);
if (newIssueCommentSettings.isKeepInformedOwner()) {
PipelineUser author = referencedUsers.stream().filter(u -> u.getUserName().equals(issue.getAuthor())).findFirst().orElseThrow(() -> new IllegalArgumentException("No issue author was found"));
message.setToUserId(author.getId());
}
IssueComment copyWithHtml = comment.toBuilder().text(htmlText).build();
Map<String, Object> commentParams = jsonMapper.convertValue(copyWithHtml, new TypeReference<Map<String, Object>>() {
});
commentParams.put("issue", jsonMapper.convertValue(issue, new TypeReference<Map<String, Object>>() {
}));
message.setTemplateParameters(commentParams);
monitoringNotificationDao.createMonitoringNotification(message);
}
use of com.epam.pipeline.entity.notification.NotificationMessage in project cloud-pipeline by epam.
the class NotificationManager method createNotification.
/**
* Creates a custom notification.
*
* @param messageVO Notification message request that contains at least subject, body and toUser fields.
* @return Created notification.
*/
@Transactional(propagation = Propagation.REQUIRED)
public NotificationMessage createNotification(final NotificationMessageVO messageVO) {
Assert.notNull(messageVO.getSubject(), messageHelper.getMessage(MessageConstants.ERROR_NOTIFICATION_SUBJECT_NOT_SPECIFIED));
Assert.notNull(messageVO.getBody(), messageHelper.getMessage(MessageConstants.ERROR_NOTIFICATION_BODY_NOT_SPECIFIED));
Assert.notNull(messageVO.getToUser(), messageHelper.getMessage(MessageConstants.ERROR_NOTIFICATION_RECEIVER_NOT_SPECIFIED));
final NotificationMessage message = toMessage(messageVO);
monitoringNotificationDao.createMonitoringNotification(message);
return message;
}
Aggregations