Search in sources :

Example 1 with DataGetObjectRetention

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);
}
Also used : XMLOutputFactory(javax.xml.stream.XMLOutputFactory) DataGetObjectRetention(com.pspace.ifs.ksan.gw.data.DataGetObjectRetention) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) Metadata(com.pspace.ifs.ksan.objmanager.Metadata) IOException(java.io.IOException) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) XMLStreamException(javax.xml.stream.XMLStreamException) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) GWException(com.pspace.ifs.ksan.gw.exception.GWException) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper)

Aggregations

JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 DataGetObjectRetention (com.pspace.ifs.ksan.gw.data.DataGetObjectRetention)1 GWException (com.pspace.ifs.ksan.gw.exception.GWException)1 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)1 S3Metadata (com.pspace.ifs.ksan.gw.identity.S3Metadata)1 Metadata (com.pspace.ifs.ksan.objmanager.Metadata)1 IOException (java.io.IOException)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1