Search in sources :

Example 1 with DeleteMultipleObjectsRequest

use of com.pspace.ifs.ksan.gw.format.DeleteMultipleObjectsRequest in project ksan by infinistor.

the class DeleteObjects method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_DELETE_OBJECTS_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);
    DataDeleteObjects dataDeleteObjects = new DataDeleteObjects(s3Parameter);
    dataDeleteObjects.extract();
    String deleteXml = dataDeleteObjects.getDeleteXml();
    XMLOutputFactory xmlOutputFactory = XMLOutputFactory.newInstance();
    try {
        DeleteMultipleObjectsRequest deleteMultipleObjectsRequest = new XmlMapper().readValue(deleteXml, DeleteMultipleObjectsRequest.class);
        Collection<Objects> objectNames = new ArrayList<>();
        if (deleteMultipleObjectsRequest.objects != null) {
            for (DeleteMultipleObjectsRequest.S3Object s3Object : deleteMultipleObjectsRequest.objects) {
                Objects object = new Objects();
                object.objectName = s3Object.key;
                if (Strings.isNullOrEmpty(s3Object.versionId)) {
                    object.versionId = GWConstants.VERSIONING_DISABLE_TAIL;
                } else if (GWConstants.VERSIONING_DISABLE_TAIL.equalsIgnoreCase(s3Object.versionId)) {
                    object.versionId = GWConstants.VERSIONING_DISABLE_TAIL;
                } else {
                    object.versionId = s3Object.versionId;
                }
                objectNames.add(object);
            }
        }
        Writer writer = s3Parameter.getResponse().getWriter();
        s3Parameter.getResponse().setContentType(GWConstants.XML_CONTENT_TYPE);
        XMLStreamWriter xmlStreamWriter = xmlOutputFactory.createXMLStreamWriter(writer);
        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement(GWConstants.DELETE_RESULT);
        xmlStreamWriter.writeDefaultNamespace(GWConstants.AWS_XMLNS);
        logger.debug(GWConstants.LOG_DELETE_OBJECTS_SIZE, objectNames.size());
        for (Objects object : objectNames) {
            deleteObject(s3Parameter, object.objectName, object.versionId, xmlStreamWriter, deleteMultipleObjectsRequest.quiet);
        // xmlStreamWriter.flush(); // In Tomcat, if you use flush(), you lose connection. jakarta, need to check
        }
        xmlStreamWriter.writeEndElement();
        xmlStreamWriter.flush();
    } catch (JsonParseException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } catch (JacksonException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } catch (IOException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    } catch (XMLStreamException e) {
        PrintStack.logging(logger, e);
        throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
    }
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_OK);
}
Also used : JacksonException(com.fasterxml.jackson.core.JacksonException) XMLOutputFactory(javax.xml.stream.XMLOutputFactory) DataDeleteObjects(com.pspace.ifs.ksan.gw.data.DataDeleteObjects) ArrayList(java.util.ArrayList) DeleteMultipleObjectsRequest(com.pspace.ifs.ksan.gw.format.DeleteMultipleObjectsRequest) IOException(java.io.IOException) JsonParseException(com.fasterxml.jackson.core.JsonParseException) XmlMapper(com.fasterxml.jackson.dataformat.xml.XmlMapper) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) DataDeleteObjects(com.pspace.ifs.ksan.gw.data.DataDeleteObjects) Objects(com.pspace.ifs.ksan.gw.format.Objects) GWException(com.pspace.ifs.ksan.gw.exception.GWException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) Writer(java.io.Writer)

Aggregations

JacksonException (com.fasterxml.jackson.core.JacksonException)1 JsonParseException (com.fasterxml.jackson.core.JsonParseException)1 XmlMapper (com.fasterxml.jackson.dataformat.xml.XmlMapper)1 DataDeleteObjects (com.pspace.ifs.ksan.gw.data.DataDeleteObjects)1 GWException (com.pspace.ifs.ksan.gw.exception.GWException)1 DeleteMultipleObjectsRequest (com.pspace.ifs.ksan.gw.format.DeleteMultipleObjectsRequest)1 Objects (com.pspace.ifs.ksan.gw.format.Objects)1 S3Bucket (com.pspace.ifs.ksan.gw.identity.S3Bucket)1 IOException (java.io.IOException)1 Writer (java.io.Writer)1 ArrayList (java.util.ArrayList)1 XMLOutputFactory (javax.xml.stream.XMLOutputFactory)1 XMLStreamException (javax.xml.stream.XMLStreamException)1 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)1