Search in sources :

Example 1 with Attachment

use of com.epam.pipeline.entity.issue.Attachment 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;
}
Also used : MessageConstants(com.epam.pipeline.common.MessageConstants) IssueVO(com.epam.pipeline.controller.vo.IssueVO) AttachmentDao(com.epam.pipeline.dao.issue.AttachmentDao) Autowired(org.springframework.beans.factory.annotation.Autowired) Supplier(java.util.function.Supplier) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) MessageHelper(com.epam.pipeline.common.MessageHelper) IssueCommentDao(com.epam.pipeline.dao.issue.IssueCommentDao) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) Map(java.util.Map) IssueComment(com.epam.pipeline.entity.issue.IssueComment) EntityManager(com.epam.pipeline.manager.EntityManager) IssueCommentVO(com.epam.pipeline.controller.vo.IssueCommentVO) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) IssueStatus(com.epam.pipeline.entity.issue.IssueStatus) Attachment(com.epam.pipeline.entity.issue.Attachment) Collectors(java.util.stream.Collectors) PagedResult(com.epam.pipeline.controller.PagedResult) List(java.util.List) IssueMapper(com.epam.pipeline.mapper.IssueMapper) IssueDao(com.epam.pipeline.dao.issue.IssueDao) Optional(java.util.Optional) AclClass(com.epam.pipeline.entity.security.acl.AclClass) NotificationManager(com.epam.pipeline.manager.notification.NotificationManager) AuthManager(com.epam.pipeline.manager.security.AuthManager) Issue(com.epam.pipeline.entity.issue.Issue) Collections(java.util.Collections) EntityVO(com.epam.pipeline.controller.vo.EntityVO) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) IssueComment(com.epam.pipeline.entity.issue.IssueComment) Attachment(com.epam.pipeline.entity.issue.Attachment) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Attachment

use of com.epam.pipeline.entity.issue.Attachment 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;
}
Also used : MessageConstants(com.epam.pipeline.common.MessageConstants) IssueVO(com.epam.pipeline.controller.vo.IssueVO) AttachmentDao(com.epam.pipeline.dao.issue.AttachmentDao) Autowired(org.springframework.beans.factory.annotation.Autowired) Supplier(java.util.function.Supplier) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) MessageHelper(com.epam.pipeline.common.MessageHelper) IssueCommentDao(com.epam.pipeline.dao.issue.IssueCommentDao) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Service(org.springframework.stereotype.Service) Map(java.util.Map) IssueComment(com.epam.pipeline.entity.issue.IssueComment) EntityManager(com.epam.pipeline.manager.EntityManager) IssueCommentVO(com.epam.pipeline.controller.vo.IssueCommentVO) AbstractSecuredEntity(com.epam.pipeline.entity.AbstractSecuredEntity) IssueStatus(com.epam.pipeline.entity.issue.IssueStatus) Attachment(com.epam.pipeline.entity.issue.Attachment) Collectors(java.util.stream.Collectors) PagedResult(com.epam.pipeline.controller.PagedResult) List(java.util.List) IssueMapper(com.epam.pipeline.mapper.IssueMapper) IssueDao(com.epam.pipeline.dao.issue.IssueDao) Optional(java.util.Optional) AclClass(com.epam.pipeline.entity.security.acl.AclClass) NotificationManager(com.epam.pipeline.manager.notification.NotificationManager) AuthManager(com.epam.pipeline.manager.security.AuthManager) Issue(com.epam.pipeline.entity.issue.Issue) Collections(java.util.Collections) EntityVO(com.epam.pipeline.controller.vo.EntityVO) Transactional(org.springframework.transaction.annotation.Transactional) Assert(org.springframework.util.Assert) Issue(com.epam.pipeline.entity.issue.Issue) Attachment(com.epam.pipeline.entity.issue.Attachment) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with Attachment

use of com.epam.pipeline.entity.issue.Attachment in project cloud-pipeline by epam.

