Example usage for com.amazonaws.services.s3.model VersionListing getMaxKeys

List of usage examples for com.amazonaws.services.s3.model VersionListing getMaxKeys

Introduction

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

Prototype

public int getMaxKeys() 

Source Link

Document

Gets the value of the maxKeys parameter used to request this version listing.

Usage

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

License:Open Source License

@Override
public ListVersionsResponseType listVersions(ListVersionsType request) throws S3Exception {
    ListVersionsResponseType reply = request.getReply();
    User requestUser = getRequestUser(request);
    OsgInternalS3Client internalS3Client = null;

    try {/*from  www. j  av a2s. c  om*/
        internalS3Client = getS3Client(requestUser);
        AmazonS3Client s3Client = internalS3Client.getS3Client();
        ListVersionsRequest listVersionsRequest = new ListVersionsRequest(request.getBucket(),
                request.getPrefix(), request.getKeyMarker(), request.getVersionIdMarker(),
                request.getDelimiter(), Integer.parseInt(request.getMaxKeys()));
        VersionListing result = s3Client.listVersions(listVersionsRequest);

        CanonicalUser owner;
        try {
            owner = AclUtils.buildCanonicalUser(requestUser.getAccount());
        } catch (AuthException e) {
            LOG.error("Error getting request user's account during bucket version listing", e);
            owner = null;
            throw new AccountProblemException("Account for user " + requestUser.getUserId());
        }

        //Populate result to euca
        reply.setBucket(request.getBucket());
        reply.setMaxKeys(result.getMaxKeys());
        reply.setDelimiter(result.getDelimiter());
        reply.setNextKeyMarker(result.getNextKeyMarker());
        reply.setNextVersionIdMarker(result.getNextVersionIdMarker());
        reply.setIsTruncated(result.isTruncated());
        reply.setVersionIdMarker(result.getVersionIdMarker());
        reply.setKeyMarker(result.getKeyMarker());

        if (result.getCommonPrefixes() != null && result.getCommonPrefixes().size() > 0) {
            reply.setCommonPrefixesList(new ArrayList<CommonPrefixesEntry>());

            for (String s : result.getCommonPrefixes()) {
                reply.getCommonPrefixesList().add(new CommonPrefixesEntry(s));
            }
        }

        ArrayList<KeyEntry> versions = new ArrayList<>();
        VersionEntry v;
        DeleteMarkerEntry d;
        for (S3VersionSummary summary : result.getVersionSummaries()) {
            if (!summary.isDeleteMarker()) {
                v = new VersionEntry();
                v.setKey(summary.getKey());
                v.setVersionId(summary.getVersionId());
                v.setLastModified(DateFormatter.dateToHeaderFormattedString(summary.getLastModified()));
                v.setEtag(summary.getETag());
                v.setIsLatest(summary.isLatest());
                v.setOwner(owner);
                v.setSize(summary.getSize());
                versions.add(v);
            } else {
                d = new DeleteMarkerEntry();
                d.setIsLatest(summary.isLatest());
                d.setKey(summary.getKey());
                d.setLastModified(DateFormatter.dateToHeaderFormattedString(summary.getLastModified()));
                d.setOwner(owner);
                d.setVersionId(summary.getVersionId());
                versions.add(d);
            }
        }
        //Again, this is wrong, should be a single listing
        reply.setKeyEntries(versions);
    } catch (AmazonServiceException e) {
        LOG.debug("Error from backend", e);
        throw S3ExceptionMapper.fromAWSJavaSDK(e);
    }

    return reply;
}