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