コード例 #1
0
  /**
   * Return a normalized focus value. If there is no normalization that can be performed, return the
   * focus value that is passed in.
   *
   * @param value a focus value to normalize
   * @return the normalized focus value
   * @throws BrowseException
   */
  private String normalizeJumpToValue(String value) throws BrowseException {
    // If the scope has a focus value (focus by value)
    if (scope.hasJumpToValue()) {
      // Normalize it based on the specified language as appropriate for this index
      return OrderFormat.makeSortString(
          scope.getJumpToValue(), scope.getJumpToValueLang(), scope.getBrowseIndex().getDataType());
    } else if (scope.hasStartsWith()) {
      // Scope has a starts with, so normalize that instead
      return OrderFormat.makeSortString(
          scope.getStartsWith(), null, scope.getBrowseIndex().getDataType());
    }

    // No focus value on the scope (ie. focus by id), so just return the passed focus value
    // This is useful in cases where we have pulled a focus value from the index
    // which will already be normalized, and avoids another DB lookup
    return value;
  }
コード例 #2
0
  /*
   * Creates a map of the browse options common to all pages (type / value /
   * value language)
   */
  Map<String, String> getCommonParameters() throws UIException {
    Map<String, String> paramMap = new HashMap<String, String>();

    paramMap.put(
        BrowseParams.TYPE, AbstractDSpaceTransformer.URLEncode(scope.getBrowseIndex().getName()));

    if (scope.getFilterValue() != null) {
      paramMap.put(
          BrowseParams.FILTER_VALUE, AbstractDSpaceTransformer.URLEncode(scope.getFilterValue()));
    }

    if (scope.getFilterValueLang() != null) {
      paramMap.put(
          BrowseParams.FILTER_VALUE_LANG,
          AbstractDSpaceTransformer.URLEncode(scope.getFilterValueLang()));
    }

    return paramMap;
  }
コード例 #3
0
  /**
   * Perform a standard browse, which will return a BrowseInfo object that represents the results
   * for the current page, the total number of results, the range, and information to construct
   * previous and next links on any web page
   *
   * @param bs the scope of the browse
   * @return the results of the browse
   * @throws BrowseException
   */
  public BrowseInfo browse(BrowserScope bs) throws BrowseException {
    log.debug(LogManager.getHeader(context, "browse", ""));

    // first, load the browse scope into the object
    this.scope = bs;

    // since we use it so much, get the browse index out of the
    // scope and store as a member
    browseIndex = scope.getBrowseIndex();

    // now make the decision as to how to browse
    if (browseIndex.isMetadataIndex() && !scope.isSecondLevel()) {
      // this is a single value browse type that has not gone to
      // the second level (i.e. authors, not items by a given author)
      return browseByValue(scope);
    } else {
      // this is the full browse type or a browse that has gone to
      // the second level
      return browseByItem(scope);
    }
  }
コード例 #4
0
  String getKey() {
    try {
      String key = "";

      key += "-" + scope.getBrowseIndex().getName();
      key += "-" + scope.getBrowseLevel();
      key += "-" + scope.getStartsWith();
      key += "-" + scope.getResultsPerPage();
      key += "-" + scope.getSortBy();
      key += "-" + scope.getSortOption().getNumber();
      key += "-" + scope.getOrder();
      key += "-" + scope.getJumpToItem();
      key += "-" + scope.getFilterValue();
      key += "-" + scope.getFilterValueLang();
      key += "-" + scope.getJumpToValue();
      key += "-" + scope.setJumpToValueLang();
      key += "-" + etAl;

      return key;
    } catch (Exception e) {
      return null; // ignore exception and return no key
    }
  }
