Search in sources :

Example 1 with IssueVO

use of com.epam.pipeline.controller.vo.IssueVO 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 2 with IssueVO

use of com.epam.pipeline.controller.vo.IssueVO in project cloud-pipeline by epam.

the class IssueManagerTest method createIssueWithAttachments.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void createIssueWithAttachments() throws InterruptedException {
    when(authManager.getAuthorizedUser()).thenReturn(AUTHOR);
    IssueVO issueVO = getIssueVO(ISSUE_NAME, ISSUE_TEXT, entityVO);
    issueVO.setAttachments(Collections.singletonList(testAttachment));
    Issue saved = issueManager.createIssue(issueVO);
    Issue loaded = issueManager.loadIssue(saved.getId());
    assertFalse(loaded.getAttachments().isEmpty());
    issueManager.deleteIssue(loaded.getId());
    assertFalse(attachmentDao.load(testAttachment.getId()).isPresent());
    Thread.sleep(10);
    verify(dataStorageManager).deleteDataStorageItems(Mockito.eq(testSystemDataStorage.getId()), Mockito.anyList(), Mockito.anyBoolean());
}
Also used : Issue(com.epam.pipeline.entity.issue.Issue) IssueVO(com.epam.pipeline.controller.vo.IssueVO) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 3 with IssueVO

use of com.epam.pipeline.controller.vo.IssueVO in project cloud-pipeline by epam.

the class IssueManagerTest method testCreateIssue.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void testCreateIssue() {
    when(authManager.getAuthorizedUser()).thenReturn(AUTHOR);
    IssueVO issueVO = getIssueVO(ISSUE_NAME, ISSUE_TEXT, entityVO);
    Issue saved = issueManager.createIssue(issueVO);
    Issue loaded = issueManager.loadIssue(saved.getId());
    compareIssues(saved, loaded);
    ArgumentCaptor<Issue> captor = ArgumentCaptor.forClass(Issue.class);
    ArgumentCaptor<String> htmlTextCaptor = ArgumentCaptor.forClass(String.class);
    verify(notificationManager).notifyIssue(captor.capture(), any(), htmlTextCaptor.capture());
    assertEquals(ISSUE_TEXT, captor.getValue().getText());
    assertEquals(ISSUE_TEXT, htmlTextCaptor.getValue());
}
Also used : Issue(com.epam.pipeline.entity.issue.Issue) IssueVO(com.epam.pipeline.controller.vo.IssueVO) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with IssueVO

use of com.epam.pipeline.controller.vo.IssueVO in project cloud-pipeline by epam.

the class IssueApiServiceTest method getIssueVO.

private IssueVO getIssueVO(String name, String text, EntityVO entity) {
    IssueVO issueVO = new IssueVO();
    issueVO.setName(name);
    issueVO.setEntity(entity);
    issueVO.setText(text);
    issueVO.setStatus(IssueStatus.OPEN);
    return issueVO;
}
Also used : IssueVO(com.epam.pipeline.controller.vo.IssueVO)

Example 5 with IssueVO

use of com.epam.pipeline.controller.vo.IssueVO in project cloud-pipeline by epam.

the class ToolDaoTest method getIssueVO.

private IssueVO getIssueVO(String name, String text, EntityVO entity) {
    IssueVO issueVO = new IssueVO();
    issueVO.setName(name);
    issueVO.setEntity(entity);
    issueVO.setText(text);
    return issueVO;
}
Also used : IssueVO(com.epam.pipeline.controller.vo.IssueVO)

Aggregations

IssueVO (com.epam.pipeline.controller.vo.IssueVO)16 Transactional (org.springframework.transaction.annotation.Transactional)11 AbstractSpringTest (com.epam.pipeline.AbstractSpringTest)10 Test (org.junit.Test)10 Issue (com.epam.pipeline.entity.issue.Issue)9 EntityVO (com.epam.pipeline.controller.vo.EntityVO)5 IssueCommentVO (com.epam.pipeline.controller.vo.IssueCommentVO)2 AttachmentDao (com.epam.pipeline.dao.issue.AttachmentDao)2 Attachment (com.epam.pipeline.entity.issue.Attachment)2 IssueComment (com.epam.pipeline.entity.issue.IssueComment)2 IssueStatus (com.epam.pipeline.entity.issue.IssueStatus)2 Folder (com.epam.pipeline.entity.pipeline.Folder)2 AclClass (com.epam.pipeline.entity.security.acl.AclClass)2 NotificationManager (com.epam.pipeline.manager.notification.NotificationManager)2 AuthManager (com.epam.pipeline.manager.security.AuthManager)2 IssueMapper (com.epam.pipeline.mapper.IssueMapper)2 Collections (java.util.Collections)2 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2