コード例 #1
0
  /**
   * See if the last backup done is updated and if it is in cloud. DSpace Object could be community,
   * collection or item
   *
   * @param context DSpace context
   * @param ref ID of the object
   * @param type type of the object DSpace
   * @return true if the updated backup is in the cloud or false if not
   */
  private Boolean sendDone(Context context, int ref, int type) {
    // see if object is a community or collection
    if (type == Constants.COMMUNITY || type == Constants.COLLECTION) {
      // see if there is a modification registry in the db
      Logbackup logbackup = new Logbackup();
      Boolean existLog = logbackup.existsLog(context, ref, type);

      // if modification has been detected return false
      if (existLog == true) return false;
    }

    // get the DSpaceObject
    DSpaceObject obj = this.getDSpaceObject(context, type, ref);

    // if Object DSpace doesn't exist, return false
    if (obj == null) return false;

    // see if exist a regist of a backup in the table sthandfile
    BackupProcess backupProcess = new BackupProcess();
    Boolean existRegist = backupProcess.existRegist(context, obj.getHandle());

    // if doesn't exist a regist return false
    if (existRegist == false) return false;

    // see if object is an item
    if (type == Constants.ITEM) {
      // get the last modification date of the item
      Item item = null;
      try {
        item = Item.find(context, ref);
      } catch (SQLException ex) {
        Logger.getLogger(ActualContentManagement.class.getName()).log(Level.SEVERE, null, ex);
      }
      Date lastModification = item.getLastModified();

      // get the last backup date
      Date lastBackup = backupProcess.getLastBackupDate(context, obj.getHandle());

      // see if some modification happens after a backup
      if (lastModification.after(lastBackup) == true) return false;
    }

    // get the last send cloud dat
    Date lastSendCloud = backupProcess.getLastSendCloudDate(context, obj.getHandle());

    // if doesn't exist a date relative to the last send to cloud return false
    if (lastSendCloud == null) return false;

    // get the last backup date
    Date lastBackup = backupProcess.getLastBackupDate(context, obj.getHandle());

    // verify if a new backup happened
    if (lastSendCloud.before(lastBackup) == true) {
      // see if new md5 file backup is equal to the last md5 file backup sent to cloud
      Boolean equalFiles = backupProcess.equalsFiles(context, obj.getHandle());

      // if equal files return true
      if (equalFiles == false) return false;
    }

    // see if file exists in cloud, if not returns false
    if (this.filesInCloud.containsKey(obj.getHandle())) {
      // see if ETag is correct, if not returns false
      if (this.filesInCloud
              .get(obj.getHandle())
              .compareTo(backupProcess.getETag(context, obj.getHandle()))
          == 0) return true;
      else return false;
    } else return false;
  }