コード例 #5
0
  /**
   * Browse the archive by the full item browse mechanism. This produces a BrowseInfo object which
   * contains full BrowseItem objects as its result set.
   *
   * @param bs the scope of the browse
   * @return the results of the browse
   * @throws BrowseException
   */
  private BrowseInfo browseByItem(BrowserScope bs) throws BrowseException {
    log.info(LogManager.getHeader(context, "browse_by_item", ""));
    try {
      // get the table name that we are going to be getting our data from
      dao.setTable(browseIndex.getTableName());

      // tell the browse query whether we are ascending or descending on the value
      dao.setAscending(scope.isAscending());

      // assemble the value clause
      String rawValue = null;
      if (scope.hasFilterValue() && scope.isSecondLevel()) {
        String value = scope.getFilterValue();
        rawValue = value;

        // make sure the incoming value is normalised
        value =
            OrderFormat.makeSortString(
                value, scope.getFilterValueLang(), scope.getBrowseIndex().getDataType());

        dao.setAuthorityValue(scope.getAuthorityValue());

        // set the values in the Browse Query
        if (scope.isSecondLevel()) {
          dao.setFilterValueField("value");
          dao.setFilterValue(rawValue);
        } else {
          dao.setFilterValueField("sort_value");
          dao.setFilterValue(value);
        }
        dao.setFilterValuePartial(scope.getFilterValuePartial());

        // to apply the filtering, we need the distinct and map tables for the index
        dao.setFilterMappingTables(
            browseIndex.getDistinctTableName(), browseIndex.getMapTableName());
      }

      // define a clause for the WHERE clause which will allow us to constrain
      // our browse to a specified community or collection
      if (scope.inCollection() || scope.inCommunity()) {
        if (scope.inCollection()) {
          Collection col = (Collection) scope.getBrowseContainer();
          dao.setContainerTable("collection2item");
          dao.setContainerIDField("collection_id");
          dao.setContainerID(col.getID());
        } else if (scope.inCommunity()) {
          Community com = (Community) scope.getBrowseContainer();
          dao.setContainerTable("communities2item");
          dao.setContainerIDField("community_id");
          dao.setContainerID(com.getID());
        }
      }

      // this is the total number of results in answer to the query
      int total = getTotalResults();

      // assemble the ORDER BY clause
      String orderBy = browseIndex.getSortField(scope.isSecondLevel());
      if (scope.getSortBy() > 0) {
        orderBy = "sort_" + Integer.toString(scope.getSortBy());
      }
      dao.setOrderField(orderBy);

      int offset = scope.getOffset();
      String rawFocusValue = null;
      if (offset < 1
          && (scope.hasJumpToItem() || scope.hasJumpToValue() || scope.hasStartsWith())) {
        // We need to convert these to an offset for the actual browse query.
        // First, get a value that we can look up in the ordering field
        rawFocusValue = getJumpToValue();

        // make sure the incoming value is normalised
        String focusValue = normalizeJumpToValue(rawFocusValue);

        log.debug("browsing using focus: " + focusValue);

        // Convert the focus value into an offset
        offset = getOffsetForValue(focusValue);
      }

      dao.setOffset(offset);

      // assemble the LIMIT clause
      dao.setLimit(scope.getResultsPerPage());

      // Holder for the results
      List<BrowseItem> results = null;

      // Does this browse have any contents?
      if (total > 0) {
        // now run the query
        results = dao.doQuery();

        // now, if we don't have any results, we are at the end of the browse.  This will
        // be because a starts_with value has been supplied for which we don't have
        // any items.
        if (results.size() == 0) {
          // In this case, we will calculate a new offset for the last page of results
          offset = total - scope.getResultsPerPage();
          if (offset < 0) {
            offset = 0;
          }

          // And rerun the query
          dao.setOffset(offset);
          results = dao.doQuery();
        }
      } else {
        // No records, so make an empty list
        results = new ArrayList<BrowseItem>();
      }

      // construct the BrowseInfo object to pass back
      //            BrowseInfo browseInfo = new BrowseInfo(results, position, total, offset);
      BrowseInfo browseInfo = new BrowseInfo(results, offset, total, offset);

      if (offset + scope.getResultsPerPage() < total) {
        browseInfo.setNextOffset(offset + scope.getResultsPerPage());
      }

      if (offset - scope.getResultsPerPage() > -1) {
        browseInfo.setPrevOffset(offset - scope.getResultsPerPage());
      }

      // add the browse index to the Browse Info
      browseInfo.setBrowseIndex(browseIndex);

      // set the sort option for the Browse Info
      browseInfo.setSortOption(scope.getSortOption());

      // tell the Browse Info which way we are sorting
      browseInfo.setAscending(scope.isAscending());

      // tell the Browse Info which level of browse we are at
      browseInfo.setBrowseLevel(scope.getBrowseLevel());

      // set the browse value if there is one
      browseInfo.setValue(rawValue);

      // set the browse authority key if there is one
      browseInfo.setAuthority(scope.getAuthorityValue());

      // set the focus value if there is one
      browseInfo.setFocus(rawFocusValue);

      if (scope.hasJumpToItem()) {
        browseInfo.setFocusItem(scope.getJumpToItem());
      }

      // tell the browse info if it is working from a starts with parameter
      browseInfo.setStartsWith(scope.hasStartsWith());

      // tell the browse info what the container for the browse was
      if (scope.inCollection() || scope.inCommunity()) {
        browseInfo.setBrowseContainer(scope.getBrowseContainer());
      }

      browseInfo.setResultsPerPage(scope.getResultsPerPage());

      browseInfo.setEtAl(scope.getEtAl());

      return browseInfo;
    } catch (SQLException e) {
      log.error("caught exception: ", e);
      throw new BrowseException(e);
    }
  }
