/**
   * Send a file to cloud to be preserved.
   *
   * @param context context DSpace
   * @param filename name of the file
   * @return true if file correctly sent to cloud, or false if not
   */
  private Boolean sendFileToCloud(Context context, String filename) {
    // send file to cloud and receive the ETag
    String Etag = newCloudConnection.sendFile(context, filename);

    // if Etag is null, fails to send file to cloud, return false
    if (Etag == null) return false;

    // get the handler to be recognized in the db
    int firstSlash = filename.indexOf('@');
    int secondSlash = filename.indexOf('.');
    String handler = filename.substring(firstSlash + 1, secondSlash);
    handler = handler.replace('-', '/');

    // get the correct etag
    Etag = Etag.substring(1, Etag.length() - 1);

    // get md5 of the local file
    String md5 = this.getMD5File(filename);

    // regist the operation in the db
    BackupProcess newRegist = new BackupProcess();
    newRegist.updateProcessSendCloud(context, handler, md5, Etag);

    return true;
  }
  /**
   * See if is necessary and possible to get the backup file from cloud.
   *
   * @param context DSpace context
   * @param ref ID of the object
   * @param type type of the object DSpace
   * @return true if it is necessary or possible to get the backup from cloud or false if not
   */
  private Boolean couldGetFileFromCloud(Context context, int ref, int type) {
    // get the corresponding Dspace Object
    DSpaceObject obj = this.getDSpaceObject(context, type, ref);

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

    // see if backup file exists in cloud, if not return false
    if (this.filesInCloud.containsKey(obj.getHandle())) {
      BackupProcess backupPro = new BackupProcess();
      String ETagSaved = backupPro.getETag(context, obj.getHandle());

      // see if ETag of file in cloud, has equal to the last send, if not return false
      if (ETagSaved.compareTo(this.filesInCloud.get(obj.getHandle())) == 0) {
        // see if exists backup file locally
        Backup backup = new Backup();
        String filename = backup.getFileNameObj(obj);
        Boolean existLocalFile = backup.existFile(filename);

        // if not exist file locally return true
        if (existLocalFile == true) {
          // get MD5 of local file
          String md5LocalFile = backup.getMD5File(filename);
          // get MD5 of the last file sent to cloud
          String md5FileSentCloud = backupPro.getSentMD5(context, obj.getHandle());

          // if files equal, there is no necessity to get file from cloud, then return false
          if (md5LocalFile.compareTo(md5FileSentCloud) == 0) return false;
          else return true;
        } else return true;
      } else return false;
    } else return false;
  }
  /**
   * 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;
  }