Search in sources :

Example 11 with Attachment

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

the class AttachmentFileManager method uploadAttachment.

public Attachment uploadAttachment(InputStream attachmentInputStream, String fileName) {
    String systemDataStorageName = preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_SYSTEM_DATA_STORAGE_NAME);
    Assert.notNull(systemDataStorageName, messageHelper.getMessage(MessageConstants.ERROR_ATTACHMENT_SYSTEM_DATA_STORAGE_NOT_CONFIGURED));
    AbstractDataStorage attachmentStorage = dataStorageManager.loadByNameOrId(systemDataStorageName);
    UUID uuid = UUID.randomUUID();
    String uniqueName = uuid.toString() + "-" + fileName;
    DataStorageFile uploadedFile = dataStorageManager.createDataStorageFile(attachmentStorage.getId(), ATTACHMENTS_DIRECTORY, uniqueName, attachmentInputStream);
    Attachment attachment = new Attachment();
    attachment.setPath(uploadedFile.getPath());
    attachment.setName(fileName);
    attachment.setCreatedDate(DateUtils.now());
    attachment.setOwner(authManager.getAuthorizedUser());
    attachmentManager.create(attachment);
    return attachment;
}
Also used : DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) Attachment(com.epam.pipeline.entity.issue.Attachment) UUID(java.util.UUID)

Example 12 with Attachment

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

the class AttachmentFileManagerTest method testUploadAttachment.

@Test
public void testUploadAttachment() {
    Attachment attachment = attachmentFileManager.uploadAttachment(new ByteArrayInputStream(new byte[] { 1 }), TEST_ATTACHMENT_NAME);
    Assert.assertNotNull(attachment.getPath());
    Assert.assertTrue(attachment.getPath().startsWith("attachments/"));
    Assert.assertTrue(attachment.getPath().endsWith(TEST_ATTACHMENT_NAME));
    Assert.assertEquals(TEST_ATTACHMENT_NAME, attachment.getName());
    verify(dataStorageManager).loadByNameOrId(TEST_SYSTEM_DATA_STORAGE);
    verify(dataStorageManager).createDataStorageFile(eq(testSystemDataStorage.getId()), eq("attachments"), Mockito.endsWith(TEST_ATTACHMENT_NAME), Mockito.any(InputStream.class));
    ArgumentCaptor<Attachment> attachmentCaptor = ArgumentCaptor.forClass(Attachment.class);
    verify(attachmentManager).create(attachmentCaptor.capture());
    Assert.assertEquals(TEST_USER, attachmentCaptor.getValue().getOwner());
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Attachment(com.epam.pipeline.entity.issue.Attachment) Test(org.junit.Test)

Example 13 with Attachment

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

the class IssueManagerTest method updateCommentWithAttachments.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Exception.class)
public void updateCommentWithAttachments() throws InterruptedException {
    Attachment newAttachment = new Attachment();
    newAttachment.setPath("///");
    newAttachment.setName("newTestAttachment");
    newAttachment.setCreatedDate(new Date());
    newAttachment.setOwner(AUTHOR);
    attachmentDao.createAttachment(newAttachment);
    Issue issue = registerIssue();
    Long issueId = issue.getId();
    IssueCommentVO commentVO = getCommentVO(COMMENT_TEXT);
    IssueComment comment = issueManager.createComment(issueId, commentVO);
    IssueCommentVO updated = new IssueCommentVO();
    updated.setText(COMMENT_TEXT2);
    updated.setAttachments(Collections.singletonList(newAttachment));
    Long commentId = comment.getId();
    issueManager.updateComment(issueId, comment.getId(), updated);
    IssueComment loaded = issueManager.loadComment(issueId, commentId);
    assertEquals(1, loaded.getAttachments().size());
    assertTrue(loaded.getAttachments().stream().allMatch(a -> a.getName().equals(newAttachment.getName())));
    issueManager.deleteComment(issueId, commentId);
    assertFalse(attachmentDao.load(newAttachment.getId()).isPresent());
    Thread.sleep(TIMEOUT);
    verify(dataStorageManager, Mockito.times(2)).deleteDataStorageItems(Mockito.eq(testSystemDataStorage.getId()), Mockito.anyList(), Mockito.anyBoolean());
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) IssueVO(com.epam.pipeline.controller.vo.IssueVO) AttachmentDao(com.epam.pipeline.dao.issue.AttachmentDao) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Function(java.util.function.Function) Folder(com.epam.pipeline.entity.pipeline.Folder) ArgumentCaptor(org.mockito.ArgumentCaptor) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Map(java.util.Map) FolderDao(com.epam.pipeline.dao.pipeline.FolderDao) IssueComment(com.epam.pipeline.entity.issue.IssueComment) Before(org.junit.Before) MockBean(org.springframework.boot.test.mock.mockito.MockBean) IssueCommentVO(com.epam.pipeline.controller.vo.IssueCommentVO) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) SpyBean(org.springframework.boot.test.mock.mockito.SpyBean) FolderManager(com.epam.pipeline.manager.pipeline.FolderManager) Assert.assertTrue(org.junit.Assert.assertTrue) IssueStatus(com.epam.pipeline.entity.issue.IssueStatus) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Attachment(com.epam.pipeline.entity.issue.Attachment) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) IssueMapper(com.epam.pipeline.mapper.IssueMapper) Assert.assertFalse(org.junit.Assert.assertFalse) Preference(com.epam.pipeline.entity.preference.Preference) AclClass(com.epam.pipeline.entity.security.acl.AclClass) NotificationManager(com.epam.pipeline.manager.notification.NotificationManager) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) AuthManager(com.epam.pipeline.manager.security.AuthManager) Issue(com.epam.pipeline.entity.issue.Issue) Collections(java.util.Collections) DataStorageManager(com.epam.pipeline.manager.datastorage.DataStorageManager) Assert.assertEquals(org.junit.Assert.assertEquals) EntityVO(com.epam.pipeline.controller.vo.EntityVO) Transactional(org.springframework.transaction.annotation.Transactional) IssueCommentVO(com.epam.pipeline.controller.vo.IssueCommentVO) Issue(com.epam.pipeline.entity.issue.Issue) IssueComment(com.epam.pipeline.entity.issue.IssueComment) Attachment(com.epam.pipeline.entity.issue.Attachment) Date(java.util.Date) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 14 with Attachment

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

