use of com.epam.pipeline.entity.issue.IssueComment in project cloud-pipeline by epam.
the class NotificationManagerTest method testNotifyIssueComment.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testNotifyIssueComment() {
Pipeline pipeline = createPipeline(testOwner);
Issue issue = createIssue(testUser2, pipeline);
issueDao.createIssue(issue);
IssueComment comment = new IssueComment();
comment.setIssueId(issue.getId());
comment.setText("Notify @TestUser1");
comment.setAuthor(testUser2.getUserName());
notificationManager.notifyIssueComment(comment, issue, comment.getText());
List<NotificationMessage> messages = monitoringNotificationDao.loadAllNotifications();
Assert.assertEquals(1, messages.size());
NotificationMessage message = messages.get(0);
Assert.assertEquals(testUser2.getId(), message.getToUserId());
Assert.assertEquals(issueCommentTemplate.getId(), message.getTemplate().getId());
Assert.assertTrue(message.getCopyUserIds().stream().anyMatch(id -> id.equals(testUser1.getId())));
Assert.assertTrue(message.getCopyUserIds().stream().anyMatch(id -> id.equals(testOwner.getId())));
updateKeepInformedOwner(issueCommentSettings, false);
notificationManager.notifyIssueComment(comment, issue, comment.getText());
messages = monitoringNotificationDao.loadAllNotifications();
Assert.assertEquals(2, messages.size());
Assert.assertNull(messages.get(1).getToUserId());
}
use of com.epam.pipeline.entity.issue.IssueComment in project cloud-pipeline by epam.
the class IssueLoaderTest method shouldLoadIssueTest.
@Test
void shouldLoadIssueTest() throws EntityNotFoundException {
Attachment attachment = new Attachment();
attachment.setPath(TEST_PATH);
attachment.setOwner(USER_NAME);
IssueComment comment = IssueComment.builder().author(USER_NAME).text(TEST_DESCRIPTION).build();
EntityVO entity = new EntityVO(1L, AclClass.TOOL);
Issue expectedIssue = Issue.builder().id(1L).name(TEST_NAME).text(TEST_DESCRIPTION).status(IssueStatus.OPEN).labels(Collections.singletonList(TEST_LABEL)).attachments(Collections.singletonList(attachment)).comments(Collections.singletonList(comment)).entity(entity).author(TEST_NAME).build();
IssueLoader issueLoader = new IssueLoader(apiClient);
when(apiClient.loadIssue(anyLong())).thenReturn(expectedIssue);
Optional<EntityContainer<Issue>> container = issueLoader.loadEntity(1L);
EntityContainer<Issue> issueEntityContainer = container.orElseThrow(AssertionError::new);
Issue actualIssue = issueEntityContainer.getEntity();
assertNotNull(actualIssue);
verifyIssue(expectedIssue, actualIssue);
verifyPipelineUser(issueEntityContainer.getOwner());
verifyPermissions(PERMISSIONS_CONTAINER_WITH_OWNER, issueEntityContainer.getPermissions());
verifyMetadata(EXPECTED_METADATA, new ArrayList<>(issueEntityContainer.getMetadata().values()));
}
use of com.epam.pipeline.entity.issue.IssueComment in project cloud-pipeline by epam.
the class IssueManager method loadComment.
/**
* Loads comment specified by ID. If comment doesn't exist an error will be thrown. If {@code issueId} and
* loaded {@link IssueComment#id} are not equal an error will be occurred.
* @param issueId issue's ID
* @param commentId comment's ID
* @return existing {@link IssueComment}
*/
public IssueComment loadComment(Long issueId, Long commentId) {
IssueComment comment = commentDao.loadComment(commentId).orElseThrow(getCommentNotFoundException(commentId));
comment.setAttachments(attachmentDao.loadAttachmentsByCommentIds(Collections.singletonList(commentId)).get(commentId));
validateIssueId(issueId, comment);
return comment;
}
use of com.epam.pipeline.entity.issue.IssueComment in project cloud-pipeline by epam.
the class IssueManager method loadIssue.
/**
* Loads an {@link Issue} specified by ID. If issue doesn't exist exception will be thrown.
* @param id issue's ID
* @return issue with comments that belong to it
*/
public Issue loadIssue(Long id) {
Issue issue = issueDao.loadIssue(id).orElseThrow(getIssueNotFoundException(id));
issue.setComments(commentDao.loadCommentsForIssue(id));
issue.setAttachments(attachmentDao.loadAttachmentsByIssueId(id));
Map<Long, List<Attachment>> attachmentMap = attachmentDao.loadAttachmentsByCommentIds(issue.getComments().stream().map(IssueComment::getId).collect(Collectors.toList()));
issue.getComments().forEach(c -> c.setAttachments(attachmentMap.get(c.getId())));
return issue;
}
use of com.epam.pipeline.entity.issue.IssueComment 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);
}
Aggregations