001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 *     http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package org.gbif.api.vocabulary;
015
016import org.gbif.api.jackson.ExtensionDeserializer;
017import org.gbif.api.jackson.ExtensionKeyDeserializer;
018import org.gbif.api.jackson.ExtensionKeySerializer;
019import org.gbif.api.jackson.ExtensionSerializer;
020
021import java.util.EnumMap;
022import java.util.Map;
023import java.util.Set;
024
025import org.apache.commons.lang3.StringUtils;
026
027import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
028import com.fasterxml.jackson.databind.annotation.JsonSerialize;
029
030/**
031 * Enumeration of dwc extensions for both Occurrence and Taxon that are indexed by GBIF.
032 *
033 * @see <a href="http://rs.gbif.org/extension">GBIF Resources</a>
034 */
035@JsonSerialize(using = ExtensionSerializer.class, keyUsing = ExtensionKeySerializer.class)
036@JsonDeserialize(using = ExtensionDeserializer.class, keyUsing = ExtensionKeyDeserializer.class)
037public enum Extension {
038
039  /**
040   * @see <a href="http://rs.gbif.org/extension/audubon/audubon.xml">extension definition</a>
041   */
042  AUDUBON("http://rs.tdwg.org/ac/terms/Multimedia"),
043
044  /**
045   * @see <a href="http://data.ggbn.org/schemas/ggbn/terms/Amplification">extension definition</a>
046   */
047  AMPLIFICATION("http://data.ggbn.org/schemas/ggbn/terms/Amplification"),
048
049  /**
050   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/description.xml">extension definition</a>
051   */
052  DESCRIPTION("http://rs.gbif.org/terms/1.0/Description"),
053
054  /**
055   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/distribution.xml">extension definition</a>
056   */
057  DISTRIBUTION("http://rs.gbif.org/terms/1.0/Distribution"),
058
059  /**
060   * @see <a href="http://eol.org/schema/media_extension.xml">extension definition</a>
061   */
062  EOL_MEDIA("http://eol.org/schema/media/Document"),
063
064  /**
065   * @see <a href="http://eol.org/schema/reference_extension.xml">extension definition</a>
066   */
067  EOL_REFERENCE("http://eol.org/schema/reference/Reference"),
068
069  /**
070   * @see <a href="http://rs.gbif.org/extension/germplasm/GermplasmAccession.xml">extension definition</a>
071   */
072  GERMPLASM_ACCESSION("http://purl.org/germplasm/germplasmTerm#GermplasmAccession"),
073
074  /**
075   * @see <a href="http://rs.gbif.org/extension/germplasm/MeasurementScore.xml">extension definition</a>
076   */
077  GERMPLASM_MEASUREMENT_SCORE("http://purl.org/germplasm/germplasmTerm#MeasurementScore"),
078
079  /**
080   * @see <a href="http://rs.gbif.org/extension/germplasm/MeasurementTrait.xml">extension definition</a>
081   */
082  GERMPLASM_MEASUREMENT_TRAIT("http://purl.org/germplasm/germplasmTerm#MeasurementTrait"),
083
084  /**
085   * @see <a href="http://rs.gbif.org/extension/germplasm/MeasurementTrial.xml">extension definition</a>
086   */
087  GERMPLASM_MEASUREMENT_TRIAL("http://purl.org/germplasm/germplasmTerm#MeasurementTrial"),
088
089  /**
090   * @see <a href="http://rs.gbif.org/extension/dwc/identification.xml">extension definition</a>
091   */
092  IDENTIFICATION("http://rs.tdwg.org/dwc/terms/Identification"),
093
094  /**
095   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/identifier.xml">extension definition</a>
096   */
097  IDENTIFIER("http://rs.gbif.org/terms/1.0/Identifier"),
098
099  /**
100   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/images.xml">extension definition</a>
101   */
102  IMAGE("http://rs.gbif.org/terms/1.0/Image"),
103
104  /**
105   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/images.xml">extension definition</a>
106   */
107  MEASUREMENT_OR_FACT("http://rs.tdwg.org/dwc/terms/MeasurementOrFact"),
108
109  /**
110   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/multimedia.xml">extension definition</a>
111   */
112  MULTIMEDIA("http://rs.gbif.org/terms/1.0/Multimedia"),
113
114  /**
115   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/references.xml">extension definition</a>
116   */
117  REFERENCE("http://rs.gbif.org/terms/1.0/Reference"),
118
119  /**
120   * @see <a href="http://rs.gbif.org/extension/dwc/resource_relation.xml">extension definition</a>
121   */
122  RESOURCE_RELATIONSHIP("http://rs.tdwg.org/dwc/terms/ResourceRelationship"),
123
124  /**
125   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/speciesprofile.xml">extension definition</a>
126   */
127  SPECIES_PROFILE("http://rs.gbif.org/terms/1.0/SpeciesProfile"),
128
129  /**
130   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/typesandspecimen.xml">extension definition</a>
131   */
132  TYPES_AND_SPECIMEN("http://rs.gbif.org/terms/1.0/TypesAndSpecimen"),
133
134  /**
135   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/vernacularname.xml">extension definition</a>
136   */
137  VERNACULAR_NAME("http://rs.gbif.org/terms/1.0/VernacularName"),
138
139  /**
140   * @see <a href="http://rs.gbif.org/extension/ggbn/cloning.xml">extension definition</a>
141   */
142  CLONING("http://data.ggbn.org/schemas/ggbn/terms/Cloning"),
143
144  /**
145   * @see <a href="http://rs.gbif.org/extension/ggbn/gelimage.xml">extension definition</a>
146   */
147  GEL_IMAGE("http://data.ggbn.org/schemas/ggbn/terms/GelImage"),
148
149  /**
150   * @see <a href="http://rs.gbif.org/extension/ggbn/loan.xml">extension definition</a>
151   */
152  LOAN("http://data.ggbn.org/schemas/ggbn/terms/Loan"),
153
154  /**
155   * @see <a href="http://rs.gbif.org/extension/ggbn/materialsample.xml">extension definition</a>
156   */
157  MATERIAL_SAMPLE("http://data.ggbn.org/schemas/ggbn/terms/MaterialSample"),
158
159  /**
160   * @see <a href="http://rs.gbif.org/extension/ggbn/permit.xml">extension definition</a>
161   */
162  PERMIT("http://data.ggbn.org/schemas/ggbn/terms/Permit"),
163
164  /**
165   * @see <a href="http://rs.gbif.org/extension/ggbn/preparation.xml">extension definition</a>
166   */
167  PREPARATION("http://data.ggbn.org/schemas/ggbn/terms/Preparation"),
168
169  /**
170   * @see <a href="http://rs.gbif.org/extension/ggbn/preservation.xml">extension definition</a>
171   */
172  PRESERVATION("http://data.ggbn.org/schemas/ggbn/terms/Preservation"),
173
174  /**
175   * @see <a href="http://rs.gbif.org/extension/obis/extended_measurement_or_fact.xml">extension definition</a>
176   */
177  EXTENDED_MEASUREMENT_OR_FACT("http://rs.iobis.org/obis/terms/ExtendedMeasurementOrFact"),
178
179  /**
180   * @see <a href="http://rs.gbif.org/extension/zooarchnet/ChronometricAge_2020-10-06.xml">extension definition</a>
181   */
182  CHRONOMETRIC_AGE("http://rs.tdwg.org/chrono/terms/ChronometricAge"),
183
184  /**
185   * @see <a href="http://rs.gbif.org/extension/zooarchnet/chronometricDate.xml">extension definition</a>
186   */
187  CHRONOMETRIC_DATE("http://zooarchnet.org/dwc/terms/ChronometricDate"),
188
189  /**
190   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/dna_derived_data_2022-02-23.xml">extension definition</a>
191   */
192  DNA_DERIVED_DATA("http://rs.gbif.org/terms/1.0/DNADerivedData");
193
194
195  private final String rowType;
196
197  /**
198   * @param rowType the case-insensitive row type uri for the extension
199   * @return the matching extension or null
200   */
201  public static Extension fromRowType(String rowType) {
202    if (StringUtils.isNotEmpty(rowType)) {
203      for (Extension extension : Extension.values()) {
204        if (rowType.equalsIgnoreCase(extension.getRowType())
205          || rowType.equalsIgnoreCase(extension.name().replaceAll("_", ""))) {
206          return extension;
207        }
208      }
209    }
210    return null;
211  }
212
213  Extension(String rowType) {
214    this.rowType = rowType;
215  }
216
217  public String getRowType() {
218    return rowType;
219  }
220
221  private static final Map<Extension, String> AVAILABLE_EXTENSION_MAP = new EnumMap<>(Extension.class);
222
223  static {
224    AVAILABLE_EXTENSION_MAP.put(AUDUBON, "http://rs.gbif.org/extension/ac/audubon_2020_10_06.xml");
225    AVAILABLE_EXTENSION_MAP.put(IMAGE, "http://rs.gbif.org/extension/gbif/1.0/images.xml");
226    AVAILABLE_EXTENSION_MAP.put(MULTIMEDIA, "http://rs.gbif.org/extension/gbif/1.0/multimedia.xml");
227    AVAILABLE_EXTENSION_MAP.put(MEASUREMENT_OR_FACT, "http://rs.gbif.org/extension/dwc/measurements_or_facts.xml");
228    AVAILABLE_EXTENSION_MAP.put(IDENTIFICATION, "http://rs.gbif.org/extension/dwc/identification.xml");
229    AVAILABLE_EXTENSION_MAP.put(RESOURCE_RELATIONSHIP, "http://rs.gbif.org/extension/dwc/resource_relation.xml");
230    AVAILABLE_EXTENSION_MAP.put(AMPLIFICATION, "http://rs.gbif.org/extension/ggbn/amplification.xml");
231    AVAILABLE_EXTENSION_MAP.put(CLONING, "http://rs.gbif.org/extension/ggbn/cloning.xml");
232    AVAILABLE_EXTENSION_MAP.put(GEL_IMAGE, "http://rs.gbif.org/extension/ggbn/gelimage.xml");
233    AVAILABLE_EXTENSION_MAP.put(LOAN, "http://rs.gbif.org/extension/ggbn/loan.xml");
234    AVAILABLE_EXTENSION_MAP.put(MATERIAL_SAMPLE, "http://rs.gbif.org/extension/ggbn/materialsample.xml");
235    AVAILABLE_EXTENSION_MAP.put(PERMIT, "http://rs.gbif.org/extension/ggbn/permit.xml");
236    AVAILABLE_EXTENSION_MAP.put(PREPARATION, "http://rs.gbif.org/extension/ggbn/preparation.xml");
237    AVAILABLE_EXTENSION_MAP.put(PRESERVATION, "http://rs.gbif.org/extension/ggbn/preservation.xml");
238    AVAILABLE_EXTENSION_MAP.put(GERMPLASM_MEASUREMENT_SCORE, "http://rs.gbif.org/extension/germplasm/MeasurementScore.xml");
239    AVAILABLE_EXTENSION_MAP.put(GERMPLASM_MEASUREMENT_TRAIT, "http://rs.gbif.org/extension/germplasm/MeasurementTrait.xml");
240    AVAILABLE_EXTENSION_MAP.put(GERMPLASM_MEASUREMENT_TRIAL, "http://rs.gbif.org/extension/germplasm/MeasurementTrial.xml");
241    AVAILABLE_EXTENSION_MAP.put(GERMPLASM_ACCESSION, "http://rs.gbif.org/extension/germplasm/GermplasmAccession.xml");
242    AVAILABLE_EXTENSION_MAP.put(EXTENDED_MEASUREMENT_OR_FACT, "http://rs.gbif.org/extension/obis/extended_measurement_or_fact.xml");
243    AVAILABLE_EXTENSION_MAP.put(CHRONOMETRIC_AGE, "http://rs.gbif.org/extension/dwc/ChronometricAge_2021-03-27.xml");
244    AVAILABLE_EXTENSION_MAP.put(REFERENCE, "http://rs.gbif.org/extension/gbif/1.0/references.xml");
245    AVAILABLE_EXTENSION_MAP.put(IDENTIFIER, "http://rs.gbif.org/extension/gbif/1.0/identifier.xml");
246    AVAILABLE_EXTENSION_MAP.put(DNA_DERIVED_DATA, "http://rs.gbif.org/extension/gbif/1.0/dna_derived_data_2022-02-23.xml");
247  }
248
249  public static Map<Extension, String> availableExtensionResources() {
250    return AVAILABLE_EXTENSION_MAP;
251  }
252
253  public static Set<Extension> availableExtensions() {
254    return AVAILABLE_EXTENSION_MAP.keySet();
255  }
256
257}