@Override public int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + Objects.hashCode(bucket()); hashCode = 31 * hashCode + Objects.hashCode(delete()); hashCode = 31 * hashCode + Objects.hashCode(mfa()); hashCode = 31 * hashCode + Objects.hashCode(requestPayerAsString()); hashCode = 31 * hashCode + Objects.hashCode(bypassGovernanceRetention()); return hashCode; }
@Override public DeleteObjectsRequest build() { return new DeleteObjectsRequest(this); }
/** * <p> * This operation enables you to delete multiple objects from a bucket using a single HTTP request. You may specify * up to 1000 keys. * </p> * <br/> * <p> * This is a convenience which creates an instance of the {@link DeleteObjectsRequest.Builder} avoiding the need to * create one manually via {@link DeleteObjectsRequest#builder()} * </p> * * @param deleteObjectsRequest * A {@link Consumer} that will call methods on {@link DeleteObjectsRequest.Builder} to create a request. * @return Result of the DeleteObjects operation returned by the service. * @throws SdkException * Base class for all exceptions that can be thrown by the SDK (both service and client). Can be used for * catch all scenarios. * @throws SdkClientException * If any client side error occurs such as an IO related failure, failure to get credentials, etc. * @throws S3Exception * Base class for all service exceptions. Unknown exceptions will be thrown as an instance of this type. * @sample S3Client.DeleteObjects */ default DeleteObjectsResponse deleteObjects(Consumer<DeleteObjectsRequest.Builder> deleteObjectsRequest) throws AwsServiceException, SdkClientException, S3Exception { return deleteObjects(DeleteObjectsRequest.builder().applyMutation(deleteObjectsRequest).build()); }
@Override public DeleteObjectsResponse deleteObjects(final DeleteObjectsRequest deleteObjectsRequest) throws S3Exception { final Map<String, BucketItem> bucketItemMap = bucketsWithContents.get(deleteObjectsRequest.bucket()); deleteObjectsRequest.delete().objects() .stream() .map(ObjectIdentifier::key) .forEach(bucketItemMap::remove); return DeleteObjectsResponse.builder().build(); }
/** * <p> * This operation enables you to delete multiple objects from a bucket using a single HTTP request. You may specify * up to 1000 keys. * </p> * <br/> * <p> * This is a convenience which creates an instance of the {@link DeleteObjectsRequest.Builder} avoiding the need to * create one manually via {@link DeleteObjectsRequest#builder()} * </p> * * @param deleteObjectsRequest * A {@link Consumer} that will call methods on {@link DeleteObjectsRequest.Builder} to create a request. * @return A Java Future containing the result of the DeleteObjects operation returned by the service.<br/> * The CompletableFuture returned by this method can be completed exceptionally with the following * exceptions. * <ul> * <li>SdkException Base class for all exceptions that can be thrown by the SDK (both service and client). * Can be used for catch all scenarios.</li> * <li>SdkClientException If any client side error occurs such as an IO related failure, failure to get * credentials, etc.</li> * <li>S3Exception Base class for all service exceptions. Unknown exceptions will be thrown as an instance * of this type.</li> * </ul> * @sample S3AsyncClient.DeleteObjects */ default CompletableFuture<DeleteObjectsResponse> deleteObjects(Consumer<DeleteObjectsRequest.Builder> deleteObjectsRequest) { return deleteObjects(DeleteObjectsRequest.builder().applyMutation(deleteObjectsRequest).build()); }
@Override public boolean equals(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof DeleteObjectsRequest)) { return false; } DeleteObjectsRequest other = (DeleteObjectsRequest) obj; return Objects.equals(bucket(), other.bucket()) && Objects.equals(delete(), other.delete()) && Objects.equals(mfa(), other.mfa()) && Objects.equals(requestPayerAsString(), other.requestPayerAsString()) && Objects.equals(bypassGovernanceRetention(), other.bypassGovernanceRetention()); }
public void deleteAllObjectsWithPrefixInBucket(final String bucketName, final String prefix) { final ListObjectsV2Response listObjectResponse = s3Client.listObjectsV2(ListObjectsV2Request.builder().bucket(bucketName).build()); if (listObjectResponse.keyCount() > 0) { DeleteObjectsRequest deleteObjectsRequest = DeleteObjectsRequest.builder() .bucket(bucketName) .delete(builder() .objects(convertS3ObjectsToObjectIdentifiers(listObjectResponse, prefix)) .build()) .build(); final DeleteObjectsResponse deleteObjectsResponse = s3Client.deleteObjects(deleteObjectsRequest); LOG.debug("deleteAllObjectsWithPrefixInBucket in bucket {} with prefix {}: {}", bucketName, prefix, deleteObjectsResponse); } else { LOG.debug("deleteAllObjectsWithPrefixInBucket listObjects found no keys in bucket {} with prefix {}: {}", bucketName, prefix, listObjectResponse); } }
/** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. */ @Override public String toString() { return ToString.builder("DeleteObjectsRequest").add("Bucket", bucket()).add("Delete", delete()).add("MFA", mfa()) .add("RequestPayer", requestPayerAsString()).add("BypassGovernanceRetention", bypassGovernanceRetention()) .build(); }
@Test public void deleteShouldRemoveItemsFromBucket() { // given PutObjectRequest putObjectRequest = PutObjectRequest.builder() .bucket("someBucket") .key("someObject") .build(); RequestBody requestBody = RequestBody.fromString("content"); testee.putObject(putObjectRequest, requestBody); testee.deleteObjects(DeleteObjectsRequest.builder().bucket("someBucket").delete(Delete.builder().objects (ObjectIdentifier.builder().key("someObject").build()).build()).build()); // when ListObjectsV2Request listObjectsV2Request = ListObjectsV2Request.builder() .bucket("someBucket") .build(); ListObjectsV2Response listObjectsV2Response = testee.listObjectsV2(listObjectsV2Request); //then assertThat(listObjectsV2Response.contents().size(), is(0)); }
public <T> Optional<T> getValueForField(String fieldName, Class<T> clazz) { switch (fieldName) { case "Bucket": return Optional.ofNullable(clazz.cast(bucket())); case "Delete": return Optional.ofNullable(clazz.cast(delete())); case "MFA": return Optional.ofNullable(clazz.cast(mfa())); case "RequestPayer": return Optional.ofNullable(clazz.cast(requestPayerAsString())); case "BypassGovernanceRetention": return Optional.ofNullable(clazz.cast(bypassGovernanceRetention())); default: return Optional.empty(); } }