Search in sources :

Example 1 with DataPutBucketVersioning

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

the class PutBucketVersioning method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_PUT_BUCKET_VERSIONING_START);
    String bucket = s3Parameter.getBucketName();
    initBucketInfo(bucket);
    S3Bucket s3Bucket = new S3Bucket();
    s3Bucket.setCors(getBucketInfo().getCors());
    s3Bucket.setAccess(getBucketInfo().getAccess());
    s3Parameter.setBucket(s3Bucket);
    GWUtils.checkCors(s3Parameter);
    if (s3Parameter.isPublicAccess() && GWUtils.isIgnorePublicAcls(s3Parameter)) {
        throw new GWException(GWErrorCode.ACCESS_DENIED, s3Parameter);
    }
    checkGrantBucketOwner(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_WRITE_ACP);
    DataPutBucketVersioning dataPutBucketVersioning = new DataPutBucketVersioning(s3Parameter);
    dataPutBucketVersioning.extract();
    String versionXml = dataPutBucketVersioning.getVersioningXml();
    if (!Strings.isNullOrEmpty(versionXml)) {
        Versioning versioning = new Versioning();
        try {
            versioning = new XmlMapper().readValue(versionXml, Versioning.class);
        } catch (JsonProcessingException e) {
            PrintStack.logging(logger, e);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
        if (versioning.status != null && !versioning.status.equalsIgnoreCase(GWConstants.VERSIONING_ENABLED) && !versioning.status.equalsIgnoreCase(GWConstants.VERSIONING_SUSPENDED)) {
            throw new GWException(GWErrorCode.MALFORMED_X_M_L, s3Parameter);
        }
        if (!Strings.isNullOrEmpty(getBucketInfo().getObjectLock())) {
            if (!versioning.status.equalsIgnoreCase(GWConstants.VERSIONING_ENABLED)) {
                throw new GWException(GWErrorCode.INVALID_BUCKET_STATE, s3Parameter);
            }
        }
        if (!Strings.isNullOrEmpty(versioning.status)) {
            putBucketVersioning(bucket, versioning.status);
        }
    }
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Also used : DataPutBucketVersioning(com.pspace.ifs.ksan.gw.data.DataPutBucketVersioning) Versioning(com.pspace.ifs.ksan.gw.format.Versioning) DataPutBucketVersioning(com.pspace.ifs.ksan.gw.data.DataPutBucketVersioning) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) GWException(com.pspace.ifs.ksan.gw.exception.GWException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 DataPutBucketVersioning (com.pspace.ifs.ksan.gw.data.DataPutBucketVersioning)1 GWException (com.pspace.ifs.ksan.gw.exception.GWException)1 Versioning (com.pspace.ifs.ksan.gw.format.Versioning)1 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)1