コード例 #6
0
  /**
   * Perform a limited browse, which only returns the results requested, without any extraneous
   * information. To perform a full browse, use BrowseEngine.browse() above. This supports Item
   * browse only, and does not currently support focus or values. This method is used, for example,
   * to generate the Recently Submitted Items results.
   *
   * @param bs the scope of the browse
   * @return the results of the browse
   */
  public BrowseInfo browseMini(BrowserScope bs) throws BrowseException {
    log.info(LogManager.getHeader(context, "browse_mini", ""));

    // load the scope into the object
    this.scope = bs;

    // since we use it so much, get the browse index out of the
    // scope and store as a member
    browseIndex = scope.getBrowseIndex();

    // get the table name that we are going to be getting our data from
    dao.setTable(browseIndex.getTableName());

    // tell the browse query whether we are ascending or descending on the value
    dao.setAscending(scope.isAscending());

    // define a clause for the WHERE clause which will allow us to constrain
    // our browse to a specified community or collection
    if (scope.inCollection() || scope.inCommunity()) {
      if (scope.inCollection()) {
        Collection col = (Collection) scope.getBrowseContainer();
        dao.setContainerTable("collection2item");
        dao.setContainerIDField("collection_id");
        dao.setContainerID(col.getID());
      } else if (scope.inCommunity()) {
        Community com = (Community) scope.getBrowseContainer();
        dao.setContainerTable("communities2item");
        dao.setContainerIDField("community_id");
        dao.setContainerID(com.getID());
      }
    }

    dao.setOffset(scope.getOffset());
    dao.setLimit(scope.getResultsPerPage());

    // assemble the ORDER BY clause
    String orderBy = browseIndex.getSortField(scope.isSecondLevel());
    if (scope.getSortBy() > 0) {
      orderBy = "sort_" + Integer.toString(scope.getSortBy());
    }
    dao.setOrderField(orderBy);

    // now run the query
    List<BrowseItem> results = dao.doQuery();

    // construct the mostly empty BrowseInfo object to pass back
    BrowseInfo browseInfo = new BrowseInfo(results, 0, scope.getResultsPerPage(), 0);

    // add the browse index to the Browse Info
    browseInfo.setBrowseIndex(browseIndex);

    // set the sort option for the Browse Info
    browseInfo.setSortOption(scope.getSortOption());

    // tell the Browse Info which way we are sorting
    browseInfo.setAscending(scope.isAscending());

    // tell the browse info what the container for the browse was
    if (scope.inCollection() || scope.inCommunity()) {
      browseInfo.setBrowseContainer(scope.getBrowseContainer());
    }

    browseInfo.setResultsPerPage(scope.getResultsPerPage());

    browseInfo.setEtAl(scope.getEtAl());

    return browseInfo;
  }