Search in sources :

Example 1 with DataDeleteObject

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

the class DeleteObject method process.

@Override
public void process() throws GWException {
    logger.info(GWConstants.LOG_DELETE_OBJECT_START);
    String bucket = s3Parameter.getBucketName();
    initBucketInfo(bucket);
    String object = s3Parameter.getObjectName();
    logger.debug(GWConstants.LOG_DELETE_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);
    }
    checkGrantBucketOwner(s3Parameter.isPublicAccess(), String.valueOf(s3Parameter.getUser().getUserId()), GWConstants.GRANT_WRITE);
    DataDeleteObject dataDeleteObject = new DataDeleteObject(s3Parameter);
    dataDeleteObject.extract();
    S3Metadata s3Metadata = new S3Metadata();
    s3Metadata.setName(object);
    s3Metadata.setOwnerId(String.valueOf(s3Parameter.getUser().getUserId()));
    s3Metadata.setOwnerName(s3Parameter.getUser().getUserName());
    String versionId = dataDeleteObject.getVersionId();
    boolean isLastVersion = true;
    String deleteMarker = null;
    String versioningStatus = null;
    versioningStatus = getBucketVersioning(bucket);
    Metadata objMeta = null;
    try {
        if (Strings.isNullOrEmpty(versionId)) {
            objMeta = open(bucket, object);
        } else {
            objMeta = open(bucket, object, versionId);
        }
    } catch (GWException e) {
        if (e.getError().equals(GWErrorCode.NO_SUCH_KEY) && Strings.isNullOrEmpty(versionId) && versioningStatus.equalsIgnoreCase(GWConstants.VERSIONING_ENABLED)) {
            objMeta = createLocal(bucket, object);
            putDeleteMarker(bucket, object, s3Metadata, objMeta);
        }
        s3Parameter.getResponse().addHeader(GWConstants.X_AMZ_VERSION_ID, versionId);
        s3Parameter.getResponse().setStatus(HttpServletResponse.SC_NO_CONTENT);
        return;
    }
    S3ObjectOperation objectOperation = new S3ObjectOperation(objMeta, s3Metadata, s3Parameter, versionId, null);
    isLastVersion = objMeta.getLastVersion();
    deleteMarker = objMeta.getDeleteMarker();
    logger.debug(GWConstants.LOG_DELETE_OBJECT_INFO, versionId, isLastVersion, deleteMarker);
    logger.debug(GWConstants.LOG_DELETE_OBJECT_BUCKET_VERSIONING, versioningStatus);
    if (Strings.isNullOrEmpty(versioningStatus)) {
        logger.debug(GWConstants.LOG_DELETE_OBJECT_BUCKET_VERSIONING_DISABLED);
        remove(bucket, object);
        objectOperation.deleteObject();
    } else {
        if (versioningStatus.equalsIgnoreCase(GWConstants.VERSIONING_ENABLED)) {
            // Bucket Versioning Enabled
            logger.debug(GWConstants.LOG_DELETE_OBJECT_BUCKET_VERSIONING_ENABLED);
            if (Strings.isNullOrEmpty(versionId)) {
                // request versionId is null
                if (deleteMarker.equalsIgnoreCase(GWConstants.OBJECT_TYPE_MARK)) {
                    remove(bucket, object, GWConstants.VERSIONING_DISABLE_TAIL);
                } else {
                    // put delete marker
                    putDeleteMarker(bucket, object, s3Metadata, objMeta);
                }
            } else {
                // request with versionId
                if (isLastVersion) {
                    remove(bucket, object, versionId);
                    if (deleteMarker.equalsIgnoreCase(GWConstants.OBJECT_TYPE_FILE)) {
                        objectOperation.deleteObject();
                    }
                } else {
                    // request with versionId not currentVid
                    remove(bucket, object, versionId);
                    objectOperation.deleteObject();
                }
            }
        } else if (versioningStatus.equalsIgnoreCase(GWConstants.VERSIONING_SUSPENDED)) {
            // Bucket Versioning Suspended
            logger.debug(GWConstants.LOG_DELETE_OBJECT_BUCKET_VERSIONING_SUSPENDED);
            if (Strings.isNullOrEmpty(versionId)) {
                if (isLastVersion) {
                    if (deleteMarker.equalsIgnoreCase(GWConstants.OBJECT_TYPE_MARK)) {
                        remove(bucket, object, GWConstants.OBJECT_TYPE_MARK);
                    } else {
                        // put delete marker
                        putDeleteMarker(bucket, object, s3Metadata, objMeta);
                    }
                }
            } else {
                // request with versionId
                remove(bucket, object, versionId);
                objectOperation.deleteObject();
            }
        } else {
            logger.error(GWConstants.LOG_DELETE_OBJECT_BUCKET_VERSIONING_WRONG, versioningStatus);
            throw new GWException(GWErrorCode.SERVER_ERROR, s3Parameter);
        }
    }
    s3Parameter.getResponse().addHeader(GWConstants.X_AMZ_VERSION_ID, versionId);
    s3Parameter.getResponse().setStatus(HttpServletResponse.SC_NO_CONTENT);
}
Also used : S3ObjectOperation(com.pspace.ifs.ksan.gw.object.S3ObjectOperation) S3Bucket(com.pspace.ifs.ksan.gw.identity.S3Bucket) DataDeleteObject(com.pspace.ifs.ksan.gw.data.DataDeleteObject) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) S3Metadata(com.pspace.ifs.ksan.gw.identity.S3Metadata) Metadata(com.pspace.ifs.ksan.objmanager.Metadata) GWException(com.pspace.ifs.ksan.gw.exception.GWException)

Aggregations

DataDeleteObject (com.pspace.ifs.ksan.gw.data.DataDeleteObject)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 S3ObjectOperation (com.pspace.ifs.ksan.gw.object.S3ObjectOperation)1 Metadata (com.pspace.ifs.ksan.objmanager.Metadata)1