Example usage for com.amazonaws.services.s3.model CopyObjectResult getLastModifiedDate

List of usage examples for com.amazonaws.services.s3.model CopyObjectResult getLastModifiedDate

Introduction

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

Prototype

public Date getLastModifiedDate() 

Source Link

Document

Gets the date the newly copied object was last modified.

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 {/*w  w  w  . java  2 s .  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;

}