Package com.cloud.bridge.model

Examples of com.cloud.bridge.model.SObjectItemVO


         SObjectVO oneObject = (SObjectVO)it.next();
        Set<SObjectItemVO> itemsInObject = oneObject.getItems();
        Iterator<SObjectItemVO> is = itemsInObject.iterator();
        while( is.hasNext())
        {
                    SObjectItemVO oneItem = (SObjectItemVO) is.next();
                    deleteMetaData(oneItem.getId());
                    deleteObjectAcls("SObjectItem", oneItem.getId());
        }       
       }
        
       // Delete all the policy state associated with the bucket
       try {
View Full Code Here


                      .getInstance().getMultipartDir(), parts,
                      outputStream);
     
            response.setETag(result.getFirst());
            response.setLastModified(DateHelper.toCalendar(object_objectitem_pair.getSecond().getLastModifiedTime()));
            SObjectItemVO item = itemDao.findById(object_objectitem_pair
                    .getSecond().getId());
            item.setMd5(result.getFirst());
            item.setStoredSize(result.getSecond().longValue());
            itemDao.update(item.getId(), item);
            response.setResultCode(200);
  } catch (Exception e) {
      logger.error("completeMultipartUpload failed due to " + e.getMessage(),e);
      txn.close();
  }
View Full Code Here

      response.setETag(md5Checksum);
      response.setLastModified(DateHelper.toCalendar( object_objectitem_pair.getSecond().getLastModifiedTime()));
          response.setVersion( object_objectitem_pair.getSecond().getVersion());
   
      //SObjectItemDaoImpl itemDao = new SObjectItemDaoImpl();
      SObjectItemVO item = itemDao.findById(object_objectitem_pair.getSecond().getId());
      item.setMd5(md5Checksum);
      item.setStoredSize(contentLength);
      itemDao.update(item.getId(), item);
      txn.commit();
    } catch (IOException e) {
      logger.error("PutObjectInline failed due to " + e.getMessage(), e);
    } catch (OutOfStorageException e) {
      logger.error("PutObjectInline failed due to " + e.getMessage(), e);
View Full Code Here

      is = request.getInputStream();
      String md5Checksum = bucketAdapter.saveObject(is, host_storagelocation_pair.getSecond(), bucket.getName(), itemFileName);
      response.setETag(md5Checksum);
      response.setLastModified(DateHelper.toCalendar( object_objectitem_pair.getSecond().getLastModifiedTime()));
     
      SObjectItemVO item = itemDao.findById(object_objectitem_pair.getSecond().getId());
      item.setMd5(md5Checksum);
      item.setStoredSize(contentLength);
      itemDao.update(item.getId(), item);
      txn.commit();
     
    } catch (OutOfStorageException e) {
      logger.error("PutObject failed due to " + e.getMessage(), e);
    } finally {
View Full Code Here

      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;     
      }

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

    // -> the acl always goes on the instance of the object
      aclDao.save("SObjectItem", item.getId(), request.getAcl());
     
      response.setResultCode(200);
      response.setResultDescription("OK");
      return response;
    }
View Full Code Here

      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);
    
     
      List<SAclVO> grants = aclDao.listGrants( "SObjectItem", item.getId());
      policy.setGrants(S3Grant.toGrants(grants));   
      return policy;
    }
View Full Code Here

      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;     
      }
   
    if ( SBucket.VERSIONING_ENABLED == versioningStatus ) {
       context = new S3PolicyContext( PolicyActions.GetObjectVersion, bucketName );
       context.setEvalParam( ConditionKeys.VersionId, wantVersion );
    }
    else context = new S3PolicyContext( PolicyActions.GetObject, bucketName );   
     context.setKeyName( nameKey );
    verifyAccess( context, "SObjectItem", item.getId(), SAcl.PERMISSION_READ );   
   
     
      // [C] Handle all the IFModifiedSince ... conditions, and access privileges
    // -> http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.27 (HTTP If-Range header)
    if (request.isReturnCompleteObjectOnConditionFailure() && (0 <= bytesStart && 0 <= bytesEnd)) ifRange = true;

    resultCode = conditionPassed( request.getConditions(), item.getLastModifiedTime(), item.getMd5(), ifRange );
      if ( -1 == resultCode ) {
        // -> If-Range implementation, we have to return the entire object
        resultCode = 200;
        bytesStart = -1;
        bytesEnd = -1;
      }
      else if (200 != resultCode) {
      response.setResultCode( resultCode );
        response.setResultDescription( "Precondition Failed" );     
      return response;
    }


    // [D] Return the contents of the object inline 
    // -> extract the meta data that corresponds the specific versioned item

    List<SMetaVO> itemMetaData =   metaDao.getByTarget( "SObjectItem", item.getId());
    if (null != itemMetaData)
    {
      int i = 0;
      S3MetaDataEntry[] metaEntries = new S3MetaDataEntry[ itemMetaData.size() ];
        ListIterator<SMetaVO> it = itemMetaData.listIterator();
        while( it.hasNext()) {
          SMetaVO oneTag = (SMetaVO)it.next();
          S3MetaDataEntry oneEntry = new S3MetaDataEntry();
          oneEntry.setName( oneTag.getName());
          oneEntry.setValue( oneTag.getValue());
          metaEntries[i++] = oneEntry;
        }
        response.setMetaEntries( metaEntries );
    }
       
    //  -> support a single byte range
    if ( 0 <= bytesStart && 0 <= bytesEnd ) {
         response.setContentLength( bytesEnd - bytesStart )
         resultCode = 206;
    }
    else response.setContentLength( item.getStoredSize());
      if(request.isReturnData())
      {
        response.setETag(item.getMd5());
        response.setLastModified(DateHelper.toCalendar( item.getLastModifiedTime()));
        response.setVersion( item.getVersion());
        if (request.isInlineData())
        {
          OrderedPair<SHostVO, String> tupleSHostInfo = getBucketStorageHost(sbucket);
        S3BucketAdapter bucketAdapter = getStorageHostBucketAdapter(tupleSHostInfo.getFirst());
       
        if ( 0 <= bytesStart && 0 <= bytesEnd )
           response.setData(bucketAdapter.loadObjectRange(tupleSHostInfo.getSecond(),
               request.getBucketName(), item.getStoredPath(), bytesStart, bytesEnd ));
        else response.setData(bucketAdapter.loadObject(tupleSHostInfo.getSecond(), request.getBucketName(), item.getStoredPath()));
        }
      }
     
      response.setResultCode( resultCode );
      response.setResultDescription("OK");
