Package com.cloud.bridge.model

Examples of com.cloud.bridge.model.SObject


   
    public void testSObject() {
      SHost host;
      SBucket bucket;
      Session session;
      SObject sobject;
     
      // setup
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      host = new SHost();
      host.setHost("localhost");
      host.setUserOnHost("root");
      host.setUserPassword("password");
      host.setExportRoot("/");
     
      bucket = new SBucket();
      bucket.setName("Bucket");
      bucket.setOwnerCanonicalId("OwnerId-dummy");
      bucket.setCreateTime(new Date());
      bucket.setShost(host);
      host.getBuckets().add(bucket);
     
      sobject = new SObject();
      sobject.setNameKey("ObjectNameKey");
      sobject.setOwnerCanonicalId("OwnerId-dummy");
      sobject.setCreateTime(new Date());
      sobject.setBucket(bucket);
      bucket.getObjectsInBucket().add(sobject);
     
      session.save(host);
      session.save(bucket);
      session.save(sobject);
      txn.commit();
     
    } finally {
      session.close();
    }
   
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      sobject = (SObject)session.get(SObject.class, sobject.getId());
      txn.commit();
      Assert.assertTrue(sobject.getBucket().getName().equals("Bucket"));
      Assert.assertTrue(sobject.getNameKey().equals("ObjectNameKey"));
      Assert.assertTrue(sobject.getOwnerCanonicalId().equals("OwnerId-dummy"));
    } finally {
      session.close();
    }

    // test delete cascade
View Full Code Here


   
    public void testSObject() {
      SHost host;
      SBucket bucket;
      Session session;
      SObject sobject;
     
      // setup
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      host = new SHost();
      host.setHost("localhost");
      host.setUserOnHost("root");
      host.setUserPassword("password");
      host.setExportRoot("/");
     
      bucket = new SBucket();
      bucket.setName("Bucket");
      bucket.setOwnerCanonicalId("OwnerId-dummy");
      bucket.setCreateTime(new Date());
      bucket.setShost(host);
      host.getBuckets().add(bucket);
     
      sobject = new SObject();
      sobject.setNameKey("ObjectNameKey");
      sobject.setOwnerCanonicalId("OwnerId-dummy");
      sobject.setCreateTime(new Date());
      sobject.setBucket(bucket);
      bucket.getObjectsInBucket().add(sobject);
     
      session.save(host);
      session.save(bucket);
      session.save(sobject);
      txn.commit();
     
    } finally {
      session.close();
    }
   
    session = CloudSessionFactory.getInstance().openSession();
    try {
      Transaction txn = session.beginTransaction();
      sobject = (SObject)session.get(SObject.class, sobject.getId());
      txn.commit();
      Assert.assertTrue(sobject.getBucket().getName().equals("Bucket"));
      Assert.assertTrue(sobject.getNameKey().equals("ObjectNameKey"));
      Assert.assertTrue(sobject.getOwnerCanonicalId().equals("OwnerId-dummy"));
    } finally {
      session.close();
    }

    // test delete cascade
View Full Code Here

    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);
              Date ts = DateHelper.currentGMTTime();
              item.setCreateTime(ts);
              item.setLastAccessTime(ts);
              item.setLastModifiedTime(ts);
              session.save(item);     
          }
       }
    }
    else
    {    // -> there is no object nor an object item
       object = new SObject();
       object.setBucket(bucket);
       object.setNameKey(nameKey);
       object.setNextSequence(2);
       object.setCreateTime(DateHelper.currentGMTTime());
       object.setOwnerCanonicalId(UserContext.current().getCanonicalUserId());
       session.save(object);
   
         item = new SObjectItem();
         item.setTheObject(object);
         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

       //    Delete SMeta & SAcl objects: (1)Get all the objects in the bucket, (2)then all the items in each object, (3) then all meta & acl data for each item
       Set<SObject> objectsInBucket = sbucket.getObjectsInBucket();
       Iterator it = objectsInBucket.iterator();
       while( it.hasNext())
       {
         SObject oneObject = (SObject)it.next();
        Set<SObjectItem> itemsInObject = oneObject.getItems();
        Iterator is = itemsInObject.iterator();
        while( is.hasNext())
        {
          SObjectItem oneItem = (SObjectItem)is.next();
            deleteMetaData( oneItem.getId());
View Full Code Here

        return response;
      }
     
      SObjectDao sobjectDao = new SObjectDao();
      String nameKey = request.getKey();
      SObject sobject = sobjectDao.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
    SObjectItem 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");
     
      SObjectDao sobjectDao = new SObjectDao();
      String nameKey = request.getKey();
      SObject sobject = sobjectDao.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
    SObjectItem 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);
    
      SAclDao aclDao = new SAclDao();
View Full Code Here

      return response;
    }

    SObjectDao objectDao = new SObjectDao();
    String nameKey = request.getKey();
    SObject 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
    SObjectItem 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;
    }
   
    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
View Full Code Here

TOP

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

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.