the class IssueManagerTest method updateIssueWithAttachments.

@Test
@Transactional(propagation = Propagation.REQUIRES_NEW, rollbackFor = Throwable.class)
public void updateIssueWithAttachments() {
    when(authManager.getAuthorizedUser()).thenReturn(AUTHOR);
    IssueVO issueVO = getIssueVO(ISSUE_NAME, ISSUE_TEXT, entityVO);
    issueVO.setStatus(IssueStatus.OPEN);
    issueVO.setAttachments(Collections.singletonList(testAttachment));
    Issue saved = issueManager.createIssue(issueVO);
    Attachment newAttachment = new Attachment();
    newAttachment.setPath("///");
    newAttachment.setName("newTestAttachment");
    newAttachment.setCreatedDate(new Date());
    newAttachment.setOwner(AUTHOR);
    attachmentDao.createAttachment(newAttachment);
    issueVO.setAttachments(Collections.singletonList(newAttachment));
    issueManager.updateIssue(saved.getId(), issueVO);
    Issue loaded = issueManager.loadIssue(saved.getId());
    assertEquals(1, loaded.getAttachments().size());
    assertTrue(loaded.getAttachments().stream().allMatch(a -> a.getName().equals(newAttachment.getName())));
}
Also used : Arrays(java.util.Arrays) Date(java.util.Date) IssueVO(com.epam.pipeline.controller.vo.IssueVO) AttachmentDao(com.epam.pipeline.dao.issue.AttachmentDao) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Autowired(org.springframework.beans.factory.annotation.Autowired) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Function(java.util.function.Function) Folder(com.epam.pipeline.entity.pipeline.Folder) ArgumentCaptor(org.mockito.ArgumentCaptor) CollectionUtils(org.apache.commons.collections.CollectionUtils) Propagation(org.springframework.transaction.annotation.Propagation) Map(java.util.Map) FolderDao(com.epam.pipeline.dao.pipeline.FolderDao) IssueComment(com.epam.pipeline.entity.issue.IssueComment) Before(org.junit.Before) MockBean(org.springframework.boot.test.mock.mockito.MockBean) IssueCommentVO(com.epam.pipeline.controller.vo.IssueCommentVO) PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) SpyBean(org.springframework.boot.test.mock.mockito.SpyBean) FolderManager(com.epam.pipeline.manager.pipeline.FolderManager) Assert.assertTrue(org.junit.Assert.assertTrue) IssueStatus(com.epam.pipeline.entity.issue.IssueStatus) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Attachment(com.epam.pipeline.entity.issue.Attachment) Collectors(java.util.stream.Collectors) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) Mockito(org.mockito.Mockito) List(java.util.List) Stream(java.util.stream.Stream) IssueMapper(com.epam.pipeline.mapper.IssueMapper) Assert.assertFalse(org.junit.Assert.assertFalse) Preference(com.epam.pipeline.entity.preference.Preference) AclClass(com.epam.pipeline.entity.security.acl.AclClass) NotificationManager(com.epam.pipeline.manager.notification.NotificationManager) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) AuthManager(com.epam.pipeline.manager.security.AuthManager) Issue(com.epam.pipeline.entity.issue.Issue) Collections(java.util.Collections) DataStorageManager(com.epam.pipeline.manager.datastorage.DataStorageManager) Assert.assertEquals(org.junit.Assert.assertEquals) EntityVO(com.epam.pipeline.controller.vo.EntityVO) Transactional(org.springframework.transaction.annotation.Transactional) Issue(com.epam.pipeline.entity.issue.Issue) Attachment(com.epam.pipeline.entity.issue.Attachment) IssueVO(com.epam.pipeline.controller.vo.IssueVO) Date(java.util.Date) AbstractSpringTest(com.epam.pipeline.AbstractSpringTest) Test(org.junit.Test) Transactional(org.springframework.transaction.annotation.Transactional)

