Search in sources :

Example 1 with Decision

use of lucee.runtime.util.Decision in project extension-s3 by lucee.

the class S3 method setMetaData.

public void setMetaData(String bucketName, String objectName, Struct metadata) throws PageException, S3Exception {
    Decision dec = CFMLEngineFactory.getInstance().getDecisionUtil();
    Cast cas = CFMLEngineFactory.getInstance().getCastUtil();
    Iterator<Entry<Key, Object>> it = metadata.entryIterator();
    Entry<Key, Object> e;
    ObjectMetadata metadataCopy = new ObjectMetadata();
    Map<String, String> data = new ConcurrentHashMap<String, String>();
    while (it.hasNext()) {
        e = it.next();
        metadataCopy.addUserMetadata(toMetaDataKey(e.getKey()), cas.toString(e.getValue()));
    }
    bucketName = improveBucketName(bucketName);
    objectName = improveObjectName(objectName);
    if (!Util.isEmpty(objectName)) {
        AmazonS3Client client = getAmazonS3(bucketName, null);
        try {
            S3BucketWrapper bw = get(bucketName);
            if (bw == null)
                throw new S3Exception("there is no bucket [" + bucketName + "]");
            Bucket b = bw.getBucket();
            CopyObjectRequest request = new CopyObjectRequest(bucketName, objectName, bucketName, objectName).withNewObjectMetadata(metadataCopy);
            client.copyObject(request);
            flushExists(bucketName, objectName);
        } finally {
            client.release();
        }
    } else
        // TOOD possible?
        throw new S3Exception("cannot set metadata for a bucket");
}
Also used : Cast(lucee.runtime.util.Cast) S3BucketWrapper(org.lucee.extension.resource.s3.info.S3BucketWrapper) AmazonS3Exception(com.amazonaws.services.s3.model.AmazonS3Exception) Decision(lucee.runtime.util.Decision) Entry(java.util.Map.Entry) AmazonS3Client(org.lucee.extension.resource.s3.pool.AmazonS3Client) CopyObjectRequest(com.amazonaws.services.s3.model.CopyObjectRequest) Bucket(com.amazonaws.services.s3.model.Bucket) ParentObject(org.lucee.extension.resource.s3.info.ParentObject) S3Object(com.amazonaws.services.s3.model.S3Object) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ObjectMetadata(com.amazonaws.services.s3.model.ObjectMetadata) Key(lucee.runtime.type.Collection.Key)

Example 2 with Decision

use of lucee.runtime.util.Decision in project extension-s3 by lucee.

the class AccessControlListUtil method toAccessControlList.

public static Object toAccessControlList(Object objACL) throws S3Exception {
    CFMLEngine engine = CFMLEngineFactory.getInstance();
    Decision dec = engine.getDecisionUtil();
    Cast cast = engine.getCastUtil();
    // String
    if (dec.isSimpleValue(objACL)) {
        String str = cast.toString(objACL, "");
        CannedAccessControlList acl = S3.toACL(str, null);
        if (acl == null)
            throw new S3Exception("invalid access control list definition [" + str + "]");
        return acl;
    }
    // Array
    if (dec.isCastableToArray(objACL)) {
        Array arr = cast.toArray(objACL, null);
        if (arr == null || arr.size() == 0)
            return null;
        AccessControlList acl = new AccessControlList();
        acl.grantAllPermissions(toGrantAndPermissions(arr));
        return acl;
    }
    throw new S3Exception("access control list must be an array or a string");
}
Also used : Cast(lucee.runtime.util.Cast) Array(lucee.runtime.type.Array) AccessControlList(com.amazonaws.services.s3.model.AccessControlList) CannedAccessControlList(com.amazonaws.services.s3.model.CannedAccessControlList) CFMLEngine(lucee.loader.engine.CFMLEngine) CannedAccessControlList(com.amazonaws.services.s3.model.CannedAccessControlList) Decision(lucee.runtime.util.Decision)

Aggregations

Cast (lucee.runtime.util.Cast)2 Decision (lucee.runtime.util.Decision)2 AccessControlList (com.amazonaws.services.s3.model.AccessControlList)1 AmazonS3Exception (com.amazonaws.services.s3.model.AmazonS3Exception)1 Bucket (com.amazonaws.services.s3.model.Bucket)1 CannedAccessControlList (com.amazonaws.services.s3.model.CannedAccessControlList)1 CopyObjectRequest (com.amazonaws.services.s3.model.CopyObjectRequest)1 ObjectMetadata (com.amazonaws.services.s3.model.ObjectMetadata)1 S3Object (com.amazonaws.services.s3.model.S3Object)1 Entry (java.util.Map.Entry)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 CFMLEngine (lucee.loader.engine.CFMLEngine)1 Array (lucee.runtime.type.Array)1 Key (lucee.runtime.type.Collection.Key)1 ParentObject (org.lucee.extension.resource.s3.info.ParentObject)1 S3BucketWrapper (org.lucee.extension.resource.s3.info.S3BucketWrapper)1 AmazonS3Client (org.lucee.extension.resource.s3.pool.AmazonS3Client)1