001/*
002 * Copyright 2020 Global Biodiversity Information Facility (GBIF)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.gbif.api.model.common;
017
018/**
019 * This enumeration represents the status of a DOI identifier.
020 * It represents both EZID and DataCite DOIs.
021 */
022public enum DoiStatus {
023   /**
024   * A NEW DOI status indicates the DOI has been minted in GBIF only and has not yet been passed on to DataCite.
025   */
026  NEW(null),
027
028  /**
029   * The identifier is known only to the DOI registration agency.
030   * This status may be used to reserve an identifier name without advertising the identifier's existence
031   * to resolvers and other external services.
032   * A reserved identifier may be fully deleted.
033   */
034  RESERVED("reserved"),
035
036  /**
037   * A public, registered DOI.
038   * It's target URL is known to public resolvers and other external services.
039   * It may be marked as DELETED in the future, but never again as RESERVED.
040   */
041  REGISTERED("public"),
042
043  /**
044   * The identifier once was registered, but the object referenced by the identifier is not available.
045   * This is known as an "inactive" DOI in DataCite and "unavailable" in EZID.
046   * <br/>
047   * In EZID the identifier redirects to an EZID-provided "tombstone" page regardless of its target URL.
048   * In DataCite the original target URL is still available.
049   */
050  DELETED("unavailable"),
051
052  /**
053   * A failed DOI status indicates we could not communicate with DataCite cause we had invalid metadata.
054   * This DOI then requires a manual cleanup. The status is GBIF internal only!
055   */
056  FAILED(null);
057
058  private final String ezid;
059
060  DoiStatus(String ezid) {
061    this.ezid = ezid;
062  }
063
064  /**
065   * @return the identifier status value used in EZID.
066   */
067  public String getEzid() {
068    return ezid;
069  }
070
071  /**
072   * @return true if the identifier is registered
073   */
074  public boolean isRegistered() {
075    return this == REGISTERED || this == DELETED;
076  }
077
078  public static DoiStatus fromString(String status) {
079    for (DoiStatus s : DoiStatus.values()) {
080      if (status.equalsIgnoreCase(s.name()) || (s.getEzid() != null && status.equalsIgnoreCase(s.getEzid()))) {
081        return s;
082      }
083    }
084    return null;
085  }
086}