001/*
002 * Copyright 2013 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.vocabulary;
017
018import org.gbif.api.util.VocabularyUtils;
019
020import javax.annotation.Nullable;
021
022import com.google.common.collect.ImmutableMap;
023
024/**
025 * Enumeration for all contact types.
026 * A utility to infer types is provided which has historically been used during data migration activities from legacy
027 * systems such as the previous "GBRDS" which was built on MySQL.
028 *
029 * @see <a href="http://rs.gbif.org/vocabulary/gbif/agent_role.xml">rs.gbif.org vocabulary</a>
030 */
031public enum ContactType {
032  /**
033   * A contact to contact for further technical information related to the dataset.
034   */
035  TECHNICAL_POINT_OF_CONTACT,
036  /**
037   * A contact to contact for further non-technical information related to the dataset.
038   */
039  ADMINISTRATIVE_POINT_OF_CONTACT,
040  /**
041   * A contact to contact for further information about the dataset.
042   */
043  POINT_OF_CONTACT,
044  /**
045   * A contact who originally gathered/prepared the dataset.
046   */
047  ORIGINATOR,
048  /**
049   * A contact responsible for providing the metadata.
050   */
051  METADATA_AUTHOR,
052  /**
053   * A primary scientific contact associated with the dataset.
054   */
055  PRINCIPAL_INVESTIGATOR,
056  /**
057   * A contact who is an author of a publication that used the dataset, or author of a data paper.
058   */
059  AUTHOR,
060  /**
061   * A contact who contributed content to a dataset (the dataset being described may be a composite).
062   */
063  CONTENT_PROVIDER,
064  /**
065   * A contact who is responsible for/takes care of the dataset.
066   */
067  CUSTODIAN_STEWARD,
068  /**
069   * A contact involved in the publishing/distribution chain of a dataset.
070   */
071  DISTRIBUTOR,
072  /**
073   * A contact associated with editing a publication that used the dataset, or a data paper.
074   */
075  EDITOR,
076  /**
077   * A contact who owns the dataset (may or may not be the custodian).
078   */
079  OWNER,
080  /**
081   * A contact responsible for any post-collection processing of the dataset.
082   */
083  PROCESSOR,
084  /**
085   * A contact associated with the publishing of some entity (paper, article, book, etc) based on the dataset, or of a
086   * data paper.
087   */
088  PUBLISHER,
089  /**
090   * The contact that makes use of the dataset.
091   */
092  USER,
093  /**
094   * The contact providing informatics/programming support related to the dataset.
095   */
096  PROGRAMMER,
097  /**
098   * The contact that maintains and documents the specimens in a collection. Some of their duties include preparing and
099   * labeling specimens so they are ready for identification, and protecting the specimens.
100   */
101  CURATOR,
102  /**
103   * A contact who manages the operation of a data system.
104   */
105  DATA_ADMINISTRATOR,
106  /**
107   * A contact who manages the operation of a computer system.
108   */
109  SYSTEM_ADMINISTRATOR,
110  /**
111   * A contact appointed to lead and represent a Participant's delegation at the GBIF Governing Board.
112   */
113  HEAD_OF_DELEGATION,
114  /**
115   * A contact temporarily appointed to lead and represent a Participant's delegation at the GBIF Governing Board.
116   */
117  TEMPORARY_HEAD_OF_DELEGATION,
118  /**
119   * A contact appointed to a Participant's delegation at the GBIF Governing Board.
120   */
121  ADDITIONAL_DELEGATE,
122  /**
123   * A contact temporarily appointed to a Participant's delegation at the GBIF Governing Board.
124   */
125  TEMPORARY_DELEGATE,
126  /**
127   * A contact representing a regional group of Nodes.
128   */
129  REGIONAL_NODE_REPRESENTATIVE,
130  /**
131   * A contact leading the work of the Node and representing the Node in the Nodes Committee.
132   */
133  NODE_MANAGER,
134  /**
135   * A contact who is a member of the Node's staff.
136   */
137  NODE_STAFF;
138
139  /**
140   * @return the matching ContactType or null
141   */
142  public static ContactType fromString(String contactType) {
143    return (ContactType) VocabularyUtils.lookupEnum(contactType, ContactType.class);
144  }
145
146  // deliberate typos have existed and might be in genuine use
147  private static final ImmutableMap<String, ContactType> TYPE_LOOKUP = ImmutableMap.<String, ContactType> builder()
148    .put("administrative", ADMINISTRATIVE_POINT_OF_CONTACT)
149    .put("technical", TECHNICAL_POINT_OF_CONTACT)
150    .put("pointofcontact", POINT_OF_CONTACT)
151    .put("originator", ORIGINATOR)
152    .put("metadataprovider", METADATA_AUTHOR)
153    .put("principleinvestigator", PRINCIPAL_INVESTIGATOR)
154    .put("author", AUTHOR)
155    .put("contentprovider", CONTENT_PROVIDER)
156    .put("custodiansteward", CUSTODIAN_STEWARD)
157    .put("distributor", DISTRIBUTOR)
158    .put("editor", EDITOR)
159    .put("owner", OWNER)
160    .put("processor", PROCESSOR)
161    .put("publisher", PUBLISHER)
162    .put("user", USER)
163    .put("programmer", PROGRAMMER)
164    .put("curator", CURATOR)
165    .put("data administrator", DATA_ADMINISTRATOR)
166    .put("system adminsitrator", SYSTEM_ADMINISTRATOR) // deliberate typo
167    .put("system administrator", SYSTEM_ADMINISTRATOR)
168  .build();
169
170  /**
171   * Tries its best to infer a ContactType from a given string. This can for example be used for the various contact
172   * types from DiGIR, TAPIR and BioCASe.
173   *
174   * @return the inferred ContactType
175   */
176  public static ContactType inferType(@Nullable String type) {
177    if (type != null) {
178      ContactType contactType = TYPE_LOOKUP.get(type.toLowerCase());
179      if (contactType != null) {
180        return contactType;
181      }
182      return fromString(type);
183    }
184    return null;
185  }
186}