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;
}
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());
}
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());
}
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())));
}
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);
}
Aggregations