return response;
}
String nameKey = request.getKey();
SObjectVO sobject = objectDao.getByNameKey( sbucket, nameKey );
if (sobject == null) {
response.setResultCode(404);
response.setResultDescription("<Code>Not Found</Code><Message>No object with key " + nameKey + " exists in bucket " + bucketName+"</Message>");
return response;
}
// Discover whether versioning is enabled. If so versioning requires the setting of a deletion marker.
String storedPath = null;
SObjectItemVO 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.getId(), sobject );
response.setResultDescription("<DeleteMarker>true</DeleteMarker><DeleteMarkerVersionId>"+ sobject.getDeletionMark() +"</DeleteMarkerVersionId>");
}
else {
// Otherwise remove the deletion marker if this has been set
String deletionMarker = sobject.getDeletionMark();
if (null != deletionMarker && wantVersion.equalsIgnoreCase( deletionMarker )) {
sobject.setDeletionMark( null );
objectDao.update(sobject.getId(), sobject );
response.setResultDescription("<VersionId>" + wantVersion +"</VersionId>");
response.setResultDescription("<DeleteMarker>true</DeleteMarker><DeleteMarkerVersionId>"+ sobject.getDeletionMark() +"</DeleteMarkerVersionId>");
response.setResultCode(204);
return response;
}
// If versioning is on and the versionId is given (non-null) then delete the object matching that version
if ( null == (item = sobject.getVersion( wantVersion ))) {
response.setResultCode(404);
return response;
}
else {
// Providing versionId is non-null, then just delete the one item that matches the versionId from the database
storedPath = item.getStoredPath();
sobject.deleteItem( item.getId());
objectDao.update(sobject.getId(), sobject );
response.setResultDescription("<VersionId>" + wantVersion +"</VersionId>");
}
}
}
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);
response.setResultDescription("<Code>AccessDenied</Code><Message>Access Denied</Message>");
return response;
}
else {
// If there is no item with a null version then we are done
if (null == item.getVersion()) {
// Otherwiswe remove the entire object
// Cascade-deleting can delete related SObject/SObjectItem objects, but not SAcl and SMeta objects.
storedPath = item.getStoredPath();
deleteMetaData( item.getId());
deleteObjectAcls( "SObjectItem", item.getId());
objectDao.remove(sobject.getId());
}
}
}
// Delete the file holding the object