use of com.pspace.ifs.ksan.gw.data.DataGetObjectRetention in project ksan by infinistor.
the class GetObjectRetention method process.
@Override
public void process() throws GWException {
logger.info(GWConstants.LOG_GET_OBJECT_RETENTION_START);
String bucket = s3Parameter.getBucketName();
initBucketInfo(bucket);
String object = s3Parameter.getObjectName();
logger.debug(GWConstants.LOG_BUCKET_OBJECT, bucket, object);
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);
}
DataGetObjectRetention dataGetObjectRetention = new DataGetObjectRetention(s3Parameter);
dataGetObjectRetention.extract();
String versionId = dataGetObjectRetention.getVersionId();
Metadata objMeta = null;
if (Strings.isNullOrEmpty(versionId)) {
objMeta = open(bucket, object);
} else {
objMeta = open(bucket, object, versionId);
}
logger.debug(GWConstants.LOG_OBJECT_META, objMeta.toString());
objMeta.setAcl(GWUtils.makeOriginalXml(objMeta.getAcl(), s3Parameter));
checkGrantObjectOwner(s3Parameter.isPublicAccess(), objMeta, String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_READ);
String meta = objMeta.getMeta();
S3Metadata s3Metadata;
try {
s3Metadata = new ObjectMapper().readValue(meta, S3Metadata.class);
} catch (JsonProcessingException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
if (!Strings.isNullOrEmpty(s3Metadata.getLockMode())) {
XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newFactory();
javax.xml.stream.XMLStreamWriter xml;
try {
xml = xmlOutputFactory.createXMLStreamWriter(s3Parameter.getResponse().getOutputStream());
xml.writeStartDocument();
xml.writeStartElement(GWConstants.RETENTION);
writeSimpleElement(xml, GWConstants.XML_MODE, s3Metadata.getLockMode());
writeSimpleElement(xml, GWConstants.RETAIN_UNTIL_DATE, s3Metadata.getLockExpires());
xml.writeEndElement();
xml.flush();
} catch (XMLStreamException | IOException e) {
PrintStack.logging(logger, e);
throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
}
} else {
throw new GWException(GWErrorCode.INVALID_REQUEST, s3Parameter);
}
s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Aggregations