use of software.amazon.awssdk.services.s3.model.ListObjectVersionsResponse in project formkiq-core by formkiq.
the class DocumentVersionsRequestHandler method get.
@Override
public ApiRequestHandlerResponse get(final LambdaLogger logger, final ApiGatewayRequestEvent event, final ApiAuthorizer authorizer, final AwsServiceCache awsservice) throws Exception {
SimpleDateFormat df = new SimpleDateFormat(GsonUtil.DATE_FORMAT);
String siteId = authorizer.getSiteId();
String documentId = event.getPathParameters().get("documentId");
String next = getParameter(event, "next");
String tz = getParameter(event, "tz");
ZoneOffset offset = DateUtil.getZoneOffset(tz);
df.setTimeZone(TimeZone.getTimeZone(offset));
String s3key = createDatabaseKey(siteId, documentId);
S3Service s3service = awsservice.s3Service();
try (S3Client s3 = s3service.buildClient()) {
ListObjectVersionsResponse response = s3service.getObjectVersions(s3, awsservice.documents3bucket(), s3key, next);
List<ApiDocumentVersion> list = response.versions().stream().map(v -> {
ApiDocumentVersion dv = new ApiDocumentVersion();
dv.setVersionId(v.versionId());
Date date = Date.from(v.lastModified());
dv.setLastModifiedDate(df.format(date));
return dv;
}).collect(Collectors.toList());
ApiDocumentVersionsResponse resp = new ApiDocumentVersionsResponse();
resp.setNext(response.nextKeyMarker());
resp.setVersions(list);
return new ApiRequestHandlerResponse(SC_OK, resp);
}
}
use of software.amazon.awssdk.services.s3.model.ListObjectVersionsResponse in project aws-sdk-java-v2 by aws.
the class S3IntegrationTestBase method deleteBucketAndAllContents.
protected static void deleteBucketAndAllContents(String bucketName) {
System.out.println("Deleting S3 bucket: " + bucketName);
ListObjectsResponse response = s3.listObjects(ListObjectsRequest.builder().bucket(bucketName).build());
while (true) {
if (response.contents() == null) {
break;
}
for (S3Object objectSummary : response.contents()) {
s3.deleteObject(DeleteObjectRequest.builder().bucket(bucketName).key(objectSummary.key()).build());
}
if (response.isTruncated()) {
response = s3.listObjects(ListObjectsRequest.builder().marker(response.nextMarker()).build());
} else {
break;
}
}
ListObjectVersionsResponse versionsResponse = s3.listObjectVersions(ListObjectVersionsRequest.builder().bucket(bucketName).build());
if (versionsResponse.versions() != null) {
for (ObjectVersion s : versionsResponse.versions()) {
s3.deleteObject(DeleteObjectRequest.builder().bucket(bucketName).key(s.key()).versionId(s.versionId()).build());
}
}
s3.deleteBucket(DeleteBucketRequest.builder().bucket(bucketName).build());
}
use of software.amazon.awssdk.services.s3.model.ListObjectVersionsResponse in project aws-sdk-java-v2 by aws.
the class CloudTrailIntegrationTest method deleteBucketAndAllContents.
public static void deleteBucketAndAllContents(String bucketName) {
System.out.println("Deleting S3 bucket: " + bucketName);
ListObjectsResponse response = s3.listObjects(ListObjectsRequest.builder().bucket(bucketName).build());
while (true) {
if (response.contents() == null) {
break;
}
for (Iterator<?> iterator = response.contents().iterator(); iterator.hasNext(); ) {
S3Object objectSummary = (S3Object) iterator.next();
s3.deleteObject(DeleteObjectRequest.builder().bucket(bucketName).key(objectSummary.key()).build());
}
if (response.isTruncated()) {
response = s3.listObjects(ListObjectsRequest.builder().marker(response.nextMarker()).build());
} else {
break;
}
}
ListObjectVersionsResponse versionsResponse = s3.listObjectVersions(ListObjectVersionsRequest.builder().bucket(bucketName).build());
if (versionsResponse.versions() != null) {
for (ObjectVersion s : versionsResponse.versions()) {
s3.deleteObject(DeleteObjectRequest.builder().bucket(bucketName).key(s.key()).versionId(s.versionId()).build());
}
}
s3.deleteBucket(DeleteBucketRequest.builder().bucket(bucketName).build());
}
use of software.amazon.awssdk.services.s3.model.ListObjectVersionsResponse in project aws-sdk-java-v2 by aws.
the class DecodeUrlEncodedResponseInterceptorTest method encodingTypeSet_decodesListObjectVersionsResponse.
@Test
public void encodingTypeSet_decodesListObjectVersionsResponse() {
Context.ModifyResponse ctx = newContext(TEST_LIST_OBJECT_VERSION_RESPONSE);
ListObjectVersionsResponse decoded = (ListObjectVersionsResponse) INTERCEPTOR.modifyResponse(ctx, new ExecutionAttributes());
assertDecoded(decoded::delimiter, " delimiter");
assertDecoded(decoded::prefix, " prefix");
assertDecoded(decoded::keyMarker, " keyMarker");
assertDecoded(decoded::nextKeyMarker, " nextKeyMarker");
assertCommonPrefixesAreDecoded(decoded.commonPrefixes());
assertVersionsAreDecoded(decoded.versions());
}
use of software.amazon.awssdk.services.s3.model.ListObjectVersionsResponse in project aws-sdk-java-v2 by aws.
the class UrlEncodingIntegrationTest method listObjectWithUrlEncodingType_shouldDecode.
@Test
public void listObjectWithUrlEncodingType_shouldDecode() {
ListObjectsResponse listObjectsV2Response = s3.listObjects(b -> b.bucket(BUCKET_NAME).encodingType(EncodingType.URL));
listObjectsV2Response.contents().forEach(c -> assertKeyIsDecoded(c.key()));
ListObjectVersionsResponse asyncResponse = s3Async.listObjectVersions(b -> b.bucket(BUCKET_NAME).encodingType(EncodingType.URL)).join();
asyncResponse.versions().forEach(v -> assertKeyIsDecoded(v.key()));
}
Aggregations