use of com.epam.pipeline.entity.issue.Issue 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.Issue 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.Issue 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.Issue 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.issue.Issue in project cloud-pipeline by epam.
the class IssueDaoTest method testCRUD.
@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testCRUD() {
EntityVO entity = new EntityVO(ENTITY_ID, ENTITY_CLASS);
Issue issue = getIssue(NAME, entity);
// create
issueDao.createIssue(issue);
Long id = issue.getId();
// load
Optional<Issue> loaded = issueDao.loadIssue(id);
assertTrue(loaded.isPresent());
verifyIssue(issue, loaded.get());
Issue issue2 = getIssue(NAME2, entity);
issueDao.createIssue(issue2);
List<Issue> issues = issueDao.loadIssuesForEntity(entity);
assertEquals(2, issues.size());
// update
issue.setName(NAME3);
issue.setText(TEXT2);
issue.setStatus(STATUS);
issueDao.updateIssue(issue);
Optional<Issue> updated = issueDao.loadIssue(id);
assertTrue(updated.isPresent());
assertEquals(NAME3, updated.get().getName());
assertEquals(STATUS, updated.get().getStatus());
// delete
issueDao.deleteIssue(issue.getId());
Optional<Issue> deleted = issueDao.loadIssue(id);
assertFalse(deleted.isPresent());
}
Aggregations