/**
   * 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;
  }
  /**
   * Return the specific DSpaceObject. Could be a community, collection or item.
   *
   * @param context DSpace context
   * @param type DSpace Object Type
   * @param ref ID of the object
   * @return the DSpaceObject if exists or null
   */
  private DSpaceObject getDSpaceObject(Context context, int type, int ref) {
    DSpaceObject obj = null;
    try {
      obj = DSpaceObject.find(context, type, ref);
    } catch (SQLException ex) {
      Logger.getLogger(ActualContentManagement.class.getName()).log(Level.SEVERE, null, ex);
    }

    return obj;
  }
  /**
   * 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;
  }
Esempio n. 4
0
  @Override
  public void authorizeAction(
      Context c, EPerson e, DSpaceObject o, int action, boolean useInheritance)
      throws AuthorizeException, SQLException {
    if (o == null) {
      // action can be -1 due to a null entry
      String actionText;

      if (action == -1) {
        actionText = "null";
      } else {
        actionText = Constants.actionText[action];
      }

      UUID userid;

      if (e == null) {
        userid = null;
      } else {
        userid = e.getID();
      }

      throw new AuthorizeException(
          "Authorization attempted on null DSpace object " + actionText + " by user " + userid);
    }

    if (!authorize(c, o, action, e, useInheritance)) {
      // denied, assemble and throw exception
      int otype = o.getType();
      UUID oid = o.getID();
      UUID userid;

      if (e == null) {
        userid = null;
      } else {
        userid = e.getID();
      }

      //            AuthorizeException j = new AuthorizeException("Denied");
      //            j.printStackTrace();
      // action can be -1 due to a null entry
      String actionText;

      if (action == -1) {
        actionText = "null";
      } else {
        actionText = Constants.actionText[action];
      }

      throw new AuthorizeException(
          "Authorization denied for action "
              + actionText
              + " on "
              + Constants.typeText[otype]
              + ":"
              + oid
              + " by user "
              + userid,
          o,
          action);
    }
  }