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.model.occurrence.search;
015import com.fasterxml.jackson.annotation.*;
016
017import com.fasterxml.jackson.core.JacksonException;
018
019import com.fasterxml.jackson.databind.DeserializationContext;
020import com.fasterxml.jackson.databind.JsonDeserializer;
021
022import com.fasterxml.jackson.databind.KeyDeserializer;
023import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
024import com.fasterxml.jackson.databind.node.ObjectNode;
025import org.gbif.api.model.common.search.SearchParameter;
026import org.gbif.api.util.IsoDateInterval;
027import org.gbif.api.vocabulary.BasisOfRecord;
028import org.gbif.api.vocabulary.Continent;
029import org.gbif.api.vocabulary.Country;
030import org.gbif.api.vocabulary.EndpointType;
031import org.gbif.api.vocabulary.GbifRegion;
032import org.gbif.api.vocabulary.License;
033import org.gbif.api.vocabulary.MediaType;
034import org.gbif.api.vocabulary.OccurrenceIssue;
035import org.gbif.api.vocabulary.OccurrenceStatus;
036import org.gbif.api.vocabulary.TaxonomicStatus;
037
038import java.io.IOException;
039import java.io.Serializable;
040import java.lang.reflect.Field;
041import java.util.ArrayList;
042import java.util.Date;
043import java.util.List;
044import java.util.Objects;
045import java.util.Optional;
046import java.util.UUID;
047
048/**
049 * Supported query parameters by the occurrence search and download service.
050 * For download predicates only the numerical types support comparisons other than equals.
051 */
052@JsonDeserialize(as = OccurrenceSearchParameter.class, using = OccurrenceSearchParameter.OccurrenceSearchParameterDeserializer.class)
053public class OccurrenceSearchParameter implements SearchParameter, Serializable {
054
055  /**
056   * The dataset key as a UUID.
057   */
058  public final static OccurrenceSearchParameter DATASET_KEY = new OccurrenceSearchParameter("DATASET_KEY", UUID.class);
059
060  /**
061   * The checklist key to use for taxonomy matching.
062   */
063  public final static OccurrenceSearchParameter CHECKLIST_KEY = new OccurrenceSearchParameter("CHECKLIST_KEY", String.class);
064
065  /**
066   * The 4 digit year. A year of 98 will be 98 common era, not 1998.
067   * This parameter accepts comma separated range values, e.g.:
068   * <dl>
069   * <dt>*,1810</dt>
070   * <dd>Found before or equal to 1810</dd>
071   * <dt>1848,1933</dt>
072   * <dd>Year between 1848 and 1933</dd>
073   * </dl>
074   */
075  public final static OccurrenceSearchParameter YEAR = new OccurrenceSearchParameter("YEAR", Integer.class);
076
077  /**
078   * The month of the year, starting with 1 for January.
079   * A month query can be used to retrieve seasonal records when used without a year or a year range.
080   * This parameter accepts comma separated range values, e.g.:
081   * <dl>
082   * <dt>4,8</dt>
083   * <dd>Month between April and August</dd>
084   * </dl>
085   */
086  public final static OccurrenceSearchParameter MONTH = new OccurrenceSearchParameter("MONTH", Integer.class);
087
088  /**
089   * The day of the month.
090   * This parameter accepts comma separated range values, e.g.:
091   * <dl>
092   * <dt>24,28</dt>
093   * <dd>Day of the month between 24 and 28</dd>
094   * </dl>
095   */
096  public final static OccurrenceSearchParameter DAY = new OccurrenceSearchParameter("DAY", Integer.class);
097
098  /**
099   * The earliest integer day of the year on which the event occurred (1 for January 1, 365 for December 31, except in a
100   * leap year, in which case it is 366).
101   */
102  public final static OccurrenceSearchParameter START_DAY_OF_YEAR = new OccurrenceSearchParameter("START_DAY_OF_YEAR", Integer.class);
103
104  /**
105   * The latest integer day of the year on which the event occurred (1 for January 1, 365 for December 31, except in a
106   * leap year, in which case it is 366).
107   */
108  public final static OccurrenceSearchParameter END_DAY_OF_YEAR = new OccurrenceSearchParameter("END_DAY_OF_YEAR", Integer.class);
109
110  /**
111   * Event date (date the occurrence was recorded) in ISO 8601 formats:yyyy, yyyy-MM, yyyy-MM-dd and MM-dd.
112   * This parameter accepts comma separated range values, examples of valid ranges are:
113   * <dl>
114   * <dt>2001-02-11,2010-01-10</dt>
115   * <dd>Dates between 2001-02-11 and 2010-01-10</dd>
116   * <dt>2001-02,2010-01</dt>
117   * <dd>Dates between first day of 2001-02 and last day of 2010-01</dd>
118   * <dt>2001,2010</dt>
119   * <dd>Dates between first day of 2001 and last day of 2010</dd>
120   * <dt>2001,2010-01</dt>
121   * <dd>Dates between first day of 2001 and last day of 2010-01</dd>
122   * <dt>2001-01-10,2010</dt>
123   * <dd>Dates between 2001-01-10 and last day of 2010</dd>
124   * <dt>2001-01-10,*</dt>
125   * <dd>Dates after 2001-01-10</dd>
126   * <dt>*,2001-01-10</dt>
127   * <dd>Dates before 2001-01-10</dd>
128   * <dt>*</dt>
129   * <dd>all dates</dd>
130   * </dl>
131   */
132  public final static OccurrenceSearchParameter EVENT_DATE = new OccurrenceSearchParameter("EVENT_DATE", IsoDateInterval.class);
133
134  /**
135   * Lower limit for the range of the event date (date the occurrence was recorded).
136   *
137   * Included for backward compatibility as it mimicks the previous search behaviour:
138   * https://github.com/gbif/occurrence/issues/346
139   */
140  @Deprecated
141  public final static OccurrenceSearchParameter EVENT_DATE_GTE = new OccurrenceSearchParameter("EVENT_DATE_GTE", Date.class);
142
143  /**
144   * An identifier for the set of information associated with an Event (something that occurs at a place and time).
145   * Maybe a global unique identifier or an identifier specific to the data set.
146   */
147  public final static OccurrenceSearchParameter EVENT_ID = new OccurrenceSearchParameter("EVENT_ID", String.class);
148
149  /**
150   * An identifier for the broader Event that groups this and potentially other Events.
151   */
152  public final static OccurrenceSearchParameter PARENT_EVENT_ID = new OccurrenceSearchParameter("PARENT_EVENT_ID", String.class);
153
154  /**
155   * The name of, reference to, or description of the method or protocol used during an Event.
156   */
157  public final static OccurrenceSearchParameter SAMPLING_PROTOCOL = new OccurrenceSearchParameter("SAMPLING_PROTOCOL", String.class);
158
159  /**
160   * A list (concatenated and separated) of previous assignments of names to the organism.
161   */
162  public final static OccurrenceSearchParameter PREVIOUS_IDENTIFICATIONS = new OccurrenceSearchParameter("PREVIOUS_IDENTIFICATIONS", String.class);
163
164  /**
165   * Last interpreted date in ISO 8601 formats:yyyy, yyyy-MM, yyyy-MM-dd and MM-dd.
166   * This parameter accepts comma separated range values, examples of valid ranges are:
167   * <dl>
168   * <dt>2001-02-11,2010-01-10</dt>
169   * <dd>Dates between 2001-02-11 and 2010-01-10</dd>
170   * <dt>2001-02,2010-01</dt>
171   * <dd>Dates between first day of 2001-02 and last day of 2010-01</dd>
172   * <dt>2001,2010</dt>
173   * <dd>Dates between first day of 2001 and last day of 2010</dd>
174   * <dt>2001,2010-01</dt>
175   * <dd>Dates between first day of 2001 and last day of 2010-01</dd>
176   * <dt>2001-01-10,2010</dt>
177   * <dd>Dates between 2001-01-10 and last day of 2010</dd>
178   * <dt>2001-01-10,*</dt>
179   * <dd>Dates after 2001-01-10</dd>
180   * <dt>*,2001-01-10</dt>
181   * <dd>Dates before 2001-01-10</dd>
182   * <dt>*</dt>
183   * <dd>all dates</dd>
184   * </dl>
185   */
186  public final static OccurrenceSearchParameter LAST_INTERPRETED = new OccurrenceSearchParameter("LAST_INTERPRETED", Date.class);
187
188
189  /**
190   * Modified date in ISO 8601 formats:yyyy, yyyy-MM, yyyy-MM-dd and MM-dd.
191   * This parameter accepts comma separated range values, examples of valid ranges are:
192   * <dl>
193   * <dt>2001-02-11,2010-01-10</dt>
194   * <dd>Dates between 2001-02-11 and 2010-01-10</dd>
195   * <dt>2001-02,2010-01</dt>
196   * <dd>Dates between first day of 2001-02 and last day of 2010-01</dd>
197   * <dt>2001,2010</dt>
198   * <dd>Dates between first day of 2001 and last day of 2010</dd>
199   * <dt>2001,2010-01</dt>
200   * <dd>Dates between first day of 2001 and last day of 2010-01</dd>
201   * <dt>2001-01-10,2010</dt>
202   * <dd>Dates between 2001-01-10 and last day of 2010</dd>
203   * <dt>2001-01-10,*</dt>
204   * <dd>Dates after 2001-01-10</dd>
205   * <dt>*,2001-01-10</dt>
206   * <dd>Dates before 2001-01-10</dd>
207   * <dt>*</dt>
208   * <dd>all dates</dd>
209   * </dl>
210   */
211  public final static OccurrenceSearchParameter MODIFIED = new OccurrenceSearchParameter("MODIFIED", Date.class);
212
213  /**
214   * Latitude in decimals between -90 and 90 based on WGS 84.
215   */
216  public final static OccurrenceSearchParameter DECIMAL_LATITUDE = new OccurrenceSearchParameter("DECIMAL_LATITUDE", Double.class);
217
218  /**
219   * Longitude in decimals between -180 and 180 based on WGS 84.
220   */
221  public final static OccurrenceSearchParameter DECIMAL_LONGITUDE = new OccurrenceSearchParameter("DECIMAL_LONGITUDE", Double.class);
222
223  /**
224   * The uncertainty of the coordinate in meters.
225   * This parameter accepts comma separated range values, e.g.:
226   * <dl>
227   * <dt>*,100</dt>
228   * <dd>Uncertainty below or equals 100m</dd>
229   * <dt>10000,*</dt>
230   * <dd>Uncertainty above or equals 10,000m</dd>
231   * <dt>1000,5000</dt>
232   * <dd>Uncertainty between or equals 1000m and 5000m
233   * </dd>
234   * </dl>
235   */
236  public final static OccurrenceSearchParameter COORDINATE_UNCERTAINTY_IN_METERS = new OccurrenceSearchParameter("COORDINATE_UNCERTAINTY_IN_METERS", Double.class);
237
238  /**
239   * Country the occurrence was recorded in.
240   */
241  public final static OccurrenceSearchParameter COUNTRY = new OccurrenceSearchParameter("COUNTRY", Country.class);
242
243  /**
244   * GBIF region based on country
245   */
246  public final static OccurrenceSearchParameter GBIF_REGION = new OccurrenceSearchParameter("GBIF_REGION", GbifRegion.class);
247
248  /**
249   * Continent the occurrence was recorded in.
250   */
251  public final static OccurrenceSearchParameter CONTINENT = new OccurrenceSearchParameter("CONTINENT", Continent.class);
252
253  /**
254   * The country of the organization that publishes the dataset the occurrence belongs to.
255   */
256  public final static OccurrenceSearchParameter PUBLISHING_COUNTRY = new OccurrenceSearchParameter("PUBLISHING_COUNTRY", Country.class);
257
258  /**
259   * GBIF region based on publishibg country
260   */
261  public final static OccurrenceSearchParameter PUBLISHED_BY_GBIF_REGION = new OccurrenceSearchParameter("PUBLISHED_BY_GBIF_REGION", GbifRegion.class);
262
263  /**
264   * Altitude/elevation in meters above sea level.
265   * This parameter accepts comma separated range values, e.g.:
266   * <dl>
267   * <dt>*,100</dt>
268   * <dd>Altitude below or equals 100m</dd>
269   * <dt>100,*</dt>
270   * <dd>Altitude above or equals 100m</dd>
271   * <dt>-2,8.8</dt>
272   * <dd>Altitude between or equals -2m and 8.8m</dd>
273   * </dl>
274   */
275  public final static OccurrenceSearchParameter ELEVATION = new OccurrenceSearchParameter("ELEVATION", Double.class);
276
277  /**
278   * Depth in meters relative to altitude. For example 10 meters below a lake surface with given altitude.
279   * This parameter accepts comma separated range values, e.g.:
280   * <dl>
281   * <dt>*,10</dt>
282   * <dd>Depth below or equals 10m</dd>
283   * <dt>100,*</dt>
284   * <dd>Depth above or equals 100m</dd>
285   * <dt>12.1,28.8</dt>
286   * <dd>Depth between or equals 12.1m and 28.8m</dd>
287   * </dl>
288   */
289  public final static OccurrenceSearchParameter DEPTH = new OccurrenceSearchParameter("DEPTH", Double.class);
290
291  /**
292   * An identifier of any form assigned by the source to identify the institution
293   * the record belongs to. Not guaranteed to be unique.
294   */
295  public final static OccurrenceSearchParameter INSTITUTION_CODE = new OccurrenceSearchParameter("INSTITUTION_CODE", String.class);
296
297  /**
298   * An identifier of any form assigned by the source to identify the physical collection or digital dataset
299   * uniquely within the context of an institution.
300   */
301  public final static OccurrenceSearchParameter COLLECTION_CODE = new OccurrenceSearchParameter("COLLECTION_CODE", String.class);
302
303  /**
304   * An identifier of any form assigned by the source within a physical collection or digital dataset for the record
305   * which may not be unique, but should be fairly unique in combination with the institution and collection code.
306   */
307  public final static OccurrenceSearchParameter CATALOG_NUMBER = new OccurrenceSearchParameter("CATALOG_NUMBER", String.class);
308
309  /**
310   * The person who recorded the occurrence.
311   */
312  public final static OccurrenceSearchParameter RECORDED_BY = new OccurrenceSearchParameter("RECORDED_BY", String.class);
313
314  /**
315   * The person who identified the occurrence.
316   */
317  public final static OccurrenceSearchParameter IDENTIFIED_BY = new OccurrenceSearchParameter("IDENTIFIED_BY", String.class);
318
319  /**
320   * An identifier given to the Occurrence at the time it was recorded.
321   */
322  public final static OccurrenceSearchParameter RECORD_NUMBER = new OccurrenceSearchParameter("RECORD_NUMBER", String.class);
323
324  /**
325   * A basis of record enumeration value.
326   */
327  public final static OccurrenceSearchParameter BASIS_OF_RECORD = new OccurrenceSearchParameter("BASIS_OF_RECORD", BasisOfRecord.class);
328
329  /**
330   * The sex of the biological individual(s) represented in the occurrence.
331   */
332  public final static OccurrenceSearchParameter SEX = new OccurrenceSearchParameter("SEX", String.class);
333
334  /**
335   * Presents of associated sequences or an extension
336   */
337  public final static OccurrenceSearchParameter IS_SEQUENCED = new OccurrenceSearchParameter("IS_SEQUENCED", Boolean.class);
338
339  /**
340   * A taxon key from the GBIF backbone. All included and synonym taxa are included in the search, so a search for
341   * aves with taxonKey=212 will match all birds, no matter which species.
342   */
343  public final static OccurrenceSearchParameter TAXON_KEY = new OccurrenceSearchParameter("TAXON_KEY", String.class);
344
345  /**
346   * A taxon key from the GBIF backbone for the name usage of the currently valid or accepted taxon.
347   */
348  public final static OccurrenceSearchParameter ACCEPTED_TAXON_KEY = new OccurrenceSearchParameter("ACCEPTED_TAXON_KEY", String.class);
349
350  /**
351   * A kingdom key from the GBIF backbone.
352   */
353  public final static OccurrenceSearchParameter KINGDOM_KEY = new OccurrenceSearchParameter("KINGDOM_KEY", String.class);
354
355  /**
356   * A phylum key from the GBIF backbone.
357   */
358  public final static OccurrenceSearchParameter PHYLUM_KEY = new OccurrenceSearchParameter("PHYLUM_KEY", String.class);
359
360  /**
361   * A class key from the GBIF backbone.
362   */
363  public final static OccurrenceSearchParameter CLASS_KEY = new OccurrenceSearchParameter("CLASS_KEY", String.class);
364
365  /**
366   * A order key from the GBIF backbone.
367   */
368  public final static OccurrenceSearchParameter ORDER_KEY = new OccurrenceSearchParameter("ORDER_KEY", String.class);
369
370  /**
371   * A family key from the GBIF backbone.
372   */
373  public final static OccurrenceSearchParameter FAMILY_KEY = new OccurrenceSearchParameter("FAMILY_KEY", String.class);
374
375  /**
376   * A genus key from the GBIF backbone.
377   */
378  public final static OccurrenceSearchParameter GENUS_KEY = new OccurrenceSearchParameter("GENUS_KEY", String.class);
379
380  /**
381   * A subgenus key from the GBIF backbone.
382   */
383  public final static OccurrenceSearchParameter SUBGENUS_KEY = new OccurrenceSearchParameter("SUBGENUS_KEY", String.class);
384
385  /**
386   * A species key from the GBIF backbone.
387   */
388  public final static OccurrenceSearchParameter SPECIES_KEY = new OccurrenceSearchParameter("SPECIES_KEY", String.class);
389
390  /**
391   * Searches the interpreted, full scientific name of the occurrence.
392   */
393  public final static OccurrenceSearchParameter SCIENTIFIC_NAME = new OccurrenceSearchParameter("SCIENTIFIC_NAME", String.class);
394
395  /**
396   * Scientific name as provided byt the source.
397   */
398  public final static OccurrenceSearchParameter VERBATIM_SCIENTIFIC_NAME = new OccurrenceSearchParameter("VERBATIM_SCIENTIFIC_NAME", String.class);
399
400  /**
401   * Verbatim identifier for the set of taxon information. Maybe a global unique identifier or an identifier specific to
402   * the data set.
403   */
404  public final static OccurrenceSearchParameter TAXON_ID = new OccurrenceSearchParameter("TAXON_ID", String.class);
405
406  /**
407   * An identifier for the taxonomic concept to which the record refers - not for the nomenclatural details of a taxon.
408   */
409  public final static OccurrenceSearchParameter TAXON_CONCEPT_ID = new OccurrenceSearchParameter("TAXON_CONCEPT_ID", String.class);
410
411  /**
412   * The status of the use of the  GBIF Backbone taxonKey.
413   */
414  public final static OccurrenceSearchParameter TAXONOMIC_STATUS = new OccurrenceSearchParameter("TAXONOMIC_STATUS", TaxonomicStatus.class);
415
416  /**
417   * Searches for occurrence records which contain a value on its coordinate fields (latitude and longitude).
418   * HAS_COORDINATE=true searches for occurrence records with a coordinate value.
419   * HAS_COORDINATE=false searches for occurrence records without a coordinate value.
420   */
421  public final static OccurrenceSearchParameter HAS_COORDINATE = new OccurrenceSearchParameter("HAS_COORDINATE", Boolean.class);
422
423  /**
424   * Geometry in <a href="https://en.wikipedia.org/wiki/Well-known_text">Well Known Text</a> (WKT) format.
425   * E.g.: POLYGON ((30.0 10.0, 10.12 20.23, 20 40, 40 40, 30 10)).
426   * Multi geometries like MULTIPOLYGON are not supported and multiple parameters should be used instead.
427   * Valid geometries are:
428   * <ul>
429   * <li>POINT</li>
430   * <li>LINESTRING</li>
431   * <li>POLYGON</li>
432   * <li>LINEARRING</li>
433   * </ul>
434   */
435  public final static OccurrenceSearchParameter GEOMETRY = new OccurrenceSearchParameter("GEOMETRY", String.class);
436
437  /**
438   * Use in combination of LATITUDE and LONGITUDE parameters matches within a given distance.
439   * E.g.: geo_distance=100m,40,90 geo_distance=100km,40,90 geo_distance=100mi,40,90.
440   * See supported units in {@link org.gbif.api.model.occurrence.geo.DistanceUnit}.
441   */
442  public final static OccurrenceSearchParameter GEO_DISTANCE = new OccurrenceSearchParameter("GEO_DISTANCE", String.class);
443
444  /**
445   * The distance from a known centroid, e.g. a country centroid.
446   */
447  public final static OccurrenceSearchParameter DISTANCE_FROM_CENTROID_IN_METERS = new OccurrenceSearchParameter("DISTANCE_FROM_CENTROID_IN_METERS", Double.class);
448
449  /**
450   * Includes/excludes occurrence records which contain geospatial issues for their coordinate.
451   * See {@link org.gbif.api.vocabulary.OccurrenceIssue#GEOSPATIAL_RULES}
452   * HAS_GEOSPATIAL_ISSUE=true include records with spatial issues.
453   * HAS_GEOSPATIAL_ISSUE=false exclude records with spatial issues.
454   * The absence of this parameter returns any record with or without spatial issues.
455   */
456  public final static OccurrenceSearchParameter HAS_GEOSPATIAL_ISSUE = new OccurrenceSearchParameter("HAS_GEOSPATIAL_ISSUE", Boolean.class);
457
458  /**
459   * Searches occurrence for those that have a specific issue.
460   */
461  public final static OccurrenceSearchParameter ISSUE = new OccurrenceSearchParameter("ISSUE", OccurrenceIssue.class);
462
463  /**
464   * Searches occurrence for those that have a specific taxonomic issue. This is separated out from the general issue
465   * field as taxonomic issues will be tied to a specific checklist.
466   */
467  public final static OccurrenceSearchParameter TAXONOMIC_ISSUE = new OccurrenceSearchParameter("TAXONOMIC_ISSUE", String.class);
468
469  /**
470   * Nomenclatural type (type status, typified scientific name, publication) applied to the subject.
471   */
472  public final static OccurrenceSearchParameter TYPE_STATUS = new OccurrenceSearchParameter("TYPE_STATUS", String.class);
473
474  /**
475   * The kind of media object.
476   * Recommended terms from the DCMI Type Vocabulary are StillImage, Sound or MovingImage for GBIF to index and show the
477   * media files.
478   */
479  public final static OccurrenceSearchParameter MEDIA_TYPE = new OccurrenceSearchParameter("MEDIA_TYPE", MediaType.class);
480
481  /**
482   *  An identifier for the Occurrence (as opposed to a particular digital record of the occurrence).
483   *  In the absence of a persistent global unique identifier, construct one from a combination of identifiers in the
484   *  record that will most closely make the occurrenceID globally unique.
485   */
486  public final static OccurrenceSearchParameter OCCURRENCE_ID = new OccurrenceSearchParameter("OCCURRENCE_ID", String.class);
487
488  /**
489   * The process by which the biological individual(s) represented in the Occurrence became established at the location.
490   */
491  public final static OccurrenceSearchParameter ESTABLISHMENT_MEANS = new OccurrenceSearchParameter("ESTABLISHMENT_MEANS", String.class);
492
493  /**
494   * Provides the controlled vocabulary for information about degree to which an Organism survives, reproduces, and expands its range at the given place and time.
495   */
496  public final static OccurrenceSearchParameter DEGREE_OF_ESTABLISHMENT = new OccurrenceSearchParameter("DEGREE_OF_ESTABLISHMENT", String.class);
497
498  /**
499   * Provides the controlled vocabulary for information about the process by which an Organism came to be in a given place at a given time.
500   * The pathway of an organism or organisms have been introduced to a given place and time.
501   */
502  public final static OccurrenceSearchParameter PATHWAY = new OccurrenceSearchParameter("PATHWAY", String.class);
503
504  /**
505   * Searches for records whose publishing country is different to the country where the record was recorded in.
506   */
507  public final static OccurrenceSearchParameter REPATRIATED = new OccurrenceSearchParameter("REPATRIATED", Boolean.class);
508
509  /**
510   * An identifier for the Organism instance (as opposed to a particular digital record of the Organism).
511   * May be a globally unique identifier or an identifier specific to the data set.
512   */
513  public final static OccurrenceSearchParameter ORGANISM_ID = new OccurrenceSearchParameter("ORGANISM_ID", String.class);
514
515  /**
516   * The name of the next smaller administrative region than country in which the Location occurs.
517   */
518  public final static OccurrenceSearchParameter STATE_PROVINCE = new OccurrenceSearchParameter("STATE_PROVINCE", String.class);
519
520  /**
521   * The name of the water body in which the Location occurs.
522   */
523  public final static OccurrenceSearchParameter WATER_BODY = new OccurrenceSearchParameter("WATER_BODY", String.class);
524
525  /**
526   * The specific description of the place.
527   * It may contain information modified from the original to correct perceived errors or standardize the description.
528   */
529  public final static OccurrenceSearchParameter LOCALITY = new OccurrenceSearchParameter("LOCALITY", String.class);
530
531  /**
532   * Protocol used to provide the occurrence record.
533   */
534  public final static OccurrenceSearchParameter PROTOCOL = new OccurrenceSearchParameter("PROTOCOL", EndpointType.class);
535
536  /**
537   * The license applied to the dataset.
538   */
539  public final static OccurrenceSearchParameter LICENSE = new OccurrenceSearchParameter("LICENSE", License.class);
540
541  /**
542   * The owning organizations uuid key.
543   */
544  public final static OccurrenceSearchParameter PUBLISHING_ORG = new OccurrenceSearchParameter("PUBLISHING_ORG", UUID.class);
545
546  /**
547   * The GBIF network that the publishing organisation belongs to.
548   */
549  public final static OccurrenceSearchParameter NETWORK_KEY = new OccurrenceSearchParameter("NETWORK_KEY", UUID.class);
550
551  /**
552   * The technical installation key that hosts/publishes this record.
553   */
554  public final static OccurrenceSearchParameter INSTALLATION_KEY = new OccurrenceSearchParameter("INSTALLATION_KEY", UUID.class);
555
556  /**
557   * The organization key of the installation that hosts this record.
558   */
559  public final static OccurrenceSearchParameter HOSTING_ORGANIZATION_KEY = new OccurrenceSearchParameter("HOSTING_ORGANIZATION_KEY", UUID.class);
560
561  /**
562   * Crawl attempt that harvested this record.
563   */
564  public final static OccurrenceSearchParameter CRAWL_ID = new OccurrenceSearchParameter("CRAWL_ID", Integer.class);
565
566  /**
567   * GBIF ProjectId.
568   */
569  public final static OccurrenceSearchParameter PROJECT_ID = new OccurrenceSearchParameter("PROJECT_ID", String.class);
570
571  /**
572   * GBIF Programme Acronym.
573   */
574  public final static OccurrenceSearchParameter PROGRAMME = new OccurrenceSearchParameter("PROGRAMME", String.class);
575
576  /**
577   * A number or enumeration value for the quantity of organisms.
578   */
579  public final static OccurrenceSearchParameter ORGANISM_QUANTITY = new OccurrenceSearchParameter("ORGANISM_QUANTITY", Double.class);
580
581  /**
582   * The type of quantification system used for the quantity of organisms.
583   */
584  public final static OccurrenceSearchParameter ORGANISM_QUANTITY_TYPE = new OccurrenceSearchParameter("ORGANISM_QUANTITY_TYPE", String.class);
585
586  /**
587   * The unit of measurement of the size (time duration, length, area, or volume) of a sample in a sampling event.
588   */
589  public final static OccurrenceSearchParameter SAMPLE_SIZE_UNIT = new OccurrenceSearchParameter("SAMPLE_SIZE_UNIT", String.class);
590
591  /**
592   * A numeric value for a measurement of the size (time duration, length, area, or volume) of a sample in a sampling event.
593   */
594  public final static OccurrenceSearchParameter SAMPLE_SIZE_VALUE = new OccurrenceSearchParameter("SAMPLE_SIZE_VALUE", Double.class);
595
596  /**
597   * Calculated organismQuantity relative to the sampleSizeValue i.e. -> organismQuantity / sampleSizeValue.
598   */
599  public final static OccurrenceSearchParameter RELATIVE_ORGANISM_QUANTITY = new OccurrenceSearchParameter("RELATIVE_ORGANISM_QUANTITY", Double.class);
600
601  /**
602   * Collection key. It links to the collection to which this record belongs.
603   */
604  public final static OccurrenceSearchParameter COLLECTION_KEY = new OccurrenceSearchParameter("COLLECTION_KEY", String.class);
605
606  /**
607   * Institution key. It links to the institution that maintains, recorded or digitized  this record.
608   */
609  public final static OccurrenceSearchParameter INSTITUTION_KEY = new OccurrenceSearchParameter("INSTITUTION_KEY", String.class);
610
611  /**
612   * Agent identifiers from GbifTerm.recordedByID
613   */
614  public final static OccurrenceSearchParameter RECORDED_BY_ID = new OccurrenceSearchParameter("RECORDED_BY_ID", String.class);
615
616  /**
617   * Agent identifiers from GbifTerm.identifiedByID
618   */
619  public final static OccurrenceSearchParameter IDENTIFIED_BY_ID = new OccurrenceSearchParameter("IDENTIFIED_BY_ID", String.class);
620
621  /**
622   * An occurrence status enumeration value.
623   */
624  public final static OccurrenceSearchParameter OCCURRENCE_STATUS = new OccurrenceSearchParameter("OCCURRENCE_STATUS", OccurrenceStatus.class);
625
626  /**
627   * A <a href="https://gadm.org">GADM</a> identifier at any level.
628   */
629  public final static OccurrenceSearchParameter GADM_GID = new OccurrenceSearchParameter("GADM_GID", String.class);
630
631  /**
632   * A <a href="https://gadm.org">GADM</a> country, island or territory (level zero) identifier.
633   */
634  public final static OccurrenceSearchParameter GADM_LEVEL_0_GID = new OccurrenceSearchParameter("GADM_LEVEL_0_GID", String.class);
635
636  /**
637   * A <a href="https://gadm.org">GADM</a> first-level identifier.
638   */
639  public final static OccurrenceSearchParameter GADM_LEVEL_1_GID = new OccurrenceSearchParameter("GADM_LEVEL_1_GID", String.class);
640
641  /**
642   * A <a href="https://gadm.org">GADM</a> second-level identifier.
643   */
644  public final static OccurrenceSearchParameter GADM_LEVEL_2_GID = new OccurrenceSearchParameter("GADM_LEVEL_2_GID", String.class);
645
646  /**
647   * A <a href="https://gadm.org">GADM</a> third-level identifier.
648   */
649  public final static OccurrenceSearchParameter GADM_LEVEL_3_GID = new OccurrenceSearchParameter("GADM_LEVEL_3_GID", String.class);
650
651  /**
652   * The life stage of an occurrence.
653   */
654  public final static OccurrenceSearchParameter LIFE_STAGE = new OccurrenceSearchParameter("LIFE_STAGE", String.class);
655
656  /**
657   * Searches for occurrences that are clustered.
658   */
659  public final static OccurrenceSearchParameter IS_IN_CLUSTER = new OccurrenceSearchParameter("IS_IN_CLUSTER", Boolean.class);
660
661  /**
662   * Searches for occurrences that have a particular DwC-A extension.
663   */
664  public final static OccurrenceSearchParameter DWCA_EXTENSION = new OccurrenceSearchParameter("DWCA_EXTENSION", String.class);
665
666  /**
667   * Searches for occurrences that have a IUCN Red List Category.
668   */
669  public final static OccurrenceSearchParameter IUCN_RED_LIST_CATEGORY = new OccurrenceSearchParameter("IUCN_RED_LIST_CATEGORY", String.class);
670
671  /**
672   * The dwc dataset id.
673   */
674  public final static OccurrenceSearchParameter DATASET_ID = new OccurrenceSearchParameter("DATASET_ID", String.class);
675
676  /**
677   * The dwc dataset name.
678   */
679  public final static OccurrenceSearchParameter DATASET_NAME = new OccurrenceSearchParameter("DATASET_NAME", String.class);
680
681  /**
682   * Other catalog numbers associated to an occurrence.
683   */
684  public final static OccurrenceSearchParameter OTHER_CATALOG_NUMBERS = new OccurrenceSearchParameter("OTHER_CATALOG_NUMBERS", String.class);
685
686  /**
687   * Preparations methods of an occurrence.
688   */
689  public final static OccurrenceSearchParameter PREPARATIONS = new OccurrenceSearchParameter("PREPARATIONS", String.class);
690
691  /**
692   * The name of the island on or near which the location occurs.
693   */
694  public final static OccurrenceSearchParameter ISLAND = new OccurrenceSearchParameter("ISLAND", String.class);
695
696  /**
697   * The name of the island group in which the location occurs.
698   */
699  public final static OccurrenceSearchParameter ISLAND_GROUP = new OccurrenceSearchParameter("ISLAND_GROUP", String.class);
700
701  /**
702   * A list (concatenated and separated) of names of people, groups, or organizations who determined the georeference
703   * (spatial representation) for the location.
704   */
705  public final static OccurrenceSearchParameter GEOREFERENCED_BY = new OccurrenceSearchParameter("GEOREFERENCED_BY", String.class);
706
707  /**
708   * A list (concatenated and separated) of geographic names less specific than the information captured in the locality
709   * term.
710   */
711  public final static OccurrenceSearchParameter HIGHER_GEOGRAPHY = new OccurrenceSearchParameter("HIGHER_GEOGRAPHY", String.class);
712
713  /**
714   *    An identifier given to the event in the field. Often serves as a link between field notes and the event.
715   */
716  public final static OccurrenceSearchParameter FIELD_NUMBER = new OccurrenceSearchParameter("FIELD_NUMBER", String.class);
717
718  /**
719   * The full name of the earliest possible geochronologic eon or lowest chrono-stratigraphic eonothem or the informal
720   * name ("Precambrian") attributable to the stratigraphic horizon from which the MaterialEntity was collected.
721   */
722  public final static OccurrenceSearchParameter EARLIEST_EON_OR_LOWEST_EONOTHEM = new OccurrenceSearchParameter("EARLIEST_EON_OR_LOWEST_EONOTHEM", String.class);
723
724  /**
725   * The full name of the latest possible geochronologic eon or highest chrono-stratigraphic eonothem or the informal
726   * name ("Precambrian") attributable to the stratigraphic horizon from which the MaterialEntity was collected.
727   */
728  public final static OccurrenceSearchParameter LATEST_EON_OR_HIGHEST_EONOTHEM = new OccurrenceSearchParameter("LATEST_EON_OR_HIGHEST_EONOTHEM", String.class);
729
730  /**
731   * The full name of the earliest possible geochronologic era or lowest chronostratigraphic erathem attributable to the
732   * stratigraphic horizon from which the MaterialEntity was collected.
733   */
734  public final static OccurrenceSearchParameter EARLIEST_ERA_OR_LOWEST_ERATHEM = new OccurrenceSearchParameter("EARLIEST_ERA_OR_LOWEST_ERATHEM", String.class);
735
736  /**
737   * The full name of the latest possible geochronologic era or highest chronostratigraphic erathem attributable to the
738   * stratigraphic horizon from which the MaterialEntity was collected.
739   */
740  public final static OccurrenceSearchParameter LATEST_ERA_OR_HIGHEST_ERATHEM = new OccurrenceSearchParameter("LATEST_ERA_OR_HIGHEST_ERATHEM", String.class);
741
742  /**
743   * The full name of the earliest possible geochronologic period or lowest chronostratigraphic system attributable to
744   * the stratigraphic horizon from which the MaterialEntity was collected.
745   */
746  public final static OccurrenceSearchParameter EARLIEST_PERIOD_OR_LOWEST_SYSTEM = new OccurrenceSearchParameter("EARLIEST_PERIOD_OR_LOWEST_SYSTEM", String.class);
747
748  /**
749   * The full name of the latest possible geochronologic period or highest chronostratigraphic system attributable to
750   * the stratigraphic horizon from which the MaterialEntity was collected.
751   */
752  public final static OccurrenceSearchParameter LATEST_PERIOD_OR_HIGHEST_SYSTEM = new OccurrenceSearchParameter("LATEST_PERIOD_OR_HIGHEST_SYSTEM", String.class);
753
754  /**
755   * The full name of the earliest possible geochronologic epoch or lowest chronostratigraphic series attributable to
756   * the stratigraphic horizon from which the MaterialEntity was collected.
757   */
758  public final static OccurrenceSearchParameter EARLIEST_EPOCH_OR_LOWEST_SERIES = new OccurrenceSearchParameter("EARLIEST_EPOCH_OR_LOWEST_SERIES", String.class);
759
760  /**
761   * The full name of the latest possible geochronologic epoch or highest chronostratigraphic series attributable to the
762   * stratigraphic horizon from which the MaterialEntity was collected.
763   */
764  public final static OccurrenceSearchParameter LATEST_EPOCH_OR_HIGHEST_SERIES = new OccurrenceSearchParameter("LATEST_EPOCH_OR_HIGHEST_SERIES", String.class);
765
766  /**
767   * The full name of the earliest possible geochronologic age or lowest chronostratigraphic stage attributable to the
768   * stratigraphic horizon from which the MaterialEntity was collected.
769   */
770  public final static OccurrenceSearchParameter EARLIEST_AGE_OR_LOWEST_STAGE = new OccurrenceSearchParameter("EARLIEST_AGE_OR_LOWEST_STAGE", String.class);
771
772  /**
773   * The full name of the latest possible geochronologic age or highest chronostratigraphic stage attributable to the
774   * stratigraphic horizon from which the MaterialEntity was collected.
775   */
776  public final static OccurrenceSearchParameter LATEST_AGE_OR_HIGHEST_STAGE = new OccurrenceSearchParameter("LATEST_AGE_OR_HIGHEST_STAGE", String.class);
777
778  /**
779   * The full name of the lowest possible geological biostratigraphic zone of the stratigraphic horizon from which the
780   * MaterialEntity was collected.
781   */
782  public final static OccurrenceSearchParameter LOWEST_BIOSTRATIGRAPHIC_ZONE = new OccurrenceSearchParameter("LOWEST_BIOSTRATIGRAPHIC_ZONE", String.class);
783
784  /**
785   * The full name of the highest possible geological biostratigraphic zone of the stratigraphic horizon from which the
786   * MaterialEntity was collected.
787   */
788  public final static OccurrenceSearchParameter HIGHEST_BIOSTRATIGRAPHIC_ZONE = new OccurrenceSearchParameter("HIGHEST_BIOSTRATIGRAPHIC_ZONE", String.class);
789
790  /**
791   * The full name of the lithostratigraphic group from which the MaterialEntity was collected.
792   */
793  public final static OccurrenceSearchParameter GROUP = new OccurrenceSearchParameter("GROUP", String.class);
794
795  /**
796   * The full name of the lithostratigraphic formation from which the MaterialEntity was collected.
797   */
798  public final static OccurrenceSearchParameter FORMATION = new OccurrenceSearchParameter("FORMATION", String.class);
799
800  /**
801   * The full name of the lithostratigraphic member from which the MaterialEntity was collected.
802   */
803  public final static OccurrenceSearchParameter MEMBER = new OccurrenceSearchParameter("MEMBER", String.class);
804
805  /**
806   * The full name of the lithostratigraphic bed from which the MaterialEntity was collected.
807   */
808  public final static OccurrenceSearchParameter BED = new OccurrenceSearchParameter("BED", String.class);
809
810  /**
811   * A list (concatenated and separated) of identifiers (publication, global unique identifier, URI) of
812   * genetic sequence information associated with the material entity.
813   */
814  public final static OccurrenceSearchParameter ASSOCIATED_SEQUENCES = new OccurrenceSearchParameter("ASSOCIATED_SEQUENCES", String.class);
815
816  /**
817   * Unique GBIF key for the occurrence.
818   */
819  public final static OccurrenceSearchParameter GBIF_ID = new OccurrenceSearchParameter("GBIF_ID", String.class);
820
821  /**
822   * Geological time of an occurrence that searchs in the chronostratigraphy fields.
823   */
824  public final static OccurrenceSearchParameter GEOLOGICAL_TIME = new OccurrenceSearchParameter("GEOLOGICAL_TIME", String.class);
825
826  /**
827   * Searches in the lithostratigraphy fields(bed, formation, group, member).
828   */
829  public final static OccurrenceSearchParameter LITHOSTRATIGRAPHY = new OccurrenceSearchParameter("LITHOSTRATIGRAPHY", String.class);
830
831  /**
832   * Searches in the biostratigraphy fields(lowest and highest biostratigraphy).
833   */
834  public final static OccurrenceSearchParameter BIOSTRATIGRAPHY = new OccurrenceSearchParameter("BIOSTRATIGRAPHY", String.class);
835
836  /**
837   * @return the data type expected for the value of the respective search parameter
838   */
839  public final static OccurrenceSearchParameter DNA_SEQUENCE_ID = new OccurrenceSearchParameter("DNA_SEQUENCE_ID", String.class);
840
841
842  public static OccurrenceSearchParameter[] values(){
843
844    Field[] values = OccurrenceSearchParameter.class.getFields();
845    List<OccurrenceSearchParameter> c = new ArrayList<>();
846    for (Field field: values) {
847      try {
848        c.add((OccurrenceSearchParameter) field.get(OccurrenceSearchParameter.class));
849      } catch (IllegalAccessException e) {
850        throw new RuntimeException(e);
851      }
852    }
853    return c.toArray(new OccurrenceSearchParameter[0]);
854  }
855
856  private Class<?> type;
857  private String name;
858
859  public OccurrenceSearchParameter() {}
860
861  public OccurrenceSearchParameter(String name, Class<?> type) {
862    this.name = name;
863    this.type = type;
864  }
865
866  @Override
867  public String name() {
868    return this.name;
869  }
870
871  public Class<?> getType() {
872    return type;
873  }
874
875  public String getName() {
876    return name;
877  }
878
879  @Override
880  public Class<?> type() {
881    return this.type;
882  }
883
884  @Override
885  public String toString() {
886    return name;
887  }
888
889  @Override
890  public boolean equals(Object o) {
891    if (this == o) return true;
892    if (o == null || getClass() != o.getClass()) return false;
893    OccurrenceSearchParameter that = (OccurrenceSearchParameter) o;
894    return Objects.equals(type, that.type) && Objects.equals(name, that.name);
895  }
896
897  @JsonValue
898  public String getSerializedValue() {
899    return name;
900  }
901
902  @Override
903  public int hashCode() {
904    return Objects.hash(type, name);
905  }
906
907  /**
908   * Lookup a parameter by its name.
909   * @param name the name of the parameter
910   * @return the parameter if found, otherwise empty
911   */
912  public static Optional<OccurrenceSearchParameter> lookup(String name) {
913    String normedType = name.toUpperCase().replaceAll("[. _-]", "");
914    java.lang.reflect.Field[] values = OccurrenceSearchParameter.class.getFields();
915    for (Field field: values) {
916
917      String fieldName = field.getName();
918      String normedVal = fieldName.replaceAll("[. _-]", "");
919      if (normedType.equals(normedVal)) {
920        try {
921          return Optional.of((OccurrenceSearchParameter) field.get(OccurrenceSearchParameter.class));
922        } catch (IllegalAccessException e) {
923          throw new RuntimeException(e);
924        }
925      }
926    }
927    return Optional.empty();
928  }
929
930  public static class OccurrenceSearchParameterKeyDeserializer extends KeyDeserializer {
931
932    @Override
933    public Object deserializeKey(String value, DeserializationContext deserializationContext) throws IOException {
934      Field[] values = OccurrenceSearchParameter.class.getFields();
935      try {
936        for (Field field: values) {
937          if (field.getName().equalsIgnoreCase(value)) {
938            return (OccurrenceSearchParameter) field.get(OccurrenceSearchParameter.class);
939          }
940        }
941      } catch (IllegalAccessException e) {
942        // DO NOTHING
943      }
944      return null;
945    }
946  }
947
948  public static class OccurrenceSearchParameterDeserializer extends JsonDeserializer<OccurrenceSearchParameter> {
949
950    @Override
951    public OccurrenceSearchParameter deserialize(com.fasterxml.jackson.core.JsonParser jsonParser, com.fasterxml.jackson.databind.DeserializationContext deserializationContext) throws IOException, JacksonException {
952
953      Field[] values = OccurrenceSearchParameter.class.getFields();
954      try {
955        String value = jsonParser.getText();
956        for (Field field: values) {
957          if (field.getName().equalsIgnoreCase(value)) {
958            return (OccurrenceSearchParameter) field.get(OccurrenceSearchParameter.class);
959          }
960        }
961
962      } catch (IllegalAccessException e) {
963        // DO NOTHING
964      }
965
966      try {
967        ObjectNode node = jsonParser.getCodec().readTree(jsonParser);
968        String value = node.get("name").asText();
969        for (Field field: values) {
970          if (field.getName().equalsIgnoreCase(value)) {
971            return (OccurrenceSearchParameter) field.get(OccurrenceSearchParameter.class);
972          }
973        }
974      } catch (Exception e) {
975        // DO NOTHING
976      }
977
978      return null;
979    }
980  }
981}