Example 15 with Attachment

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

the class IssueManagerTest method setUp.

@Before
public void setUp() throws Exception {
    Folder folder = new Folder();
    folder.setName(FOLDER_NAME);
    folder.setOwner(AUTHOR);
    folderDao.createFolder(folder);
    folderDao.loadFolder(folder.getId());
    entityVO = new EntityVO(folder.getId(), AclClass.FOLDER);
    testAttachment = new Attachment();
    testAttachment.setName("test");
    testAttachment.setPath("///");
    testAttachment.setCreatedDate(new Date());
    testAttachment.setOwner(AUTHOR);
    attachmentDao.createAttachment(testAttachment);
    Preference systemDataStorage = SystemPreferences.DATA_STORAGE_SYSTEM_DATA_STORAGE_NAME.toPreference();
    systemDataStorage.setName(TEST_SYSTEM_DATA_STORAGE);
    when(preferenceManager.getPreference(SystemPreferences.DATA_STORAGE_SYSTEM_DATA_STORAGE_NAME)).thenReturn(TEST_SYSTEM_DATA_STORAGE);
    when(dataStorageManager.loadByNameOrId(TEST_SYSTEM_DATA_STORAGE)).thenReturn(testSystemDataStorage);
    when(dataStorageManager.deleteDataStorageItems(any(), any(), any())).thenReturn(1);
}
Also used : EntityVO(com.epam.pipeline.controller.vo.EntityVO) Preference(com.epam.pipeline.entity.preference.Preference) Attachment(com.epam.pipeline.entity.issue.Attachment) Folder(com.epam.pipeline.entity.pipeline.Folder) Date(java.util.Date) Before(org.junit.Before)

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