Skip to content

Commit 961ec14

Browse files
committed
Add support for S3Object getObjectMetadata transform
1 parent 7a1f13b commit 961ec14

7 files changed

Lines changed: 44 additions & 12 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "bugfix",
3+
"category": "AWS SDK for Java v2 Migration Tool",
4+
"contributor": "",
5+
"description": "Add support for S3Object getObjectMetadata transform"
6+
}

test/v2-migration-tests/src/test/resources/software/amazon/awssdk/v2migrationtests/maven/after/src/main/java/foo/bar/S3Streaming.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ void getObject(String bucket, String key, File file) throws Exception {
4343
.build());
4444
s3Object.close();
4545

46+
String cacheControl = s3Object.response().cacheControl();
47+
4648
GetObjectResponse objectMetadata = s3.getObject(GetObjectRequest.builder().bucket(bucket).key(key)
4749
.build(), file.toPath());
4850
}

test/v2-migration-tests/src/test/resources/software/amazon/awssdk/v2migrationtests/maven/after/src/main/java/foo/bar/SdkClientsDependencyFactory.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,17 @@ public static ClientOverrideConfiguration customClientConfiguration() {
4848

4949
public static SqsClient sqsClientWithAllSettings() {
5050
return SqsClient.builder()
51-
.region(Region.of("us-west-2"))
52-
.httpClientBuilder(ApacheHttpClient.builder()
53-
.connectionMaxIdleTime(Duration.ofMillis(1006))
54-
.tcpKeepAlive(true)
55-
.socketTimeout(Duration.ofMillis(1004))
56-
.connectionTimeToLive(Duration.ofMillis(1005))
57-
.connectionTimeout(Duration.ofMillis(1003))
58-
.maxConnections(1002))
59-
.overrideConfiguration(customClientConfiguration())
51+
.region(Region.of("us-west-2"))
52+
.httpClientBuilder(ApacheHttpClient.builder()
53+
.connectionMaxIdleTime(Duration.ofMillis(1006))
54+
.tcpKeepAlive(true)
55+
.socketTimeout(Duration.ofMillis(1004))
56+
.connectionTimeToLive(Duration.ofMillis(1005))
57+
.connectionTimeout(Duration.ofMillis(1003))
58+
.maxConnections(1002))
59+
.overrideConfiguration(customClientConfiguration())
6060
.credentialsProvider(CredentialsDependencyFactory.defaultCredentialsProviderChain())
61-
.build();
61+
.build();
6262
}
6363

6464
public static SqsClientBuilder sqsClientBuilder() {
@@ -90,6 +90,6 @@ public static SqsAsyncClient sqsAsyncClientWithAllSettings() {
9090
.httpClientBuilder(NettyNioAsyncHttpClient.builder()
9191
.connectionTimeout(Duration.ofMillis(2004)))
9292
.overrideConfiguration(clientConfiguration)
93-
.build();
93+
.build();
9494
}
9595
}

test/v2-migration-tests/src/test/resources/software/amazon/awssdk/v2migrationtests/maven/before/src/main/java/foo/bar/S3Streaming.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ void getObject(String bucket, String key, File file) throws Exception {
4040
S3Object s3Object = s3.getObject(bucket, key);
4141
s3Object.getObjectContent().close();
4242

43+
String cacheControl = s3Object.getObjectMetadata().getCacheControl();
44+
4345
ObjectMetadata objectMetadata = s3.getObject(new GetObjectRequest(bucket, key), file);
4446
}
4547

v2-migration/src/main/java/software/amazon/awssdk/v2migration/S3PojoToV2.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,12 +73,14 @@ public J visitNewClass(J.NewClass newClass, ExecutionContext executionContext) {
7373
params.get(0), params.get(1), params.get(2), params.get(3));
7474
}
7575
if (type.isAssignableFrom(OBJECT_TAGGING) && newClass.getArguments().size() == 1) {
76+
addV2S3ModelImport("Tagging");
7677
String v2Builder = "Tagging.builder().tagSet(#{any()}).build();";
7778
return JavaTemplate.builder(v2Builder)
7879
.build().apply(getCursor(), newClass.getCoordinates().replace(),
7980
newClass.getArguments().get(0));
8081
}
8182
if (type.isAssignableFrom(GET_OBJECT_TAGGING_RESULT) && newClass.getArguments().size() == 1) {
83+
addV2S3ModelImport("GetObjectTaggingResponse");
8284
String v2Builder = "GetObjectTaggingResponse.builder().tagSet(#{any()}).build();";
8385
return JavaTemplate.builder(v2Builder)
8486
.build().apply(getCursor(), newClass.getCoordinates().replace(),

v2-migration/src/main/java/software/amazon/awssdk/v2migration/S3PutObjectRequestToV2.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import static software.amazon.awssdk.v2migration.internal.utils.S3TransformUtils.getArgumentName;
2525
import static software.amazon.awssdk.v2migration.internal.utils.S3TransformUtils.getSelectName;
2626
import static software.amazon.awssdk.v2migration.internal.utils.S3TransformUtils.inputStreamBufferingWarningComment;
27+
import static software.amazon.awssdk.v2migration.internal.utils.S3TransformUtils.isObjectMetadataGetter;
2728
import static software.amazon.awssdk.v2migration.internal.utils.S3TransformUtils.isObjectMetadataSetter;
2829
import static software.amazon.awssdk.v2migration.internal.utils.S3TransformUtils.isPayloadSetter;
2930
import static software.amazon.awssdk.v2migration.internal.utils.S3TransformUtils.isPutObjectRequestBuilderSetter;
@@ -95,6 +96,11 @@ public J visitMethodInvocation(J.MethodInvocation method, ExecutionContext ctx)
9596
if (isObjectMetadataSetter(method)) {
9697
return saveMetadataValueAndRemoveStatement(method);
9798
}
99+
if (isObjectMetadataGetter(method)) {
100+
if (method.getSelect() != null) {
101+
return method.getSelect().withPrefix(method.getPrefix());
102+
}
103+
}
98104

99105
if (isPutObjectRequestBuilderSetter(method)) {
100106
if (isRequestMetadataSetter(method)) {

v2-migration/src/main/java/software/amazon/awssdk/v2migration/internal/utils/S3TransformUtils.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,20 @@ public static boolean isObjectMetadataSetter(J.MethodInvocation method) {
207207
return isSetterForClassType(method, V2_S3_MODEL_PKG + "HeadObjectResponse");
208208
}
209209

210+
public static boolean isObjectMetadataGetter(J.MethodInvocation method) {
211+
if (!"objectMetadata".equals(method.getSimpleName()) || hasArguments(method)) {
212+
return false;
213+
}
214+
215+
Expression select = method.getSelect();
216+
if (!(select instanceof J.MethodInvocation)) {
217+
return false;
218+
}
219+
220+
J.MethodInvocation receiverMethod = (J.MethodInvocation) select;
221+
return "response".equals(receiverMethod.getSimpleName());
222+
}
223+
210224
/** Field set during POJO instantiation, e.g.,
211225
* PutObjectRequest request = new PutObjectRequest("bucket" "key", "redirectLocation").withFile(file);
212226
*/
@@ -236,7 +250,7 @@ public static boolean isSetterForClassType(J.MethodInvocation method, String fqc
236250
}
237251

238252
public static boolean hasArguments(J.MethodInvocation method) {
239-
return !method.getArguments().isEmpty();
253+
return method.getArguments().stream().anyMatch(arg -> !(arg instanceof J.Empty));
240254
}
241255

242256
public static boolean isPayloadSetter(J.MethodInvocation method) {

0 commit comments

Comments
 (0)