use of com.epam.pipeline.entity.issue.Issue in project cloud-pipeline by epam.
the class IssueManager method updateComment.
/**
* Updates comment specified by ID. If issue was closed or issue doesn't exist or comment doesn't exist an error
* will be thrown. If text for comment is empty exception will be thrown.
* @param issueId issue's ID
* @param commentId comment's ID
* @param commentVO comment's text
* @return updated {@link IssueComment}
*/
@Transactional(propagation = Propagation.REQUIRED)
public IssueComment updateComment(Long issueId, Long commentId, IssueCommentVO commentVO) {
IssueComment issueComment = loadComment(issueId, commentId);
loadIssueAndCheckIfNotClosed(issueId);
String text = commentVO.getText();
ensureNotEmptyString(text, MessageConstants.ERROR_INVALID_COMMENT_TEXT);
issueComment.setText(text);
commentDao.updateComment(issueComment);
// Find the attachments that were removed during update and delete them
HashSet<Attachment> newAttachments = new HashSet<>(commentVO.getAttachments());
List<Attachment> allAttachments = attachmentDao.loadAttachmentsByCommentId(commentId);
List<Attachment> toDelete = allAttachments.stream().filter(a -> !newAttachments.contains(a)).collect(Collectors.toList());
attachmentFileManager.deleteAttachments(toDelete);
// New attachments might be added so we need to link them to this comment
commentVO.getAttachments().forEach(a -> attachmentDao.updateAttachmentCommentId(a.getId(), commentId));
return issueComment;
}
use of com.epam.pipeline.entity.issue.Issue in project cloud-pipeline by epam.
the class IssueManager method createIssue.
/**
* Creates a new issue that refers to existing {@link com.epam.pipeline.entity.AbstractSecuredEntity}.
* If {@link com.epam.pipeline.entity.AbstractSecuredEntity} doesn't exist an error will be occurred.
* @param issueVO {@link IssueVO} to create
* @return create {@link Issue}
*/
@Transactional(propagation = Propagation.REQUIRED)
public Issue createIssue(IssueVO issueVO) {
validateIssueParameters(issueVO);
EntityVO entityVO = issueVO.getEntity();
validateEntityParameters(entityVO);
AbstractSecuredEntity entity = ensureEntityExists(entityVO);
Issue issue = issueMapper.toIssue(issueVO);
issue.setAuthor(authManager.getAuthorizedUser());
issueDao.createIssue(issue);
issueVO.getAttachments().forEach(a -> attachmentDao.updateAttachmentIssueId(a.getId(), issue.getId()));
notificationManager.notifyIssue(issue, entity, StringUtils.defaultIfBlank(issueVO.getHtmlText(), issue.getText()));
return issue;
}
use of com.epam.pipeline.entity.issue.Issue in project cloud-pipeline by epam.
the class IssueManager method updateIssue.
/**
* Updates an {@link Issue} specified by ID. If issue was closed or doesn't exist an error will be occurred.
* @param issueId issue ID
* @param issueVO issue content to update
* @return updated issue
*/
@Transactional(propagation = Propagation.REQUIRED)
public Issue updateIssue(Long issueId, IssueVO issueVO) {
validateIssueParameters(issueVO);
Issue existingIssue = loadIssueAndCheckIfNotClosed(issueId);
Issue issue = updateIssueObject(existingIssue, issueVO);
issueDao.updateIssue(issue);
// Find the attachments that were removed during update and delete them
HashSet<Attachment> newAttachments = new HashSet<>(issueVO.getAttachments());
List<Attachment> allAttachments = attachmentDao.loadAttachmentsByIssueId(issueId);
List<Attachment> toDelete = allAttachments.stream().filter(a -> !newAttachments.contains(a)).collect(Collectors.toList());
attachmentFileManager.deleteAttachments(toDelete);
// Link new attachments to this issue
issueVO.getAttachments().forEach(a -> attachmentDao.updateAttachmentIssueId(a.getId(), issueId));
return issue;
}
use of com.epam.pipeline.entity.issue.Issue in project cloud-pipeline by epam.
the class IssueManager method createComment.
/**
* Creates comment for issue. If issue was closed or doesn't exist an error will be occurred.
* @param issueId issue's ID
* @param commentVO comment text
* @return created {@link IssueComment}
*/
@Transactional(propagation = Propagation.REQUIRED)
public IssueComment createComment(Long issueId, IssueCommentVO commentVO) {
Issue issue = loadIssueAndCheckIfNotClosed(issueId);
validateComment(commentVO);
IssueComment comment = issueMapper.toIssueComment(commentVO);
comment.setIssueId(issueId);
comment.setAuthor(authManager.getAuthorizedUser());
commentDao.createComment(comment);
commentVO.getAttachments().forEach(a -> attachmentDao.updateAttachmentCommentId(a.getId(), comment.getId()));
notificationManager.notifyIssueComment(comment, issue, StringUtils.defaultIfBlank(commentVO.getHtmlText(), comment.getText()));
return comment;
}
use of com.epam.pipeline.entity.issue.Issue in project cloud-pipeline by epam.
the class IssueDaoTest method getIssue.
public static Issue getIssue(String name, EntityVO entity) {
Issue issue = new Issue();
issue.setName(name);
issue.setAuthor(AUTHOR);
issue.setEntity(entity);
issue.setText(TEXT);
issue.setLabels(Arrays.asList(LABEL1, LABEL2));
return issue;
}
Aggregations