Example usage for com.amazonaws.services.s3.model CannedAccessControlList toString

List of usage examples for com.amazonaws.services.s3.model CannedAccessControlList toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns the Amazon S3 x-amz-acl header value for this canned acl.

Usage

From source file:com.mindtree.maven.S3Mojo.java

License:Apache License

private void createBucketAndUploadFiles() throws MojoExecutionException {
    for (int i = 0; i < bucketNames.length; i++) {
        String path = bucketNames[i];
        int index = path.indexOf("/");
        logger.debug("Got index of / : " + index);
        logger.debug("Trying upload for files with path : " + path);
        // The path to upload can have subdirectories hence only the first
        // directory (root) is required
        String rootBucket = path;
        if (index == 0) {
            logger.debug("Unique name bucket creation is required");
            rootBucket = UNIQUE;//w  w  w  . j  a  v a  2 s.co m
        } else if (index != -1) {
            logger.debug("Given name bucket creation is required");
            rootBucket = rootBucket.substring(0, index);
        }
        Bucket bucket = createS3Bucket(rootBucket);
        if (bucket != null) {
            List<File> fileList = mapFiles.get(path);
            logger.debug("Got fileList as null :: " + (fileList == null));
            if (fileList != null) {
                logger.debug("Size of fileList :" + fileList.size());
            }
            CannedAccessControlList cacl = CannedAccessControlList.Private;
            if (accessControls[i].equalsIgnoreCase(CannedAccessControlList.AuthenticatedRead.toString())) {
                cacl = CannedAccessControlList.AuthenticatedRead;
            } else if (accessControls[i]
                    .equalsIgnoreCase(CannedAccessControlList.BucketOwnerFullControl.toString())) {
                cacl = CannedAccessControlList.BucketOwnerFullControl;
            } else if (accessControls[i].equalsIgnoreCase(CannedAccessControlList.BucketOwnerRead.toString())) {
                cacl = CannedAccessControlList.BucketOwnerRead;
            } else if (accessControls[i]
                    .equalsIgnoreCase(CannedAccessControlList.LogDeliveryWrite.toString())) {
                cacl = CannedAccessControlList.LogDeliveryWrite;
            } else if (accessControls[i].equalsIgnoreCase(CannedAccessControlList.Private.toString())) {
                cacl = CannedAccessControlList.Private;
            } else if (accessControls[i].equalsIgnoreCase(CannedAccessControlList.PublicRead.toString())) {
                cacl = CannedAccessControlList.PublicRead;
            } else if (accessControls[i].equalsIgnoreCase(CannedAccessControlList.PublicReadWrite.toString())) {
                cacl = CannedAccessControlList.PublicReadWrite;
            }
            String bucketName = bucket.getName() + bucketNames[i].substring(bucketNames[i].indexOf("/"));
            logger.debug("File to upload to :" + bucketName);
            if (fileList != null && fileList.size() > 0) {
                if (!retainFolderStructure) {
                    logger.debug("Not retaining folder structure and uploadinf files");
                    System.out.println(cacl.toString());
                    List<PutObjectResult> fileUploadResults = S3Helper.uploadFiles(fileList, bucketName, s3,
                            cacl);
                } else {
                    logger.debug("Uploading with retained dir structure");
                    List<PutObjectResult> fileUploadResults = S3Helper.uploadFiles(fileList, bucketName, s3,
                            cacl, root);
                }
            }
        }
    }
}

From source file:org.elasticsearch.repositories.s3.S3BlobStore.java

License:Apache License

/**
 * Constructs canned acl from string// w w  w.  j av  a2  s  .  c o  m
 */
public static CannedAccessControlList initCannedACL(String cannedACL) {
    if (cannedACL == null || cannedACL.equals("")) {
        return CannedAccessControlList.Private;
    }

    for (CannedAccessControlList cur : CannedAccessControlList.values()) {
        if (cur.toString().equalsIgnoreCase(cannedACL)) {
            return cur;
        }
    }

    throw new BlobStoreException("cannedACL is not valid: [" + cannedACL + "]");
}