the class AttachmentDaoTest method testCRUD.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testCRUD() {
    Attachment attachment = new Attachment();
    attachment.setName("testAttachment");
    attachment.setCreatedDate(new Date());
    attachment.setPath("///");
    attachment.setOwner(TEST_OWNER);
    attachmentDao.createAttachment(attachment);
    Assert.assertNotNull(attachment.getId());
    attachmentDao.updateAttachmentIssueId(attachment.getId(), issue.getId());
    List<Attachment> attachments = attachmentDao.loadAttachmentsByIssueId(issue.getId());
    Assert.assertFalse(attachments.isEmpty());
    Attachment loaded = attachments.get(0);
    Assert.assertEquals(attachment.getId(), loaded.getId());
    Assert.assertEquals(attachment.getName(), loaded.getName());
    Assert.assertEquals(attachment.getPath(), loaded.getPath());
    Assert.assertEquals(attachment.getCreatedDate(), loaded.getCreatedDate());
    attachmentDao.updateAttachmentCommentId(attachment.getId(), comment.getId());
    Map<Long, List<Attachment>> attachmentsMap = attachmentDao.loadAttachmentsByCommentIds(Collections.singletonList(comment.getId()));
    Assert.assertFalse(attachmentsMap.isEmpty());
    loaded = attachmentsMap.get(comment.getId()).get(0);
    Assert.assertEquals(attachment.getId(), loaded.getId());
    Assert.assertEquals(attachment.getName(), loaded.getName());
    Assert.assertEquals(attachment.getPath(), loaded.getPath());
    Assert.assertEquals(attachment.getCreatedDate(), loaded.getCreatedDate());
    attachmentDao.deleteAttachment(attachment.getId());
    Assert.assertTrue(attachmentDao.loadAttachmentsByIssueId(issue.getId()).isEmpty());
}
Also used : Attachment(com.epam.pipeline.entity.issue.Attachment) List(java.util.List) Date(java.util.Date) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Attachment

use of com.epam.pipeline.entity.issue.Attachment in project cloud-pipeline by epam.

the class AttachmentDaoTest method testDeleteByComment.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testDeleteByComment() {
    Attachment attachment = new Attachment();
    attachment.setName("testAttachment");
    attachment.setCreatedDate(new Date());
    attachment.setPath("///");
    attachment.setOwner(TEST_OWNER);
    attachmentDao.createAttachment(attachment);
    Assert.assertNotNull(attachment.getId());
    attachmentDao.updateAttachmentCommentId(attachment.getId(), comment.getId());
    attachmentDao.deleteAttachmentsByCommentIds(Collections.singletonList(comment.getId()));
    Assert.assertTrue(attachmentDao.loadAttachmentsByCommentIds(Collections.singletonList(comment.getId())).isEmpty());
}
Also used : Attachment(com.epam.pipeline.entity.issue.Attachment) Date(java.util.Date) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Example 5 with Attachment

use of com.epam.pipeline.entity.issue.Attachment in project cloud-pipeline by epam.

the class AttachmentDaoTest method testDeleteByIssueId.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void testDeleteByIssueId() {
    Attachment attachment = new Attachment();
    attachment.setName("testAttachment");
    attachment.setCreatedDate(new Date());
    attachment.setPath("///");
    attachment.setOwner(TEST_OWNER);
    attachmentDao.createAttachment(attachment);
    Assert.assertNotNull(attachment.getId());
    attachmentDao.updateAttachmentIssueId(attachment.getId(), issue.getId());
    attachmentDao.deleteAttachmentsByIssueId(issue.getId());
    Assert.assertTrue(attachmentDao.loadAttachmentsByIssueId(issue.getId()).isEmpty());
}
Also used : Attachment(com.epam.pipeline.entity.issue.Attachment) Date(java.util.Date) Test(org.junit.Test) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Transactional(org.springframework.transaction.annotation.Transactional)

Aggregations

Attachment (com.epam.pipeline.entity.issue.Attachment)17 Transactional (org.springframework.transaction.annotation.Transactional)9 Issue (com.epam.pipeline.entity.issue.Issue)7 IssueComment (com.epam.pipeline.entity.issue.IssueComment)7 Date (java.util.Date)7 Test (org.junit.Test)7 EntityVO (com.epam.pipeline.controller.vo.EntityVO)6 AuthManager (com.epam.pipeline.manager.security.AuthManager)6 List (java.util.List)6 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)5 AclClass (com.epam.pipeline.entity.security.acl.AclClass)5 Collections (java.util.Collections)5 Collectors (java.util.stream.Collectors)5 Autowired (org.springframework.beans.factory.annotation.Autowired)5 Propagation (org.springframework.transaction.annotation.Propagation)5 IssueCommentVO (com.epam.pipeline.controller.vo.IssueCommentVO)4 IssueVO (com.epam.pipeline.controller.vo.IssueVO)4 AttachmentDao (com.epam.pipeline.dao.issue.AttachmentDao)4 IssueStatus (com.epam.pipeline.entity.issue.IssueStatus)4 Folder (com.epam.pipeline.entity.pipeline.Folder)4