001/*
002 * Copyright 2014 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.jackson.ExtensionDeserializer;
019import org.gbif.api.jackson.ExtensionSerializer;
020
021import com.google.common.base.Strings;
022import org.codehaus.jackson.map.annotate.JsonDeserialize;
023import org.codehaus.jackson.map.annotate.JsonSerialize;
024
025/**
026 * Enumeration of dwc extensions for both Occurrence and Taxon that are indexed by GBIF.
027 *
028 * @see <a href="http://rs.gbif.org/extension">GBIF Resources</a>
029 */
030@JsonSerialize(using= ExtensionSerializer.class)
031@JsonDeserialize(using= ExtensionDeserializer.class)
032public enum Extension {
033
034  /**
035   * @see <a href="http://rs.gbif.org/extension/audubon/audubon.xml">extension definition</a>
036   */
037  AUDUBON("http://rs.tdwg.org/ac/terms/Multimedia"),
038
039  /**
040   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/description.xml">extension definition</a>
041   */
042  DESCRIPTION("http://rs.gbif.org/terms/1.0/Description"),
043
044  /**
045   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/distribution.xml">extension definition</a>
046   */
047  DISTRIBUTION("http://rs.gbif.org/terms/1.0/Distribution"),
048
049  /**
050   * @see <a href="http://eol.org/schema/media_extension.xml">extension definition</a>
051   */
052  EOL_MEDIA("http://eol.org/schema/media/Document"),
053
054  /**
055   * @see <a href="http://eol.org/schema/reference_extension.xml">extension definition</a>
056   */
057  EOL_REFERENCE("http://eol.org/schema/reference/Reference"),
058
059  /**
060   * @see <a href="http://rs.gbif.org/extension/germplasm/GermplasmAccession.xml">extension definition</a>
061   */
062  GERMPLASM_ACCESSION("http://purl.org/germplasm/germplasmTerm#GermplasmAccession"),
063
064  /**
065   * @see <a href="http://rs.gbif.org/extension/germplasm/MeasurementScore.xml">extension definition</a>
066   */
067  GERMPLASM_MEASUREMENT_SCORE("http://purl.org/germplasm/germplasmTerm#MeasurementScore"),
068
069  /**
070   * @see <a href="http://rs.gbif.org/extension/germplasm/MeasurementTrait.xml">extension definition</a>
071   */
072  GERMPLASM_MEASUREMENT_TRAIT("http://purl.org/germplasm/germplasmTerm#MeasurementTrait"),
073
074  /**
075   * @see <a href="http://rs.gbif.org/extension/germplasm/MeasurementTrial.xml">extension definition</a>
076   */
077  GERMPLASM_MEASUREMENT_TRIAL("http://purl.org/germplasm/germplasmTerm#MeasurementTrial"),
078
079  /**
080   * @see <a href="http://rs.gbif.org/extension/dwc/identification.xml">extension definition</a>
081   */
082  IDENTIFICATION("http://rs.tdwg.org/dwc/terms/Identification"),
083
084  /**
085   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/identifier.xml">extension definition</a>
086   */
087  IDENTIFIER("http://rs.gbif.org/terms/1.0/Identifier"),
088
089  /**
090   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/images.xml">extension definition</a>
091   */
092  IMAGE("http://rs.gbif.org/terms/1.0/Image"),
093
094  /**
095   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/images.xml">extension definition</a>
096   */
097  MEASUREMENT_OR_FACT("http://rs.tdwg.org/dwc/terms/MeasurementOrFact"),
098
099  /**
100   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/multimedia.xml">extension definition</a>
101   */
102  MULTIMEDIA("http://rs.gbif.org/terms/1.0/Multimedia"),
103
104  /**
105   * @see <a href="http://rs.gbif.org/extension/dwc/measurements_or_facts.xml">extension definition</a>
106   */
107  REFERENCE("http://rs.gbif.org/terms/1.0/Reference"),
108
109  /**
110   * @see <a href="http://rs.gbif.org/extension/dwc/resource_relation.xml">extension definition</a>
111   */
112  RESOURCE_RELATIONSHIP("http://rs.tdwg.org/dwc/terms/ResourceRelationship"),
113
114  /**
115   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/speciesprofile.xml">extension definition</a>
116   */
117  SPECIES_PROFILE("http://rs.gbif.org/terms/1.0/SpeciesProfile"),
118
119  /**
120   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/typesandspecimen.xml">extension definition</a>
121   */
122  TYPES_AND_SPECIMEN("http://rs.gbif.org/terms/1.0/TypesAndSpecimen"),
123
124  /**
125   * @see <a href="http://rs.gbif.org/extension/gbif/1.0/vernacularname.xml">extension definition</a>
126   */
127  VERNACULAR_NAME("http://rs.gbif.org/terms/1.0/VernacularName");
128
129
130  private final String rowType;
131
132  /**
133   * @param rowType the case insensitive row type uri for the extension
134   *
135   * @return the matching extension or null
136   */
137  public static Extension fromRowType(String rowType) {
138    if (!Strings.isNullOrEmpty(rowType)) {
139      for (Extension extension : Extension.values()) {
140        if (rowType.equalsIgnoreCase(extension.getRowType())
141            || rowType.equalsIgnoreCase(extension.name().replaceAll("_", ""))) {
142          return extension;
143        }
144      }
145    }
146    return null;
147  }
148
149  Extension(String rowType) {
150    this.rowType = rowType;
151  }
152
153  public String getRowType() {
154    return rowType;
155  }
156
157}