Example usage for com.amazonaws.services.s3.model CopyObjectRequest setMatchingETagConstraints

List of usage examples for com.amazonaws.services.s3.model CopyObjectRequest setMatchingETagConstraints

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model CopyObjectRequest setMatchingETagConstraints.

Prototype

public void setMatchingETagConstraints(List<String> eTagList) 

Source Link

Document

Sets the optional list of ETag constraints that, when present, must include a match for the source object's current ETag in order for the copy object request to be executed.

Usage

From source file:com.eucalyptus.objectstorage.providers.s3.S3ProviderClient.java

License:Open Source License

@Override
public CopyObjectResponseType copyObject(CopyObjectType request) throws S3Exception {
    CopyObjectResponseType reply = request.getReply();
    User requestUser = getRequestUser(request);
    OsgInternalS3Client internalS3Client = null;

    String sourceBucket = request.getSourceBucket();
    String sourceKey = request.getSourceObject();
    String sourceVersionId = request.getSourceVersionId();
    String destinationBucket = request.getDestinationBucket();
    String destinationKey = request.getDestinationObject();
    String copyIfMatch = request.getCopySourceIfMatch();
    String copyIfNoneMatch = request.getCopySourceIfNoneMatch();
    Date copyIfUnmodifiedSince = request.getCopySourceIfUnmodifiedSince();
    Date copyIfModifiedSince = request.getCopySourceIfModifiedSince();
    try {//from w  ww  .j  a v  a  2s .co m
        CopyObjectRequest copyRequest = new CopyObjectRequest(sourceBucket, sourceKey, sourceVersionId,
                destinationBucket, destinationKey);
        copyRequest.setModifiedSinceConstraint(copyIfModifiedSince);
        copyRequest.setUnmodifiedSinceConstraint(copyIfUnmodifiedSince);
        if (copyIfMatch != null) {
            List<String> copyIfMatchConstraint = new ArrayList<String>();
            copyIfMatchConstraint.add(copyIfMatch);
            copyRequest.setMatchingETagConstraints(copyIfMatchConstraint);
        }
        if (copyIfNoneMatch != null) {
            List<String> copyIfNoneMatchConstraint = new ArrayList<String>();
            copyIfNoneMatchConstraint.add(copyIfNoneMatch);
            copyRequest.setNonmatchingETagConstraints(copyIfNoneMatchConstraint);
        }
        //TODO: Need to set canned ACL if specified
        internalS3Client = getS3Client(requestUser);
        AmazonS3Client s3Client = internalS3Client.getS3Client();
        CopyObjectResult result = s3Client.copyObject(copyRequest);
        reply.setEtag(result.getETag());
        reply.setLastModified(DateFormatter.dateToListingFormattedString(result.getLastModifiedDate()));
        String destinationVersionId = result.getVersionId();
        if (destinationVersionId != null) {
            reply.setCopySourceVersionId(sourceVersionId);
            reply.setVersionId(destinationVersionId);
        }
    } catch (AmazonServiceException e) {
        LOG.debug("Error from backend", e);
        throw S3ExceptionMapper.fromAWSJavaSDK(e);
    }
    return reply;

}