Ejemplo n.º 1
0
  /**
   * Get a item backup file preserved in the cloud.
   *
   * @param context context DSpace
   * @param ref ID of the item
   * @param establishConnection true if pretend establish connection to cloud
   * @return true if file correctly sent to cloud, or false if not
   */
  public Boolean getItem(Context context, Integer ref, Boolean establishConnection) {
    DSpaceObject obj = this.getDSpaceObject(context, Constants.ITEM, ref);

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

    // if just one file to get make connection with cloud
    if (establishConnection == true) {
      this.makeConnection();
      this.filesInCloud.putAll(this.newCloudConnection.getInfoFilesIn(Constants.ITEM));
    }

    // see if it is possible and necessary get community backup from cloud
    Boolean var = this.couldGetFileFromCloud(context, ref, Constants.ITEM);
    if (var == false) {
      // if just one file to send close connection with cloud
      if (establishConnection == true) this.closeConnection();
      return false;
    }

    // get file name of the community backup
    Backup backup = new Backup();
    String filename = backup.getFileNameObj(obj);

    // get file from cloud
    Boolean result = this.getFileFromCloud(filename);

    // if just one file to send close connection with cloud
    if (establishConnection == true) this.closeConnection();

    return result;
  }
Ejemplo n.º 2
0
  /**
   * 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;
  }
Ejemplo n.º 3
0
  /**
   * Send a community backup file to cloud to be preserved.
   *
   * @param context context DSpace
   * @param ref ID of the community
   * @param establishConnection true if pretend establish connection to cloud
   * @return true if file correctly sent to cloud, or false if not
   */
  public Boolean sendCommunity(Context context, Integer ref, Boolean establishConnection) {
    // get Dspace Object to the respective community
    DSpaceObject obj = this.getDSpaceObject(context, Constants.COMMUNITY, ref);

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

    // if connection not maked
    if (establishConnection == true) {
      this.makeConnection();
      this.filesInCloud.putAll(this.newCloudConnection.getInfoFilesIn(Constants.COMMUNITY));
    }

    // see if last backup has sent to cloud
    Boolean var = this.sendDone(context, ref, Constants.COMMUNITY);
    if (var == true) {
      // if just one file to send close connection with cloud
      if (establishConnection == true) this.closeConnection();
      return false;
    }

    Backup backup = new Backup();

    // see if backup exists and is correct
    Boolean statBackup = backup.backupDone(context, ref, Constants.COMMUNITY);

    // if backup doesn't exist, do it
    Boolean statOperation = false;
    if (statBackup == false) statOperation = backup.exportCommunity(context, ref);
    else statOperation = true;

    // if backup operation fails, return false
    if (statOperation == false) {
      // if just one file to send close connection with cloud
      if (establishConnection == true) this.closeConnection();
      return false;
    }

    // get file name of the community backup
    String filename = backup.getFileNameObj(obj);

    // send file to cloud
    Boolean result = this.sendFileToCloud(context, filename);

    // if just one file to send close connection with cloud
    if (establishConnection == true) this.closeConnection();

    return result;
  }