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);
}
Aggregations