Search in sources :

Example 6 with DataStorageStreamingContent

use of com.epam.pipeline.entity.datastorage.DataStorageStreamingContent in project cloud-pipeline by epam.

the class S3Helper method getFileStream.

public DataStorageStreamingContent getFileStream(AbstractDataStorage dataStorage, String path, String version) {
    try {
        AmazonS3 client = getDefaultS3Client();
        GetObjectRequest rangeObjectRequest = new GetObjectRequest(dataStorage.getPath(), path, version);
        S3Object object = client.getObject(rangeObjectRequest);
        return new DataStorageStreamingContent(object.getObjectContent(), object.getKey());
    } catch (AmazonS3Exception e) {
        if (e.getStatusCode() == NOT_FOUND) {
            throw new DataStorageException(String.format("File '%s' doesn't exist", path));
        } else {
            throw new DataStorageException(e.getMessage(), e);
        }
    }
}
Also used : AmazonS3(com.amazonaws.services.s3.AmazonS3) DataStorageException(com.epam.pipeline.entity.datastorage.DataStorageException) DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) S3Object(com.amazonaws.services.s3.model.S3Object) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) GetObjectRequest(com.amazonaws.services.s3.model.GetObjectRequest)

Example 7 with DataStorageStreamingContent

use of com.epam.pipeline.entity.datastorage.DataStorageStreamingContent in project cloud-pipeline by epam.

the class AttachmentFileManagerTest method testDownloadAttachment.

@Test
public void testDownloadAttachment() {
    DataStorageStreamingContent content = attachmentFileManager.downloadAttachment(1L);
    Assert.assertNotNull(content.getContent());
    Assert.assertEquals(TEST_ATTACHMENT_NAME, content.getName());
    verify(dataStorageManager).loadByNameOrId(TEST_SYSTEM_DATA_STORAGE);
    verify(attachmentManager).load(1L);
    verify(dataStorageManager).getStreamingContent(testSystemDataStorage.getId(), TEST_ATTACHMENT_PATH, null);
}
Also used : DataStorageStreamingContent(com.epam.pipeline.entity.datastorage.DataStorageStreamingContent) Test(org.junit.Test)

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