コード例 #1
0
  /**
   * Returns the information for the supplied source keys
   *
   * <p>TODO: There may be a better location for this method.
   *
   * @param sources
   * @return
   */
  public List<OccurrenceSourceDTO> getSourceInformation(Map<String, Integer> sources) {

    Set<String> keys = sources.keySet();
    logger.debug("Listing the source information for : " + keys);
    List<OccurrenceSourceDTO> lsources = new ArrayList<OccurrenceSourceDTO>();
    try {
      for (String key : keys) {
        String name = key;
        if (key.startsWith("co")) name = collectionCache.getCollections().get(key);
        else if (key.startsWith("in")) name = collectionCache.getInstitutions().get(key);
        else if (key.startsWith("dr")) name = collectionCache.getDataResources().get(key);
        lsources.add(new OccurrenceSourceDTO(name, key, sources.get(key)));
      }
    } catch (Exception e) {
      logger.error(e.getMessage());
    }

    // sort the sources based on count
    java.util.Collections.sort(
        lsources,
        new java.util.Comparator<OccurrenceSourceDTO>() {
          @Override
          public int compare(OccurrenceSourceDTO o1, OccurrenceSourceDTO o2) {
            // sort the counts in reverse order so that max count appears at the top of the list
            return o2.getCount() - o1.getCount();
          }
        });
    return lsources;
  }
コード例 #2
0
  /**
   * Returns the display string for the supplied uid
   *
   * @param uid
   * @return a user friendly display name for this UID
   */
  public String getUidDisplayString(String fieldName, String uid, boolean includeField) {

    uid = stripEscapedQuotes(uid);

    // get the information from the collections cache
    if (uid.startsWith("in") && collectionCache.getInstitutions().containsKey(uid)) {
      if (includeField) return "Institution: " + collectionCache.getInstitutions().get(uid);
      else return collectionCache.getInstitutions().get(uid);
    } else if (uid.startsWith("co") && collectionCache.getCollections().containsKey(uid)) {
      if (includeField) return "Collection: " + collectionCache.getCollections().get(uid);
      else return collectionCache.getCollections().get(uid);
    } else if (uid.startsWith("drt") && collectionCache.getTempDataResources().containsKey(uid)) {
      if (includeField)
        return "Temporary Data resource: " + collectionCache.getTempDataResources().get(uid);
      else return collectionCache.getTempDataResources().get(uid);
    } else if (uid.startsWith("dr") && collectionCache.getDataResources().containsKey(uid)) {
      if (includeField) return "Data resource: " + collectionCache.getDataResources().get(uid);
      else return collectionCache.getDataResources().get(uid);
    } else if (uid.startsWith("dp") && collectionCache.getDataProviders().containsKey(uid)) {
      if (includeField) return "Data provider: " + collectionCache.getDataProviders().get(uid);
      else return collectionCache.getDataProviders().get(uid);
    } else if (uid.startsWith("dh") && collectionCache.getDataHubs().containsKey(uid)) {
      if (includeField) return "Data hub: " + collectionCache.getDataHubs().get(uid);
      else return collectionCache.getDataHubs().get(uid);
    }
    return messageSource.getMessage(
        fieldName + "." + StringUtils.remove(uid, "\""), null, uid, null);
  }