Search in sources :

Example 1 with DataCreateBucket

use of com.pspace.ifs.ksan.gw.data.DataCreateBucket in project ksan by infinistor.

the class CreateBucket method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_CREATE_BUCKET_START);
    String bucket = s3Parameter.getBucketName();
    logger.debug(GWConstants.LOG_CREATE_BUCKET_NAME, bucket);
    checkBucketName(bucket);
    if (isExistBucket(bucket) || bucket.equalsIgnoreCase(GWConstants.WEBSITE)) {
        logger.info(GWConstants.LOG_CREATE_BUCKET_EXIST, bucket);
        initBucketInfo(bucket);
        if (isBucketOwner(String.valueOf(s3Parameter.getUser().getUserId()))) {
            throw new GWException(GWErrorCode.BUCKET_ALREADY_OWNED_BY_YOU, s3Parameter);
        }
        throw new GWException(GWErrorCode.BUCKET_ALREADY_EXISTS, s3Parameter);
    }
    DataCreateBucket dataCreateBucket = new DataCreateBucket(s3Parameter);
    dataCreateBucket.extract();
    accessControlPolicy = new AccessControlPolicy();
    accessControlPolicy.aclList = new AccessControlList();
    accessControlPolicy.aclList.grants = new ArrayList<Grant>();
    accessControlPolicy.owner = new Owner();
    accessControlPolicy.owner.id = String.valueOf(s3Parameter.getUser().getUserId());
    accessControlPolicy.owner.displayName = s3Parameter.getUser().getUserName();
    String xml = GWUtils.makeAclXml(accessControlPolicy, null, dataCreateBucket.hasAclKeyword(), null, dataCreateBucket.getAcl(), getBucketInfo(), String.valueOf(s3Parameter.getUser().getUserId()), s3Parameter.getUser().getUserName(), dataCreateBucket.getGrantRead(), dataCreateBucket.getGrantWrite(), dataCreateBucket.getGrantFullControl(), dataCreateBucket.getGrantReadAcp(), dataCreateBucket.getGrantWriteAcp(), s3Parameter);
    logger.debug(GWConstants.LOG_ACL, xml);
    int result = 0;
    if (!Strings.isNullOrEmpty(dataCreateBucket.getBucketObjectLockEnabled()) && GWConstants.STRING_TRUE.equalsIgnoreCase(dataCreateBucket.getBucketObjectLockEnabled())) {
        logger.info(GWConstants.LOG_CREATE_BUCKET_VERSIONING_ENABLED_OBJECT_LOCK_TRUE);
        String objectLockXml = GWConstants.OBJECT_LOCK_XML;
        result = createBucket(bucket, s3Parameter.getUser().getUserName(), String.valueOf(s3Parameter.getUser().getUserId()), xml, "", objectLockXml);
        putBucketVersioning(bucket, GWConstants.STATUS_ENABLED);
    } else {
        result = createBucket(bucket, s3Parameter.getUser().getUserName(), String.valueOf(s3Parameter.getUser().getUserId()), xml, "", "");
    }
    if (result != 0) {
        throw new GWException(GWErrorCode.INTERNAL_SERVER_DB_ERROR, s3Parameter);
    }
    s3Parameter.getResponse().addHeader(HttpHeaders.LOCATION, GWConstants.SLASH + bucket);
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Also used : AccessControlList(com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList) DataCreateBucket(com.pspace.ifs.ksan.gw.data.DataCreateBucket) Grant(com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList.Grant) AccessControlPolicy(com.pspace.ifs.ksan.gw.format.AccessControlPolicy) Owner(com.pspace.ifs.ksan.gw.format.AccessControlPolicy.Owner) GWException(com.pspace.ifs.ksan.gw.exception.GWException)

Aggregations

DataCreateBucket (com.pspace.ifs.ksan.gw.data.DataCreateBucket)1 GWException (com.pspace.ifs.ksan.gw.exception.GWException)1 AccessControlPolicy (com.pspace.ifs.ksan.gw.format.AccessControlPolicy)1 AccessControlList (com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList)1 Grant (com.pspace.ifs.ksan.gw.format.AccessControlPolicy.AccessControlList.Grant)1 Owner (com.pspace.ifs.ksan.gw.format.AccessControlPolicy.Owner)1