request.setTagging(new ObjectTagging(getObjectTags(context, flowFileCopy)));
tagList.add(new Tag(tagParts[0], tagParts[1])); putObjectRequest.setTagging(new ObjectTagging(tagList)); } catch (Exception exception) { LOGGER.error("Error in passing the object tags as request headers.", exception);
tagList.add(new Tag(tagParts[0], tagParts[1])); putObjectRequest.setTagging(new ObjectTagging(tagList)); } catch (Exception exception) { LOGGER.error("Error in passing the object tags as request headers.", exception);
@Override protected void doPut(String fullPath, ISObject stuff, Map<String, String> attrs) { ObjectMetadata meta = new ObjectMetadata(); meta.setContentType(stuff.getAttribute(ISObject.ATTR_CONTENT_TYPE)); if (!(stuff instanceof SObject.InputStreamSObject)) { long length = stuff.getLength(); if (0 < length) { meta.setContentLength(stuff.getLength()); } } PutObjectRequest req = new PutObjectRequest(bucket, fullPath, stuff.asInputStream(), meta); req.setTagging(mapToTagList(attrs)); StorageClass storageClass = StorageClass.valueOfIgnoreCase(attrs.remove(ATTR_STORAGE_CLASS), defStorageClass); if (null != storageClass) { req.setStorageClass(storageClass.toString()); } req.withCannedAcl(CannedAccessControlList.PublicRead); s3.putObject(req); }
@Test public void testTagObjectsTargetTagKeyAlreadyExists() { // Create two S3 object tags having the same tag key. List<Tag> tags = Arrays.asList(new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE), new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE_2)); // Put a file in S3 that is already tagged with the first S3 object tag. PutObjectRequest putObjectRequest = new PutObjectRequest(S3_BUCKET_NAME, TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), new ObjectMetadata()); putObjectRequest.setTagging(new ObjectTagging(Collections.singletonList(tags.get(0)))); s3Operations.putObject(putObjectRequest, null); // Validate that the S3 object is tagged with the first tag. GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, TARGET_S3_KEY), null); assertEquals(Collections.singletonList(tags.get(0)), getObjectTaggingResult.getTagSet()); // Create an S3 file transfer request parameters DTO to access S3 objects. S3FileTransferRequestParamsDto params = new S3FileTransferRequestParamsDto(); params.setS3BucketName(S3_BUCKET_NAME); // Create an S3 object summary. S3ObjectSummary s3ObjectSummary = new S3ObjectSummary(); s3ObjectSummary.setKey(TARGET_S3_KEY); // Tag the S3 file with the second S3 object tag. s3Dao.tagObjects(params, new S3FileTransferRequestParamsDto(), Collections.singletonList(s3ObjectSummary), tags.get(1)); // Validate that the S3 object is tagged with the second tag now. getObjectTaggingResult = s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, TARGET_S3_KEY), null); assertEquals(Collections.singletonList(tags.get(1)), getObjectTaggingResult.getTagSet()); }
@Test public void testTagObjectsOtherTagKeyAlreadyExists() { // Create two S3 object tags having different tag keys. List<Tag> tags = Arrays.asList(new Tag(S3_OBJECT_TAG_KEY, S3_OBJECT_TAG_VALUE), new Tag(S3_OBJECT_TAG_KEY_2, S3_OBJECT_TAG_VALUE_2)); // Put a file in S3 that is already tagged with the first S3 object tag. PutObjectRequest putObjectRequest = new PutObjectRequest(S3_BUCKET_NAME, TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), new ObjectMetadata()); putObjectRequest.setTagging(new ObjectTagging(Collections.singletonList(tags.get(0)))); s3Operations.putObject(putObjectRequest, null); // Validate that the S3 object is tagged with the first tag only. GetObjectTaggingResult getObjectTaggingResult = s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, TARGET_S3_KEY), null); assertEquals(Collections.singletonList(tags.get(0)), getObjectTaggingResult.getTagSet()); // Create an S3 file transfer request parameters DTO to access S3 objects. S3FileTransferRequestParamsDto params = new S3FileTransferRequestParamsDto(); params.setS3BucketName(S3_BUCKET_NAME); // Create an S3 object summary. S3ObjectSummary s3ObjectSummary = new S3ObjectSummary(); s3ObjectSummary.setKey(TARGET_S3_KEY); // Tag the S3 file with the second S3 object tag. s3Dao.tagObjects(params, new S3FileTransferRequestParamsDto(), Collections.singletonList(s3ObjectSummary), tags.get(1)); // Validate that the S3 object is now tagged with both tags. getObjectTaggingResult = s3Operations.getObjectTagging(new GetObjectTaggingRequest(S3_BUCKET_NAME, TARGET_S3_KEY), null); assertEquals(tags.size(), getObjectTaggingResult.getTagSet().size()); assertTrue(getObjectTaggingResult.getTagSet().containsAll(tags)); }
request.setTagging(new ObjectTagging(getObjectTags(context, flowFileCopy)));
new PutObjectRequest(MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_VERSIONING_ENABLED, TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), new ObjectMetadata()); putObjectRequest.setTagging(new ObjectTagging(Collections.singletonList(tags.get(0)))); s3Operations.putObject(putObjectRequest, null);
new PutObjectRequest(MockS3OperationsImpl.MOCK_S3_BUCKET_NAME_VERSIONING_ENABLED, TARGET_S3_KEY, new ByteArrayInputStream(new byte[1]), new ObjectMetadata()); putObjectRequest.setTagging(new ObjectTagging(Collections.singletonList(tags.get(0)))); s3Operations.putObject(putObjectRequest, null);