001package org.gbif.api.model.common;
002
003/**
004 * This enumeration represents the status of a DOI identifier.
005 * It represents both EZID and DataCite DOIs.
006 */
007public enum DoiStatus {
008   /**
009   * A NEW DOI status indicates the DOI has been minted in GBIF only and has not yet been passed on to DataCite.
010   */
011  NEW(null),
012
013  /**
014   * The identifier is known only to the DOI registration agency.
015   * This status may be used to reserve an identifier name without advertising the identifier's existence
016   * to resolvers and other external services.
017   * A reserved identifier may be fully deleted.
018   */
019  RESERVED("reserved"),
020
021  /**
022   * A public, registered DOI.
023   * It's target URL is known to public resolvers and other external services.
024   * It may be marked as DELETED in the future, but never again as RESERVED.
025   */
026  REGISTERED("public"),
027
028  /**
029   * The identifier once was registered, but the object referenced by the identifier is not available.
030   * This is known as an "inactive" DOI in DataCite and "unavailable" in EZID.
031   * <br/>
032   * In EZID the identifier redirects to an EZID-provided "tombstone" page regardless of its target URL.
033   * In DataCite the original target URL is still available.
034   */
035  DELETED("unavailable"),
036
037  /**
038   * A failed DOI status indicates we could not communicate with DataCite cause we had invalid metadata.
039   * This DOI then requires a manual cleanup. The status is GBIF internal only!
040   */
041  FAILED(null);
042
043  private final String ezid;
044
045  DoiStatus(String ezid) {
046    this.ezid = ezid;
047  }
048
049  /**
050   * @return the identifier status value used in EZID.
051   */
052  public String getEzid() {
053    return ezid;
054  }
055
056  /**
057   * @return true if the identifier is registered
058   */
059  public boolean isRegistered() {
060    return this == REGISTERED || this == DELETED;
061  }
062
063  public static DoiStatus fromString(String status) {
064    for (DoiStatus s : DoiStatus.values()) {
065      if (status.equalsIgnoreCase(s.name()) || (s.getEzid() != null && status.equalsIgnoreCase(s.getEzid()))) {
066        return s;
067      }
068    }
069    return null;
070  }
071}