Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"type": "bugfix",
"category": "AWS SDK for Java v2 Migration Tool",
"contributor": "",
"description": "Fix bug for v1 getUserMetaDataOf transform"
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ void getObject(String bucket, String key, File file) throws Exception {

String etag = /*AWS SDK for Java v2 migration: NOTE: V2's eTag() preserves surrounding quotes in the response, whereas V1's getETag() strips them - https://docs.aws.amazon.com/sdk-for-java/latest/developer-guide/migration-s3-client.html#V1s-ObjectMetadata-using-V1s-getETag*/
objectMetadata.eTag().replaceAll("^\"|\"$", "");

String value = s3Object.response().metadata().get("key");
}

void putObject_bucketKeyContent(String bucket, String key, String content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ void getObject(String bucket, String key, File file) throws Exception {
ObjectMetadata objectMetadata = s3.getObject(new GetObjectRequest(bucket, key), file);

String etag = objectMetadata.getETag();

String value = s3Object.getObjectMetadata().getUserMetaDataOf("key");
}

void putObject_bucketKeyContent(String bucket, String key, String content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,9 @@ private Expression retrieveContentLengthForMetadataIfSet(String metadataName) {
}

private J.MethodInvocation saveMetadataValueAndRemoveStatement(J.MethodInvocation method) {
if (!(method.getSelect() instanceof J.Identifier)) {
return method;
}
J.Identifier metadataPojo = (J.Identifier) method.getSelect();
String variableName = metadataPojo.getSimpleName();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

import static software.amazon.awssdk.v2migration.internal.utils.S3TransformUtils.changeBucketNameToBucket;
import static software.amazon.awssdk.v2migration.internal.utils.S3TransformUtils.isS3ETagGetter;
import static software.amazon.awssdk.v2migration.internal.utils.S3TransformUtils.isS3UserMetaDataOfGetter;
import static software.amazon.awssdk.v2migration.internal.utils.S3TransformUtils.transformETagGetter;
import static software.amazon.awssdk.v2migration.internal.utils.S3TransformUtils.transformUserMetaDataOfGetter;
import static software.amazon.awssdk.v2migration.internal.utils.SdkTypeUtils.isV2ModelClass;

import org.openrewrite.ExecutionContext;
Expand Down Expand Up @@ -69,6 +71,10 @@ public J.MethodInvocation visitMethodInvocation(J.MethodInvocation method, Execu
return transformETagGetter(getCursor(), method);
}

if (isS3UserMetaDataOfGetter(methodName, fullyQualified)) {
return transformUserMetaDataOfGetter(getCursor(), method);
}

methodName = changeBucketNameToBucket(methodName);

if (NamingUtils.isGetter(methodName)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,18 @@ public static J.MethodInvocation transformETagGetter(Cursor cursor, J.MethodInvo
.withComments(createCommentsWithNewline(comment));
}

public static boolean isS3UserMetaDataOfGetter(String methodName, JavaType.FullyQualified declaringType) {
return "getUserMetaDataOf".equals(methodName)
&& declaringType.getFullyQualifiedName().startsWith(V2_S3_MODEL_PKG);
}

public static J.MethodInvocation transformUserMetaDataOfGetter(Cursor cursor, J.MethodInvocation method) {
String template = "#{any()}.metadata().get(#{any()})";
return JavaTemplate.builder(template).build()
.apply(cursor, method.getCoordinates().replace(),
method.getSelect(), method.getArguments().get(0));
}

public static List<Comment> inputStreamBufferingWarningComment() {
String warning = "When using InputStream to upload with S3Client, Content-Length should be specified and used "
+ "with RequestBody.fromInputStream(). Otherwise, the entire stream will be buffered in memory. If"
Expand Down
Loading