001package org.gbif.api.util;
002
003import org.gbif.api.vocabulary.IdentifierType;
004
005import javax.annotation.Nullable;
006
007/**
008 * This class contains utility methods for identifiers. Currently there are 3 separate Identifier
009 * classes:
010 * </br>
011 * 1) org.gbif.api.model.checklistbank.Identifier
012 * 2) org.gbif.api.model.common.Identifier
013 * 3) org.gbif.api.model.registry.Identifier
014 * </br>
015 * Methods common to 2 or more classes should be listed here.
016 */
017public class IdentifierUtils {
018
019  /**
020   * Creates a http link for an identifier if possible by passing it to some known resolvers for the specific id type.
021   * If no link can be constructed, null is returned.
022   *
023   * @param identifier Identifier's identifier
024   * @param type Identifier's type
025   *
026   * @return the url or null if it cannot be created
027   */
028  @Nullable
029  public static String getIdentifierLink(String identifier, IdentifierType type) {
030    if (identifier == null || type == null) {
031      return null;
032    }
033    switch (type) {
034      case HANDLER:
035      case URI:
036      case URL:
037      case FTP:
038        return identifier;
039      case DOI:
040        return "http://dx.doi.org/" + identifier;
041      case LSID:
042        return "http://lsid.tdwg.org/summary/" + identifier;
043      case GBIF_PORTAL:
044        return "http://data.gbif.org/datasets/resource/" + identifier;
045    }
046    return null;
047  }
048}