return response;
}
SObjectDao objectDao = new SObjectDao();
String nameKey = request.getKey();
SObject sobject = objectDao.getByNameKey( sbucket, nameKey );
if (sobject == null) {
response.setResultCode(404);
response.setResultDescription("Bucket does not exist");
return response;
}
// -> versioning controls what delete means
String storedPath = null;
SObjectItem item = null;
int versioningStatus = sbucket.getVersioningStatus();
if ( SBucket.VERSIONING_ENABLED == versioningStatus )
{
String wantVersion = request.getVersion();
S3PolicyContext context = new S3PolicyContext( PolicyActions.DeleteObjectVersion, bucketName );
context.setKeyName( nameKey );
context.setEvalParam( ConditionKeys.VersionId, wantVersion );
verifyAccess( context, "SBucket", sbucket.getId(), SAcl.PERMISSION_WRITE );
if (null == wantVersion) {
// -> if versioning is on and no versionId is given then we just write a deletion marker
sobject.setDeletionMark( UUID.randomUUID().toString());
objectDao.update( sobject );
}
else {
// -> are we removing the delete marker?
String deletionMarker = sobject.getDeletionMark();
if (null != deletionMarker && wantVersion.equalsIgnoreCase( deletionMarker )) {
sobject.setDeletionMark( null );
objectDao.update( sobject );
response.setResultCode(204);
return response;
}
// -> if versioning is on and the versionId is given then we delete the object matching that version
if ( null == (item = sobject.getVersion( wantVersion ))) {
response.setResultCode(404);
return response;
}
else {
// -> just delete the one item that matches the versionId from the database
storedPath = item.getStoredPath();
sobject.deleteItem( item.getId());
objectDao.update( sobject );
}
}
}
else
{ // -> if versioning is off then we do delete the null object
S3PolicyContext context = new S3PolicyContext( PolicyActions.DeleteObject, bucketName );
context.setKeyName( nameKey );
verifyAccess( context, "SBucket", sbucket.getId(), SAcl.PERMISSION_WRITE );
if ( null == (item = sobject.getLatestVersion( true ))) {
response.setResultCode(404);
return response;
}
else {
// -> if no item with a null version then we are done