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 com.fasterxml.jackson.databind.annotation.JsonDeserialize;
017import com.fasterxml.jackson.databind.annotation.JsonSerialize;
018import java.util.EnumMap;
019import java.util.Map;
020import java.util.Set;
021import org.apache.commons.lang3.StringUtils;
022import org.gbif.api.jackson.ExtensionDeserializer;
023import org.gbif.api.jackson.ExtensionKeyDeserializer;
024import org.gbif.api.jackson.ExtensionKeySerializer;
025import org.gbif.api.jackson.ExtensionSerializer;
026import org.gbif.dwc.terms.DwcTerm;
027
028/**
029 * Enumeration of dwc extensions for both Occurrence and Taxon that are indexed by GBIF.
030 *
031 * @see <a href="http://rs.gbif.org/extension">GBIF Resources</a>
032 */
033@JsonSerialize(using = ExtensionSerializer.class, keyUsing = ExtensionKeySerializer.class)
034@JsonDeserialize(using = ExtensionDeserializer.class, keyUsing = ExtensionKeyDeserializer.class)
035public enum Extension {
036
037  /**
038   * @see <a href="http://rs.gbif.org/extension/audubon/audubon.xml">extension definition</a>
039   */
040  AUDUBON("http://rs.tdwg.org/ac/terms/Multimedia"),
041
042  /**
043   * @see <a href="http://data.ggbn.org/schemas/ggbn/terms/Amplification">extension definition</a>
044   */
045  AMPLIFICATION("http://data.ggbn.org/schemas/ggbn/terms/Amplification"),
046
047  /**
048   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/description.xml">extension definition</a>
049   */
050  DESCRIPTION("http://rs.gbif.org/terms/1.0/Description"),
051
052  /**
053   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/distribution.xml">extension definition</a>
054   */
055  DISTRIBUTION("http://rs.gbif.org/terms/1.0/Distribution"),
056
057  /**
058   * @see <a href="http://eol.org/schema/media_extension.xml">extension definition</a>
059   */
060  EOL_MEDIA("http://eol.org/schema/media/Document"),
061
062  /**
063   * @see <a href="http://eol.org/schema/reference_extension.xml">extension definition</a>
064   */
065  EOL_REFERENCE("http://eol.org/schema/reference/Reference"),
066
067  /**
068   * @see <a href="http://rs.gbif.org/extension/germplasm/GermplasmAccession.xml">extension definition</a>
069   */
070  GERMPLASM_ACCESSION("http://purl.org/germplasm/germplasmTerm#GermplasmAccession"),
071
072  /**
073   * @see <a href="http://rs.gbif.org/extension/germplasm/MeasurementScore.xml">extension definition</a>
074   */
075  GERMPLASM_MEASUREMENT_SCORE("http://purl.org/germplasm/germplasmTerm#MeasurementScore"),
076
077  /**
078   * @see <a href="http://rs.gbif.org/extension/germplasm/MeasurementTrait.xml">extension definition</a>
079   */
080  GERMPLASM_MEASUREMENT_TRAIT("http://purl.org/germplasm/germplasmTerm#MeasurementTrait"),
081
082  /**
083   * @see <a href="http://rs.gbif.org/extension/germplasm/MeasurementTrial.xml">extension definition</a>
084   */
085  GERMPLASM_MEASUREMENT_TRIAL("http://purl.org/germplasm/germplasmTerm#MeasurementTrial"),
086
087  /**
088   * @see <a href="http://rs.gbif.org/extension/dwc/identification.xml">extension definition</a>
089   */
090  IDENTIFICATION("http://rs.tdwg.org/dwc/terms/Identification"),
091
092  /**
093   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/identifier.xml">extension definition</a>
094   */
095  IDENTIFIER("http://rs.gbif.org/terms/1.0/Identifier"),
096
097  /**
098   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/images.xml">extension definition</a>
099   */
100  IMAGE("http://rs.gbif.org/terms/1.0/Image"),
101
102  /**
103   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/images.xml">extension definition</a>
104   */
105  MEASUREMENT_OR_FACT("http://rs.tdwg.org/dwc/terms/MeasurementOrFact"),
106
107  /**
108   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/multimedia.xml">extension definition</a>
109   */
110  MULTIMEDIA("http://rs.gbif.org/terms/1.0/Multimedia"),
111
112  /**
113   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/references.xml">extension definition</a>
114   */
115  REFERENCE("http://rs.gbif.org/terms/1.0/Reference"),
116
117  /**
118   * @see <a href="http://rs.gbif.org/extension/dwc/resource_relation.xml">extension definition</a>
119   */
120  RESOURCE_RELATIONSHIP("http://rs.tdwg.org/dwc/terms/ResourceRelationship"),
121
122  /**
123   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/speciesprofile.xml">extension definition</a>
124   */
125  SPECIES_PROFILE("http://rs.gbif.org/terms/1.0/SpeciesProfile"),
126
127  /**
128   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/typesandspecimen.xml">extension definition</a>
129   */
130  TYPES_AND_SPECIMEN("http://rs.gbif.org/terms/1.0/TypesAndSpecimen"),
131
132  /**
133   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/vernacularname.xml">extension definition</a>
134   */
135  VERNACULAR_NAME("http://rs.gbif.org/terms/1.0/VernacularName"),
136
137  /**
138   * @see <a href="http://rs.gbif.org/extension/ggbn/cloning.xml">extension definition</a>
139   */
140  CLONING("http://data.ggbn.org/schemas/ggbn/terms/Cloning"),
141
142  /**
143   * @see <a href="http://rs.gbif.org/extension/ggbn/gelimage.xml">extension definition</a>
144   */
145  GEL_IMAGE("http://data.ggbn.org/schemas/ggbn/terms/GelImage"),
146
147  /**
148   * @see <a href="http://rs.gbif.org/extension/ggbn/loan.xml">extension definition</a>
149   */
150  LOAN("http://data.ggbn.org/schemas/ggbn/terms/Loan"),
151
152  /**
153   * @see <a href="http://rs.gbif.org/extension/ggbn/materialsample.xml">extension definition</a>
154   */
155  MATERIAL_SAMPLE("http://data.ggbn.org/schemas/ggbn/terms/MaterialSample"),
156
157  /**
158   * @see <a href="http://rs.gbif.org/extension/ggbn/permit.xml">extension definition</a>
159   */
160  PERMIT("http://data.ggbn.org/schemas/ggbn/terms/Permit"),
161
162  /**
163   * @see <a href="http://rs.gbif.org/extension/ggbn/preparation.xml">extension definition</a>
164   */
165  PREPARATION("http://data.ggbn.org/schemas/ggbn/terms/Preparation"),
166
167  /**
168   * @see <a href="http://rs.gbif.org/extension/ggbn/preservation.xml">extension definition</a>
169   */
170  PRESERVATION("http://data.ggbn.org/schemas/ggbn/terms/Preservation"),
171
172  /**
173   * @see <a href="http://rs.gbif.org/extension/obis/extended_measurement_or_fact.xml">extension definition</a>
174   */
175  EXTENDED_MEASUREMENT_OR_FACT("http://rs.iobis.org/obis/terms/ExtendedMeasurementOrFact"),
176
177  /**
178   * @see <a href="http://rs.gbif.org/extension/zooarchnet/ChronometricAge_2020-10-06.xml">extension definition</a>
179   */
180  CHRONOMETRIC_AGE("http://rs.tdwg.org/chrono/terms/ChronometricAge"),
181
182  /**
183   * @see <a href="http://rs.gbif.org/extension/zooarchnet/chronometricDate.xml">extension definition</a>
184   */
185  CHRONOMETRIC_DATE("http://zooarchnet.org/dwc/terms/ChronometricDate"),
186
187  /**
188   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/dna_derived_data_2024-07-11.xml">extension definition</a>
189   */
190  DNA_DERIVED_DATA("http://rs.gbif.org/terms/1.0/DNADerivedData"),
191
192  /**
193   * @see <a href="https://rs.gbif.org/extension/eco/Humboldt_2024-04-16.xml">extension definition</a>
194   */
195  HUMBOLDT("http://rs.tdwg.org/eco/terms/Event"),
196
197  /**
198   * @see <a href="http://rs.tdwg.org/dwc/terms/Occurrence">extension definition</a>
199   */
200  OCCURRENCE("http://rs.tdwg.org/dwc/terms/Occurrence");
201
202
203  private final String rowType;
204
205  /**
206   * @param rowType the case-insensitive row type uri for the extension
207   * @return the matching extension or null
208   */
209  public static Extension fromRowType(String rowType) {
210    if (StringUtils.isNotEmpty(rowType)) {
211      for (Extension extension : Extension.values()) {
212        if (rowType.equalsIgnoreCase(extension.getRowType())
213          || rowType.equalsIgnoreCase(extension.name().replaceAll("_", ""))) {
214          return extension;
215        }
216      }
217    }
218    return null;
219  }
220
221  Extension(String rowType) {
222    this.rowType = rowType;
223  }
224
225  public String getRowType() {
226    return rowType;
227  }
228
229  private static final Map<Extension, String> AVAILABLE_INTERPRETED_OCCURRENCE_EXTENSION_MAP = new EnumMap<>(Extension.class);
230  private static final Map<Extension, String> AVAILABLE_INTERPRETED_EVENTS_EXTENSION_MAP = new EnumMap<>(Extension.class);
231  private static final Map<Extension, String> AVAILABLE_EXTENSION_MAP = new EnumMap<>(Extension.class);
232
233  static {
234    AVAILABLE_EXTENSION_MAP.put(AUDUBON, "http://rs.gbif.org/extension/ac/audubon_2020_10_06.xml");
235    AVAILABLE_EXTENSION_MAP.put(IMAGE, "http://rs.gbif.org/extension/gbif/1.0/images.xml");
236    AVAILABLE_EXTENSION_MAP.put(MULTIMEDIA, "http://rs.gbif.org/extension/gbif/1.0/multimedia.xml");
237    AVAILABLE_EXTENSION_MAP.put(MEASUREMENT_OR_FACT, "http://rs.gbif.org/extension/dwc/measurements_or_facts.xml");
238    AVAILABLE_EXTENSION_MAP.put(IDENTIFICATION, "http://rs.gbif.org/extension/dwc/identification.xml");
239    AVAILABLE_EXTENSION_MAP.put(RESOURCE_RELATIONSHIP, "http://rs.gbif.org/extension/dwc/resource_relation.xml");
240    AVAILABLE_EXTENSION_MAP.put(AMPLIFICATION, "http://rs.gbif.org/extension/ggbn/amplification.xml");
241    AVAILABLE_EXTENSION_MAP.put(CLONING, "http://rs.gbif.org/extension/ggbn/cloning.xml");
242    AVAILABLE_EXTENSION_MAP.put(GEL_IMAGE, "http://rs.gbif.org/extension/ggbn/gelimage.xml");
243    AVAILABLE_EXTENSION_MAP.put(LOAN, "http://rs.gbif.org/extension/ggbn/loan.xml");
244    AVAILABLE_EXTENSION_MAP.put(MATERIAL_SAMPLE, "http://rs.gbif.org/extension/ggbn/materialsample.xml");
245    AVAILABLE_EXTENSION_MAP.put(PERMIT, "http://rs.gbif.org/extension/ggbn/permit.xml");
246    AVAILABLE_EXTENSION_MAP.put(PREPARATION, "http://rs.gbif.org/extension/ggbn/preparation.xml");
247    AVAILABLE_EXTENSION_MAP.put(PRESERVATION, "http://rs.gbif.org/extension/ggbn/preservation.xml");
248    AVAILABLE_EXTENSION_MAP.put(GERMPLASM_MEASUREMENT_SCORE, "http://rs.gbif.org/extension/germplasm/MeasurementScore.xml");
249    AVAILABLE_EXTENSION_MAP.put(GERMPLASM_MEASUREMENT_TRAIT, "http://rs.gbif.org/extension/germplasm/MeasurementTrait.xml");
250    AVAILABLE_EXTENSION_MAP.put(GERMPLASM_MEASUREMENT_TRIAL, "http://rs.gbif.org/extension/germplasm/MeasurementTrial.xml");
251    AVAILABLE_EXTENSION_MAP.put(GERMPLASM_ACCESSION, "http://rs.gbif.org/extension/germplasm/GermplasmAccession.xml");
252    AVAILABLE_EXTENSION_MAP.put(EXTENDED_MEASUREMENT_OR_FACT, "http://rs.gbif.org/extension/obis/extended_measurement_or_fact.xml");
253    AVAILABLE_EXTENSION_MAP.put(CHRONOMETRIC_AGE, "http://rs.gbif.org/extension/dwc/ChronometricAge_2021-03-27.xml");
254    AVAILABLE_EXTENSION_MAP.put(REFERENCE, "http://rs.gbif.org/extension/gbif/1.0/references.xml");
255    AVAILABLE_EXTENSION_MAP.put(IDENTIFIER, "http://rs.gbif.org/extension/gbif/1.0/identifier.xml");
256    AVAILABLE_EXTENSION_MAP.put(DNA_DERIVED_DATA, "http://rs.gbif.org/extension/gbif/1.0/dna_derived_data_2024-07-11.xml");
257    AVAILABLE_EXTENSION_MAP.put(HUMBOLDT, "http://rs.gbif.org/extension/eco/humboldt_2025-07-10.xml");
258    AVAILABLE_EXTENSION_MAP.put(OCCURRENCE, "http://rs.gbif.org/core/dwc_occurrence.xml");
259
260    AVAILABLE_INTERPRETED_EVENTS_EXTENSION_MAP.put(MULTIMEDIA, "http://rs.gbif.org/extension/gbif/1.0/multimedia.xml");
261    AVAILABLE_INTERPRETED_EVENTS_EXTENSION_MAP.put(HUMBOLDT, "http://rs.gbif.org/extension/eco/humboldt_2025-07-10.xml");
262    AVAILABLE_INTERPRETED_EVENTS_EXTENSION_MAP.put(OCCURRENCE, "http://rs.gbif.org/core/dwc_occurrence.xml");
263
264    AVAILABLE_INTERPRETED_OCCURRENCE_EXTENSION_MAP.put(MULTIMEDIA, "http://rs.gbif.org/extension/gbif/1.0/multimedia.xml");
265  }
266
267  public static Map<Extension, String> availableExtensionResources() {
268    return AVAILABLE_EXTENSION_MAP;
269  }
270
271  public static Set<Extension> availableExtensions() {
272    return AVAILABLE_EXTENSION_MAP.keySet();
273  }
274
275  public static Set<Extension> availableInterpretedExtensions(DwcTerm coreTerm) {
276    return coreTerm == DwcTerm.Event
277        ? AVAILABLE_INTERPRETED_EVENTS_EXTENSION_MAP.keySet()
278        : AVAILABLE_INTERPRETED_OCCURRENCE_EXTENSION_MAP.keySet();
279  }
280}