Search in sources :

Example 1 with DataStorageStreamingContent

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);
}
Also used : PreferenceManager(com.epam.pipeline.manager.preference.PreferenceManager) Mock(org.mockito.Mock) SystemPreferences(com.epam.pipeline.manager.preference.SystemPreferences) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Attachment(com.epam.pipeline.entity.issue.Attachment) Mockito.verify(org.mockito.Mockito.verify) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) Mockito(org.mockito.Mockito) MockitoAnnotations(org.mockito.MockitoAnnotations) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) ByteArrayInputStream(java.io.ByteArrayInputStream) MessageHelper(com.epam.pipeline.common.MessageHelper) DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) Matchers.eq(org.mockito.Matchers.eq) Preference(com.epam.pipeline.entity.preference.Preference) S3bucketDataStorage(com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage) AuthManager(com.epam.pipeline.manager.security.AuthManager) Assert(org.junit.Assert) DataStorageManager(com.epam.pipeline.manager.datastorage.DataStorageManager) InputStream(java.io.InputStream) Before(org.junit.Before) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) Preference(com.epam.pipeline.entity.preference.Preference) DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) ByteArrayInputStream(java.io.ByteArrayInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Attachment(com.epam.pipeline.entity.issue.Attachment) Before(org.junit.Before)

Example 2 with DataStorageStreamingContent

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());
}
Also used : AbstractDataStorage(com.epam.pipeline.entity.datastorage.AbstractDataStorage) DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) Attachment(com.epam.pipeline.entity.issue.Attachment)

Example 3 with DataStorageStreamingContent

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()));
}
Also used : DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) GetMapping(org.springframework.web.bind.annotation.GetMapping) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with DataStorageStreamingContent

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());
}
Also used : DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with DataStorageStreamingContent

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);
    }
}
Also used : DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException) DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) FileNotFoundException(java.io.FileNotFoundException) DataStorageFile(com.epam.pipeline.entity.datastorage.DataStorageFile) File(java.io.File)

Aggregations

DataStorageStreamingContent (com.epam.pipeline.entity.datastorage.DataStorageStreamingContent)7 DataStorageException (com.epam.pipeline.entity.datastorage.DataStorageException)2 DataStorageFile (com.epam.pipeline.entity.datastorage.DataStorageFile)2 Attachment (com.epam.pipeline.entity.issue.Attachment)2 Test (org.junit.Test)2 AmazonS3 (com.amazonaws.services.s3.AmazonS3)1 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)1 GetObjectRequest (com.amazonaws.services.s3.model.GetObjectRequest)1 S3Object (com.amazonaws.services.s3.model.S3Object)1 MessageHelper (com.epam.pipeline.common.MessageHelper)1 AbstractDataStorage (com.epam.pipeline.entity.datastorage.AbstractDataStorage)1 S3bucketDataStorage (com.epam.pipeline.entity.datastorage.aws.S3bucketDataStorage)1 Preference (com.epam.pipeline.entity.preference.Preference)1 DataStorageManager (com.epam.pipeline.manager.datastorage.DataStorageManager)1 PreferenceManager (com.epam.pipeline.manager.preference.PreferenceManager)1 SystemPreferences (com.epam.pipeline.manager.preference.SystemPreferences)1 AuthManager (com.epam.pipeline.manager.security.AuthManager)1 ApiOperation (io.swagger.annotations.ApiOperation)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1