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

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

Introduction

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

Prototype

@Override
    public String getVersionId() 

Source Link

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  w w. jav  a 2s  .  c  om
        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;

}

From source file:io.konig.camel.aws.s3.DeleteObjectProducer.java

License:Apache License

private void copyObject(AmazonS3 s3Client, Exchange exchange) {
    String bucketNameDestination;
    String destinationKey;/*from   w w  w . j  a  va 2s. c om*/
    String sourceKey;
    String bucketName;
    String versionId;

    bucketName = exchange.getIn().getHeader(S3Constants.BUCKET_NAME, String.class);
    if (ObjectHelper.isEmpty(bucketName)) {
        bucketName = getConfiguration().getBucketName();
    }
    sourceKey = exchange.getIn().getHeader(S3Constants.KEY, String.class);
    destinationKey = exchange.getIn().getHeader(S3Constants.DESTINATION_KEY, String.class);
    bucketNameDestination = exchange.getIn().getHeader(S3Constants.BUCKET_DESTINATION_NAME, String.class);
    versionId = exchange.getIn().getHeader(S3Constants.VERSION_ID, String.class);

    if (ObjectHelper.isEmpty(bucketName)) {
        throw new IllegalArgumentException("Bucket Name must be specified for copyObject Operation");
    }
    if (ObjectHelper.isEmpty(bucketNameDestination)) {
        throw new IllegalArgumentException(
                "Bucket Name Destination must be specified for copyObject Operation");
    }
    if (ObjectHelper.isEmpty(sourceKey)) {
        throw new IllegalArgumentException("Source Key must be specified for copyObject Operation");
    }
    if (ObjectHelper.isEmpty(destinationKey)) {
        throw new IllegalArgumentException("Destination Key must be specified for copyObject Operation");
    }
    CopyObjectRequest copyObjectRequest;
    if (ObjectHelper.isEmpty(versionId)) {
        copyObjectRequest = new CopyObjectRequest(bucketName, sourceKey, bucketNameDestination, destinationKey);
    } else {
        copyObjectRequest = new CopyObjectRequest(bucketName, sourceKey, versionId, bucketNameDestination,
                destinationKey);
    }

    if (getConfiguration().isUseAwsKMS()) {
        SSEAwsKeyManagementParams keyManagementParams;
        if (ObjectHelper.isNotEmpty(getConfiguration().getAwsKMSKeyId())) {
            keyManagementParams = new SSEAwsKeyManagementParams(getConfiguration().getAwsKMSKeyId());
        } else {
            keyManagementParams = new SSEAwsKeyManagementParams();
        }
        copyObjectRequest.setSSEAwsKeyManagementParams(keyManagementParams);
    }

    CopyObjectResult copyObjectResult = s3Client.copyObject(copyObjectRequest);

    Message message = getMessageForResponse(exchange);
    message.setHeader(S3Constants.E_TAG, copyObjectResult.getETag());
    if (copyObjectResult.getVersionId() != null) {
        message.setHeader(S3Constants.VERSION_ID, copyObjectResult.getVersionId());
    }
}