Beispiel #1
0
  // returns recently changed items, checking for accessibility
  private Item[] getItems(Context context, DSpaceObject dso) throws IOException, SQLException {
    try {
      // new method of doing the browse:
      String idx = ConfigurationManager.getProperty("recent.submissions.sort-option");
      if (idx == null) {
        throw new IOException(
            "There is no configuration supplied for: recent.submissions.sort-option");
      }
      BrowseIndex bix = BrowseIndex.getItemBrowseIndex();
      if (bix == null) {
        throw new IOException("There is no browse index with the name: " + idx);
      }

      BrowserScope scope = new BrowserScope(context);
      scope.setBrowseIndex(bix);
      if (dso != null) {
        scope.setBrowseContainer(dso);
      }

      for (SortOption so : SortOption.getSortOptions()) {
        if (so.getName().equals(idx)) {
          scope.setSortBy(so.getNumber());
        }
      }
      scope.setOrder(SortOption.DESCENDING);
      scope.setResultsPerPage(itemCount);

      // gather & add items to the feed.
      BrowseEngine be = new BrowseEngine(context);
      BrowseInfo bi = be.browseMini(scope);
      Item[] results = bi.getItemResults(context);

      if (includeAll) {
        return results;
      } else {
        // Check to see if we can include this item
        // Group[] authorizedGroups = AuthorizeManager.getAuthorizedGroups(context, results[i],
        // Constants.READ);
        // boolean added = false;
        List<Item> items = new ArrayList<Item>();
        for (Item result : results) {
          checkAccess:
          for (Group group :
              AuthorizeManager.getAuthorizedGroups(context, result, Constants.READ)) {
            if ((group.getID() == Group.ANONYMOUS_ID)) {
              items.add(result);
              break checkAccess;
            }
          }
        }
        return items.toArray(new Item[items.size()]);
      }
    } catch (SortException se) {
      log.error("caught exception: ", se);
      throw new IOException(se.getMessage(), se);
    } catch (BrowseException e) {
      log.error("caught exception: ", e);
      throw new IOException(e.getMessage(), e);
    }
  }
  /**
   * Get the recently submitted items for the given collection.
   *
   * @param collection The collection.
   */
  @SuppressWarnings(
      "unchecked") // The cast from getLastSubmitted is correct, it dose infact return a list of
                   // Items.
  private java.util.List<BrowseItem> getRecientlySubmittedIems(Collection collection)
      throws SQLException {
    if (recentSubmissionItems != null) return recentSubmissionItems;

    String source = ConfigurationManager.getProperty("recent.submissions.sort-option");
    BrowserScope scope = new BrowserScope(context);
    scope.setCollection(collection);
    scope.setResultsPerPage(RECENT_SUBMISISONS);

    // FIXME Exception Handling
    try {
      scope.setBrowseIndex(BrowseIndex.getItemBrowseIndex());
      for (SortOption so : SortOption.getSortOptions()) {
        if (so.getName().equals(source)) scope.setSortBy(so.getNumber());
      }

      BrowseEngine be = new BrowseEngine(context);
      this.recentSubmissionItems = be.browse(scope).getResults();
    } catch (BrowseException bex) {
      log.error("Caught BrowseException", bex);
    }

    return this.recentSubmissionItems;
  }