View Full Code Here

    }
   
       
    // 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());
            }
         }
    }
   
View Full Code Here

   * TODO - how does the versionIdMarker work when there is a deletion marker in the object?
   */
  private S3ListBucketObjectEntry[] composeListBucketContentEntries(List<SObjectVO> l, String prefix, String delimiter, int maxKeys, boolean enableVersion, String versionIdMarker)
  {
    List<S3ListBucketObjectEntry> entries = new ArrayList<S3ListBucketObjectEntry>();
    SObjectItemVO latest  = null;
    boolean hitIdMarker = false;
    int count = 0;
   
    for( SObjectVO sobject : l )
    {
      if (delimiter != null && !delimiter.isEmpty())
      {
        if (StringHelper.substringInBetween(sobject.getNameKey(), prefix, delimiter) != null)
          continue;
      }
     
      if (enableVersion)
      {
        hitIdMarker = (null == versionIdMarker ? true : false);

        // This supports GET REST calls with /?versions
        String deletionMarker = sobject.getDeletionMark();
                if ( null != deletionMarker )
                {
                   // TODO we should also save the timestamp when something is deleted
                   S3ListBucketObjectEntry entry = new S3ListBucketObjectEntry();
                 entry.setKey(sobject.getNameKey());
                 entry.setVersion( deletionMarker );
                 entry.setIsLatest( true );
                 entry.setIsDeletionMarker( true );
                 entry.setLastModified( Calendar.getInstance( TimeZone.getTimeZone("GMT") ));
                 entry.setOwnerCanonicalId(sobject.getOwnerCanonicalId());
                 entry.setOwnerDisplayName("");
                 entries.add( entry );
                 latest = null;
                }
                else latest = sobject.getLatestVersion( false );
       
        Iterator<SObjectItemVO> it = sobject.getItems().iterator();
        while( it.hasNext())
        {
          SObjectItemVO item = (SObjectItemVO)it.next();
         
          if ( !hitIdMarker )
          {
             if (item.getVersion().equalsIgnoreCase( versionIdMarker )) {
               hitIdMarker = true;
               entries.add( toListEntry( sobject, item, latest ));
             }
          }
          else entries.add( toListEntry( sobject, item, latest ));
        }
      }
      else
      {   // -> if there are multiple versions of an object then just return its last version
        Iterator<SObjectItemVO> it = sobject.getItems().iterator();
        SObjectItemVO lastestItem = null;
        int maxVersion = 0;
        int version = 0;
        while(it.hasNext())
        {
          SObjectItemVO item = (SObjectItemVO)it.next();
          String versionStr = item.getVersion();
         
          if ( null != versionStr )
             version = Integer.parseInt(item.getVersion());
          else lastestItem = item;
         
          // -> if the bucket has versions turned on
          if (version > maxVersion) {
            maxVersion = version;
View Full Code Here

   * @throws IOException
   */
  @SuppressWarnings("deprecation")
  public OrderedPair<SObjectVO, SObjectItemVO> allocObjectItem(SBucketVO bucket, String nameKey, S3MetaDataEntry[] meta, S3AccessControlList acl, String cannedAccessPolicy)
  {
    SObjectItemVO    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 )// 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);
        item = itemDao.persist(item);
        txn.commit();
        txn.close();
       
    }
     
   
    // [C] We will use the item DB id as the file name, MD5/contentLength will be stored later
    String suffix = null;
    int dotPos = nameKey.lastIndexOf('.');
    if (dotPos >= 0) suffix = nameKey.substring(dotPos);
    if ( suffix != null )
       item.setStoredPath(String.valueOf(item.getId()) + suffix);
    else item.setStoredPath(String.valueOf(item.getId()));
   
    metaDao.save("SObjectItem", item.getId(), meta);
   
   
    // [D] Are we setting an ACL along with the object
    //  -> the ACL is ALWAYS set on a particular instance of the object (i.e., a version)
    if ( null != cannedAccessPolicy )
    {
       setCannedAccessControls( cannedAccessPolicy, "SObjectItem", item.getId(), bucket );
    }
    else if (null == acl || 0 == acl.size())
    {
       // -> this is termed the "private" or default ACL, "Owner gets FULL_CONTROL"
       setSingleAcl( "SObjectItem", item.getId(), SAcl.PERMISSION_FULL );
    }
    else if (null != acl) {
       aclDao.save( "SObjectItem", item.getId(), acl );
    }
   
    itemDao.update(item.getId(), item);
    txn.close();
    return new OrderedPair<SObjectVO, SObjectItemVO>(object, item);
  }
View Full Code Here

TOP

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

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.