Package com.cloud.bridge.model

Examples of com.cloud.bridge.model.SObjectVO


    verifyAccess( context, "SBucket", bucket.getId(), SAcl.PERMISSION_WRITE )// TODO - check this validates plain POSTs
    Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
    txn.start();

    // [B] If versioning is off them we over write a null object item
    SObjectVO object = objectDao.getByNameKey(bucket, nameKey);
    if ( object != null )
    {    
       // -> if versioning is on create new object items
       if ( SBucket.VERSIONING_ENABLED == versioningStatus )
       {

            versionSeq = object.getNextSequence();
            object.setNextSequence(versionSeq + 1);
            objectDao.update(object.getId(), object);
           
            item = new SObjectItemVO();
            item.setTheObject(object);
            object.getItems().add(item);
            item.setsObjectID(object.getId());
            item.setVersion(String.valueOf(versionSeq));
            Date ts = DateHelper.currentGMTTime();
            item.setCreateTime(ts);
            item.setLastAccessTime(ts);
            item.setLastModifiedTime(ts);
            item = itemDao.persist(item);
            txn.commit();
            //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 = itemDao.getByObjectIdNullVersion( object.getId());
          if (item == null)
          {
              item = new SObjectItemVO();
              item.setTheObject(object);
              item.setsObjectID(object.getId());
              object.getItems().add(item);
              Date ts = DateHelper.currentGMTTime();
              item.setCreateTime(ts);
              item.setLastAccessTime(ts);
              item.setLastModifiedTime(ts);
              item = itemDao.persist(item);
              txn.commit();
          }
       }
    }
    else
    {   
        Transaction txn1 = Transaction.open(Transaction.AWSAPI_DB);
        txn1.start();
        // -> there is no object nor an object item
      object = new SObjectVO();
      object.setBucket(bucket);
      object.setNameKey(nameKey);
      object.setNextSequence(2);
      object.setBucketID(bucket.getId());
      object.setCreateTime(DateHelper.currentGMTTime());
      object.setOwnerCanonicalId(UserContext.current().getCanonicalUserId());
      object = objectDao.persist(object);
        item = new SObjectItemVO();
        item.setTheObject(object);
        item.setsObjectID(object.getId());
        object.getItems().add(item);
        if (SBucket.VERSIONING_ENABLED  == versioningStatus) item.setVersion(String.valueOf(versionSeq));
        Date ts = DateHelper.currentGMTTime();
        item.setCreateTime(ts);
        item.setLastAccessTime(ts);
        item.setLastModifiedTime(ts);
View Full Code Here


   
  public SObjectDaoImpl() {}

  @Override
  public SObjectVO getByNameKey(SBucketVO bucket, String nameKey) {
    SObjectVO object = null;
      SearchBuilder<SObjectVO> SearchByName = createSearchBuilder();
      SearchByName.and("SBucketID", SearchByName.entity().getBucketID() , SearchCriteria.Op.EQ);
      SearchByName.and("NameKey", SearchByName.entity().getNameKey() , SearchCriteria.Op.EQ);
      Transaction txn = Transaction.open(Transaction.AWSAPI_DB);
      try {
            txn.start();
            SearchCriteria<SObjectVO> sc = SearchByName.create();
            sc.setParameters("SBucketID", bucket.getId());
            sc.setParameters("NameKey", nameKey);
            object = findOneBy(sc);
            if (null != object) {
                Set<SObjectItemVO> items = new HashSet<SObjectItemVO>(
                        itemDao.getItems(object.getId()));
                object.setItems(items);
            }
    return object;
   
      }finally {
            txn.close();
View Full Code Here

            // (3) then all meta & acl data for each item
            Set<SObjectVO> objectsInBucket = sbucket.getObjectsInBucket();
            Iterator<SObjectVO> it = objectsInBucket.iterator();
            while( it.hasNext())
            {
                SObjectVO oneObject = it.next();
                Set<SObjectItemVO> itemsInObject = oneObject.getItems();
                Iterator<SObjectItemVO> is = itemsInObject.iterator();
                while( is.hasNext())
                {
                    SObjectItemVO oneItem = is.next();
                    deleteMetaData(oneItem.getId());
View Full Code Here

            response.setResultDescription("Bucket " + bucketName + "does not exist");
            return response;
        }

        String nameKey = request.getKey();
        SObjectVO sobject = objectDao.getByNameKey( sbucket, nameKey );    
        if(sobject == null) {
            response.setResultCode(404);
            response.setResultDescription("Object " + request.getKey() + " in bucket " + bucketName + " does not exist");
            return response;
        }

        String deletionMark = sobject.getDeletionMark();
        if (null != deletionMark) {
            response.setResultCode(404);
            response.setResultDescription("Object " + request.getKey() + " has been deleted (1)");
            return response;
        }


        // [B] Versioning allow the client to ask for a specific version not just the latest
        SObjectItemVO item = null;
        int versioningStatus = sbucket.getVersioningStatus();
        String wantVersion = request.getVersion();
        if ( SBucket.VERSIONING_ENABLED == versioningStatus && null != wantVersion)
            item = sobject.getVersion( wantVersion );
        else item = sobject.getLatestVersion(( SBucket.VERSIONING_ENABLED != versioningStatus ));   

        if (item == null) {
            response.setResultCode(404);
            response.setResultDescription("Object " + request.getKey() + " has been deleted (2)");
            return response;     
View Full Code Here

        if (sbucket == null)
            throw new NoSuchObjectException("Bucket " + bucketName + " does not exist");

        //SObjectDaoImpl sobjectDao = new SObjectDaoImpl();
        String nameKey = request.getKey();
        SObjectVO sobject = objectDao.getByNameKey( sbucket, nameKey );
        if (sobject == null)
            throw new NoSuchObjectException("Object " + request.getKey() + " does not exist");

        String deletionMark = sobject.getDeletionMark();
        if (null != deletionMark) {
            policy.setResultCode(404);
            policy.setResultDescription("Object " + request.getKey() + " has been deleted (1)");
            return policy;
        }


        // [B] Versioning allow the client to ask for a specific version not just the latest
        SObjectItemVO item = null;
        int versioningStatus = sbucket.getVersioningStatus();
        String wantVersion = request.getVersion();
        if ( SBucket.VERSIONING_ENABLED == versioningStatus && null != wantVersion)
            item = sobject.getVersion( wantVersion );
        else item = sobject.getLatestVersion(( SBucket.VERSIONING_ENABLED != versioningStatus ));   

        if (item == null) {
            policy.setResultCode(404);
            policy.setResultDescription("Object " + request.getKey() + " has been deleted (2)");
            return policy;     
        }

        if ( SBucket.VERSIONING_ENABLED == versioningStatus ) {
            context = new S3PolicyContext( PolicyActions.GetObjectVersionAcl, bucketName );
            context.setEvalParam( ConditionKeys.VersionId, wantVersion );
            policy.setVersion( item.getVersion());
        }
        else context = new S3PolicyContext( PolicyActions.GetObjectAcl, bucketName );   
        context.setKeyName( nameKey );
        verifyAccess( context, "SObjectItem", item.getId(), SAcl.PERMISSION_READ_ACL );   


        // [C] ACLs are ALWAYS on an instance of the object
        S3CanonicalUser owner = new S3CanonicalUser();
        owner.setID(sobject.getOwnerCanonicalId());
        owner.setDisplayName("");
        policy.setOwner(owner);
        policy.setResultCode(200);

View Full Code Here

            response.setResultDescription("Bucket " + request.getBucketName() + " does not exist");
            return response;
        }

        String nameKey = request.getKey();
        SObjectVO sobject = objectDao.getByNameKey( sbucket, nameKey );
        if (sobject == null) {
            response.setResultCode(404);
            response.setResultDescription("Object " + request.getKey() + " does not exist in bucket " + request.getBucketName());
            return response;
        }

        String deletionMark = sobject.getDeletionMark();
        if (null != deletionMark) {
            response.setDeleteMarker( deletionMark );
            response.setResultCode(404);
            response.setResultDescription("Object " + request.getKey() + " has been deleted (1)");
            return response;
        }


        // [B] Versioning allow the client to ask for a specific version not just the latest
        SObjectItemVO item = null;
        int versioningStatus = sbucket.getVersioningStatus();
        String wantVersion = request.getVersion();
        if ( SBucket.VERSIONING_ENABLED == versioningStatus && null != wantVersion)      
            item = sobject.getVersion( wantVersion );
        else item = sobject.getLatestVersion(( SBucket.VERSIONING_ENABLED != versioningStatus ));   

        if (item == null) {
            response.setResultCode(404);
            response.setResultDescription("Object " + request.getKey() + " has been deleted (2)");
            return response;     
View Full Code Here

            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
View Full Code Here

        verifyAccess( context, "SBucket", bucket.getId(), SAcl.PERMISSION_WRITE )// TODO - check this validates plain POSTs
        TransactionLegacy txn = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
        txn.start();

        // [B] If versioning is off them we over write a null object item
        SObjectVO object = objectDao.getByNameKey(bucket, nameKey);
        if ( object != null )
        {    
            // -> if versioning is on create new object items
            if ( SBucket.VERSIONING_ENABLED == versioningStatus )
            {

                versionSeq = object.getNextSequence();
                object.setNextSequence(versionSeq + 1);
                objectDao.update(object.getId(), object);

                item = new SObjectItemVO();
                item.setTheObject(object);
                object.getItems().add(item);
                item.setsObjectID(object.getId());
                item.setVersion(String.valueOf(versionSeq));
                Date ts = DateHelper.currentGMTTime();
                item.setCreateTime(ts);
                item.setLastAccessTime(ts);
                item.setLastModifiedTime(ts);
                item = itemDao.persist(item);
                txn.commit();
                //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 = itemDao.getByObjectIdNullVersion( object.getId());
                if (item == null)
                {
                    item = new SObjectItemVO();
                    item.setTheObject(object);
                    item.setsObjectID(object.getId());
                    object.getItems().add(item);
                    Date ts = DateHelper.currentGMTTime();
                    item.setCreateTime(ts);
                    item.setLastAccessTime(ts);
                    item.setLastModifiedTime(ts);
                    item = itemDao.persist(item);
                    txn.commit();
                }
            }
        }
        else
        {   
            TransactionLegacy txn1 = TransactionLegacy.open(TransactionLegacy.AWSAPI_DB);
            txn1.start();
            // -> there is no object nor an object item
            object = new SObjectVO();
            object.setBucket(bucket);
            object.setNameKey(nameKey);
            object.setNextSequence(2);
            object.setBucketID(bucket.getId());
            object.setCreateTime(DateHelper.currentGMTTime());
            object.setOwnerCanonicalId(UserContext.current().getCanonicalUserId());
            object = objectDao.persist(object);
            item = new SObjectItemVO();
            item.setTheObject(object);
            item.setsObjectID(object.getId());
            object.getItems().add(item);
            if (SBucket.VERSIONING_ENABLED  == versioningStatus) item.setVersion(String.valueOf(versionSeq));
            Date ts = DateHelper.currentGMTTime();
            item.setCreateTime(ts);
            item.setLastAccessTime(ts);
            item.setLastModifiedTime(ts);
View Full Code Here

            // (3) then all meta & acl data for each item
            Set<SObjectVO> objectsInBucket = sbucket.getObjectsInBucket();
            Iterator<SObjectVO> it = objectsInBucket.iterator();
            while( it.hasNext())
            {
                SObjectVO oneObject = it.next();
                Set<SObjectItemVO> itemsInObject = oneObject.getItems();
                Iterator<SObjectItemVO> is = itemsInObject.iterator();
                while( is.hasNext())
                {
                    SObjectItemVO oneItem = is.next();
                    deleteMetaData(oneItem.getId());
View Full Code Here

            response.setResultDescription("Bucket " + bucketName + "does not exist");
            return response;
        }

        String nameKey = request.getKey();
        SObjectVO sobject = objectDao.getByNameKey( sbucket, nameKey );    
        if(sobject == null) {
            response.setResultCode(404);
            response.setResultDescription("Object " + request.getKey() + " in bucket " + bucketName + " does not exist");
            return response;
        }

        String deletionMark = sobject.getDeletionMark();
        if (null != deletionMark) {
            response.setResultCode(404);
            response.setResultDescription("Object " + request.getKey() + " has been deleted (1)");
            return response;
        }


        // [B] Versioning allow the client to ask for a specific version not just the latest
        SObjectItemVO item = null;
        int versioningStatus = sbucket.getVersioningStatus();
        String wantVersion = request.getVersion();
        if ( SBucket.VERSIONING_ENABLED == versioningStatus && null != wantVersion)
            item = sobject.getVersion( wantVersion );
        else item = sobject.getLatestVersion(( SBucket.VERSIONING_ENABLED != versioningStatus ));   

        if (item == null) {
            response.setResultCode(404);
            response.setResultDescription("Object " + request.getKey() + " has been deleted (2)");
            return response;     
View Full Code Here

TOP

Related Classes of com.cloud.bridge.model.SObjectVO

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.