use of com.epam.pipeline.entity.notification.NotificationTemplate 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.NotificationTemplate 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.NotificationTemplate 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.NotificationTemplate in project cloud-pipeline by epam.
the class NotificationManager method notifyIssue.
/**
* Notify users that a new issue was created for a given entity. Will notify mentioned users as well.
*
* @param issue an issue to notify about
* @param entity an entity for wich issue was created
*/
@Transactional(propagation = Propagation.REQUIRED)
public void notifyIssue(Issue issue, AbstractSecuredEntity entity, String htmlText) {
NotificationSettings newIssueSettings = notificationSettingsManager.load(NotificationType.NEW_ISSUE);
if (newIssueSettings == null || !newIssueSettings.isEnabled()) {
LOGGER.info(messageHelper.getMessage(MessageConstants.INFO_NOTIFICATION_TEMPLATE_NOT_CONFIGURED, "new issue"));
return;
}
NotificationMessage message = new NotificationMessage();
message.setTemplate(new NotificationTemplate(newIssueSettings.getTemplateId()));
message.setCopyUserIds(getMentionedUsers(issue.getText()));
Issue copyWithHtml = issue.toBuilder().text(htmlText).build();
message.setTemplateParameters(jsonMapper.convertValue(copyWithHtml, new TypeReference<Map<String, Object>>() {
}));
if (newIssueSettings.isKeepInformedOwner()) {
PipelineUser owner = userManager.loadUserByName(entity.getOwner());
message.setToUserId(owner.getId());
}
monitoringNotificationDao.createMonitoringNotification(message);
}
use of com.epam.pipeline.entity.notification.NotificationTemplate in project cloud-pipeline by epam.
the class NotificationManager method notifyRunStatusChanged.
@Transactional(propagation = Propagation.REQUIRED)
public void notifyRunStatusChanged(PipelineRun pipelineRun) {
NotificationSettings runStatusSettings = notificationSettingsManager.load(NotificationType.PIPELINE_RUN_STATUS);
if (runStatusSettings == null || !runStatusSettings.isEnabled()) {
LOGGER.info("No template configured for pipeline run status changes notifications or it was disabled!");
return;
}
NotificationMessage message = new NotificationMessage();
message.setTemplate(new NotificationTemplate(runStatusSettings.getTemplateId()));
message.setTemplateParameters(PipelineRunMapper.map(pipelineRun, null));
List<Long> ccUserIds = getKeepInformedUserIds(runStatusSettings);
if (runStatusSettings.isKeepInformedAdmins()) {
ExtendedRole extendedRole = roleManager.loadRoleWithUsers(DefaultRoles.ROLE_ADMIN.getId());
ccUserIds.addAll(extendedRole.getUsers().stream().map(PipelineUser::getId).collect(Collectors.toList()));
}
message.setCopyUserIds(ccUserIds);
if (runStatusSettings.isKeepInformedOwner()) {
PipelineUser pipelineOwner = userManager.loadUserByName(pipelineRun.getOwner());
message.setToUserId(pipelineOwner.getId());
}
monitoringNotificationDao.createMonitoringNotification(message);
}
Aggregations