use of com.epam.pipeline.entity.datastorage.DataStorageStreamingContent in project cloud-pipeline by epam.
the class AttachmentFileManagerTest method setUp.
@Before
public void setUp() throws Exception {
MockitoAnnotations.initMocks(this);
attachmentFileManager = new AttachmentFileManager(dataStorageManager, preferenceManager, attachmentManager, messageHelper, authManager);
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.createDataStorageFile(Mockito.eq(1L), Mockito.anyString(), Mockito.anyString(), Mockito.any(InputStream.class))).then((Answer<DataStorageFile>) invocation -> {
String path = invocation.getArgumentAt(1, String.class);
String name = invocation.getArgumentAt(2, String.class);
DataStorageFile file = new DataStorageFile();
file.setPath(path + "/" + name);
return file;
});
when(attachmentManager.load(Mockito.anyLong())).thenAnswer(invocation -> {
Attachment attachment = new Attachment();
attachment.setId(invocation.getArgumentAt(0, Long.class));
attachment.setName(TEST_ATTACHMENT_NAME);
attachment.setPath(TEST_ATTACHMENT_PATH);
return attachment;
});
DataStorageStreamingContent content = new DataStorageStreamingContent(new ByteArrayInputStream(new byte[] { 1 }), TEST_ATTACHMENT_NAME);
when(dataStorageManager.getStreamingContent(testSystemDataStorage.getId(), TEST_ATTACHMENT_PATH, null)).thenReturn(content);
when(authManager.getAuthorizedUser()).thenReturn(TEST_USER);
}
use of com.epam.pipeline.entity.datastorage.DataStorageStreamingContent in project cloud-pipeline by epam.
the class AttachmentFileManager method downloadAttachment.
public DataStorageStreamingContent downloadAttachment(long attachmentId) {
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);
Attachment attachment = attachmentManager.load(attachmentId);
DataStorageStreamingContent content = dataStorageManager.getStreamingContent(attachmentStorage.getId(), attachment.getPath(), null);
return new DataStorageStreamingContent(content.getContent(), attachment.getName());
}
use of com.epam.pipeline.entity.datastorage.DataStorageStreamingContent in project cloud-pipeline by epam.
the class IssueController method downloadAttachment.
@GetMapping(value = "/attachment/{id}")
@ApiOperation(value = "Downloads an attachment.", notes = "Downloads an attachment by specified ID.", produces = MediaType.APPLICATION_JSON_VALUE)
public void downloadAttachment(HttpServletResponse response, @PathVariable Long id) throws IOException {
DataStorageStreamingContent content = attachmentFileManager.downloadAttachment(id);
writeStreamToResponse(response, content.getContent(), content.getName(), guessMediaType(content.getName()));
}
use of com.epam.pipeline.entity.datastorage.DataStorageStreamingContent in project cloud-pipeline by epam.
the class DataStorageController method downloadStream.
@RequestMapping(value = "/datastorage/{id}/download", method = RequestMethod.GET)
public void downloadStream(HttpServletResponse response, @PathVariable Long id, @RequestParam String path, @RequestParam(value = VERSION, required = false) final String version) throws IOException {
DataStorageStreamingContent content = dataStorageApiService.getStreamingContent(id, path, version);
writeStreamToResponse(response, content.getContent(), content.getName());
}
use of com.epam.pipeline.entity.datastorage.DataStorageStreamingContent in project cloud-pipeline by epam.
the class NFSStorageProvider method getStream.
@Override
public DataStorageStreamingContent getStream(NFSDataStorage dataStorage, String path, String version) {
File mntDir = mount(dataStorage);
File file = new File(mntDir, path);
try {
return new DataStorageStreamingContent(file);
} catch (FileNotFoundException e) {
throw new DataStorageException(e);
}
}
Aggregations