*/
@SuppressWarnings("deprecation")
public Tuple<SObject, SObjectItem> allocObjectItem(SBucket bucket, String nameKey, S3MetaDataEntry[] meta, S3AccessControlList acl, String cannedAccessPolicy)
{
SObjectDao objectDao = new SObjectDao();
SObjectItemDao objectItemDao = new SObjectItemDao();
SMetaDao metaDao = new SMetaDao();
SAclDao aclDao = new SAclDao();
SObjectItem item = null;
int versionSeq = 1;
int versioningStatus = bucket.getVersioningStatus();
Session session = PersistContext.getSession();
// [A] To write into a bucket the user must have write permission to that bucket
S3PolicyContext context = new S3PolicyContext( PolicyActions.PutObject, bucket.getName());
context.setKeyName( nameKey );
context.setEvalParam( ConditionKeys.Acl, cannedAccessPolicy);
verifyAccess( context, "SBucket", bucket.getId(), SAcl.PERMISSION_WRITE );
// [A] If versioning is off them we over write a null object item
SObject object = objectDao.getByNameKey(bucket, nameKey);
if ( object != null )
{
// -> if versioning is on create new object items
if ( SBucket.VERSIONING_ENABLED == versioningStatus )
{
session.lock(object, LockMode.UPGRADE);
versionSeq = object.getNextSequence();
object.setNextSequence(versionSeq + 1);
session.save(object);
item = new SObjectItem();
item.setTheObject(object);
object.getItems().add(item);
item.setVersion(String.valueOf(versionSeq));
Date ts = DateHelper.currentGMTTime();
item.setCreateTime(ts);
item.setLastAccessTime(ts);
item.setLastModifiedTime(ts);
session.save(item);
}
else
{ // -> find an object item with a null version, can be null
// if bucket started out with versioning enabled and was then suspended
item = objectItemDao.getByObjectIdNullVersion( object.getId());
if (item == null)
{
item = new SObjectItem();
item.setTheObject(object);
object.getItems().add(item);