use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project stocator by CODAIT.
the class COSBlockOutputStream method putObject.
/**
* Upload the current block as a single PUT request; if the buffer is empty a
* 0-byte PUT will be invoked, as it is needed to create an entry at the far
* end.
*
* @throws IOException any problem
*/
private void putObject() throws IOException {
LOG.debug("Executing regular upload for {}", writeOperationHelper);
final COSDataBlocks.DataBlock block = getActiveBlock();
int size = block.dataSize();
final COSDataBlocks.BlockUploadData uploadData = block.startUpload();
final PutObjectRequest putObjectRequest = uploadData.hasFile() ? writeOperationHelper.newPutRequest(uploadData.getFile()) : writeOperationHelper.newPutRequest(uploadData.getUploadStream(), size);
final ObjectMetadata om = new ObjectMetadata();
om.setUserMetadata(mMetadata);
if (contentType != null && !contentType.isEmpty()) {
om.setContentType(contentType);
} else {
om.setContentType("application/octet-stream");
}
putObjectRequest.setMetadata(om);
ListenableFuture<PutObjectResult> putObjectResult = executorService.submit(new Callable<PutObjectResult>() {
@Override
public PutObjectResult call() throws Exception {
PutObjectResult result;
try {
// the putObject call automatically closes the input
// stream afterwards.
result = writeOperationHelper.putObject(putObjectRequest);
} finally {
closeAll(LOG, uploadData, block);
}
return result;
}
});
clearActiveBlock();
// wait for completion
try {
putObjectResult.get();
} catch (InterruptedException ie) {
LOG.warn("Interrupted object upload", ie);
Thread.currentThread().interrupt();
} catch (ExecutionException ee) {
throw extractException("regular upload", key, ee);
}
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project acs-aem-commons by Adobe-Consulting-Services.
the class S3AssetIngestorTest method testCreateFoldersWithBasePath.
@Test
public void testCreateFoldersWithBasePath() throws Exception {
ingestor.s3BasePath = "a/";
ingestor.init();
s3Client.putObject(TEST_BUCKET, "image.png", getClass().getResourceAsStream("/img/test.png"), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "a/image.png", getClass().getResourceAsStream("/img/test.png"), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "a/folder1/", new ByteArrayInputStream(new byte[0]), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "a/folder1/image.png", getClass().getResourceAsStream("/img/test.png"), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "a/folder2/", new ByteArrayInputStream(new byte[0]), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "a/folder2/folder3/", new ByteArrayInputStream(new byte[0]), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "a/folder2/folder3/image.png", getClass().getResourceAsStream("/img/test.png"), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "b/image.png", getClass().getResourceAsStream("/img/test.png"), new ObjectMetadata());
ingestor.createFolders(actionManager);
assertFalse(context.resourceResolver().hasChanges());
assertEquals(3, ingestor.folderCount.get());
assertNotNull(context.resourceResolver().getResource("/content/dam/folder1"));
assertNotNull(context.resourceResolver().getResource("/content/dam/folder2"));
assertNotNull(context.resourceResolver().getResource("/content/dam/folder2/folder3"));
verify(actionManager, times(4)).setCurrentItem(currentItemCaptor.capture());
assertEquals(Arrays.asList("testbucket:a/", "testbucket:a/folder1/", "testbucket:a/folder2/", "testbucket:a/folder2/folder3/"), currentItemCaptor.getAllValues());
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project acs-aem-commons by Adobe-Consulting-Services.
the class S3AssetIngestorTest method testImportAssetsWithBucketContainingJustFolders.
@Test
public void testImportAssetsWithBucketContainingJustFolders() throws Exception {
ingestor.init();
s3Client.putObject(TEST_BUCKET, "folder1/", new ByteArrayInputStream(new byte[0]), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "folder2/", new ByteArrayInputStream(new byte[0]), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "folder2/folder3/", new ByteArrayInputStream(new byte[0]), new ObjectMetadata());
ingestor.importAssets(actionManager);
assertFalse(context.resourceResolver().hasChanges());
assertFalse(context.resourceResolver().getResource("/content/dam").hasChildren());
verify(actionManager).setCurrentItem(currentItemCaptor.capture());
assertEquals(1, currentItemCaptor.getAllValues().size());
assertEquals(TEST_BUCKET, currentItemCaptor.getValue());
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project acs-aem-commons by Adobe-Consulting-Services.
the class S3AssetIngestorTest method testImportAssetsWithBasePath.
@Test
public void testImportAssetsWithBasePath() throws Exception {
ingestor.s3BasePath = "folder2/";
ingestor.init();
s3Client.putObject(TEST_BUCKET, "image.png", getClass().getResourceAsStream("/img/test.png"), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "folder1/", new ByteArrayInputStream(new byte[0]), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "folder1/image.png", getClass().getResourceAsStream("/img/test.png"), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "folder2/", new ByteArrayInputStream(new byte[0]), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "folder2/folder3/", new ByteArrayInputStream(new byte[0]), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "folder2/folder3/image.png", getClass().getResourceAsStream("/img/test.png"), new ObjectMetadata());
ingestor.importAssets(actionManager);
assertFalse(context.resourceResolver().hasChanges());
assertEquals(1, ingestor.assetCount.get());
assertEquals(1, ingestor.folderCount.get());
assertEquals(FILE_SIZE, ingestor.totalImportedData.get());
verify(assetManager, times(1)).createAsset(assetPathCaptor.capture(), any(), any(), eq(false));
assertEquals("/content/dam/folder3/image.png", assetPathCaptor.getValue());
verify(actionManager, times(2)).setCurrentItem(currentItemCaptor.capture());
assertEquals(Arrays.asList("testbucket:folder2/", "testbucket:folder2/folder3/image.png"), currentItemCaptor.getAllValues());
}
use of com.talend.shaded.com.amazonaws.services.s3.model.ObjectMetadata in project acs-aem-commons by Adobe-Consulting-Services.
the class S3AssetIngestorTest method testCreateFolders.
@Test
public void testCreateFolders() throws Exception {
ingestor.init();
s3Client.putObject(TEST_BUCKET, "image.png", getClass().getResourceAsStream("/img/test.png"), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "folder1/", new ByteArrayInputStream(new byte[0]), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "folder1/image.png", getClass().getResourceAsStream("/img/test.png"), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "folder2/", new ByteArrayInputStream(new byte[0]), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "folder2/folder3/", new ByteArrayInputStream(new byte[0]), new ObjectMetadata());
s3Client.putObject(TEST_BUCKET, "folder2/folder3/image.png", getClass().getResourceAsStream("/img/test.png"), new ObjectMetadata());
ingestor.createFolders(actionManager);
assertFalse(context.resourceResolver().hasChanges());
assertEquals(3, ingestor.folderCount.get());
assertNotNull(context.resourceResolver().getResource("/content/dam/folder1"));
assertNotNull(context.resourceResolver().getResource("/content/dam/folder2"));
assertNotNull(context.resourceResolver().getResource("/content/dam/folder2/folder3"));
verify(actionManager, times(4)).setCurrentItem(currentItemCaptor.capture());
assertEquals(Arrays.asList("testbucket", "testbucket:folder1/", "testbucket:folder2/", "testbucket:folder2/folder3/"), currentItemCaptor.getAllValues());
}
Aggregations