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.event.search; 015 016import com.fasterxml.jackson.annotation.*; 017import com.fasterxml.jackson.core.JacksonException; 018import com.fasterxml.jackson.databind.DeserializationContext; 019import com.fasterxml.jackson.databind.JsonDeserializer; 020import com.fasterxml.jackson.databind.KeyDeserializer; 021import com.fasterxml.jackson.databind.annotation.JsonDeserialize; 022import com.fasterxml.jackson.databind.node.ObjectNode; 023import io.swagger.v3.oas.annotations.Hidden; 024import java.io.IOException; 025import java.io.Serializable; 026import java.lang.reflect.Field; 027import java.util.ArrayList; 028import java.util.List; 029import java.util.Objects; 030import java.util.Optional; 031import lombok.extern.slf4j.Slf4j; 032import org.gbif.api.annotation.Experimental; 033import org.gbif.api.model.common.search.SearchParameter; 034import org.gbif.api.model.common.search.SearchParameterFormat; 035import org.gbif.api.model.occurrence.search.OccurrenceSearchParameter; 036import org.gbif.api.vocabulary.DurationUnit; 037import org.gbif.api.vocabulary.EventIssue; 038 039import static org.gbif.api.model.common.search.SearchParameterFormat.ALPHABETIC_UNDERSCORE; 040 041/** 042 * Supported query parameters by the occurrence search and download service. For download predicates 043 * only the numerical types support comparisons other than equals. 044 */ 045@Slf4j 046@JsonDeserialize( 047 as = EventSearchParameter.class, 048 using = EventSearchParameter.EventSearchParameterDeserializer.class) 049public class EventSearchParameter implements SearchParameter, Serializable { 050 051 /** See @link {@link OccurrenceSearchParameter#DATASET_KEY} */ 052 public static final EventSearchParameter DATASET_KEY = 053 new EventSearchParameter(OccurrenceSearchParameter.DATASET_KEY); 054 055 /** See @link {@link OccurrenceSearchParameter#CHECKLIST_KEY} */ 056 public static final EventSearchParameter CHECKLIST_KEY = 057 new EventSearchParameter(OccurrenceSearchParameter.CHECKLIST_KEY); 058 059 /** See @link {@link OccurrenceSearchParameter#YEAR} */ 060 public static final EventSearchParameter YEAR = 061 new EventSearchParameter(OccurrenceSearchParameter.YEAR); 062 063 /** See @link {@link OccurrenceSearchParameter#MONTH} */ 064 public static final EventSearchParameter MONTH = 065 new EventSearchParameter(OccurrenceSearchParameter.MONTH); 066 067 /** See @link {@link OccurrenceSearchParameter#DAY} */ 068 public static final EventSearchParameter DAY = 069 new EventSearchParameter(OccurrenceSearchParameter.DAY); 070 071 /** See @link {@link OccurrenceSearchParameter#START_DAY_OF_YEAR} */ 072 public static final EventSearchParameter START_DAY_OF_YEAR = 073 new EventSearchParameter(OccurrenceSearchParameter.START_DAY_OF_YEAR); 074 075 /** See @link {@link OccurrenceSearchParameter#END_DAY_OF_YEAR} */ 076 public static final EventSearchParameter END_DAY_OF_YEAR = 077 new EventSearchParameter(OccurrenceSearchParameter.END_DAY_OF_YEAR); 078 079 /** See @link {@link OccurrenceSearchParameter#EVENT_DATE} */ 080 public static final EventSearchParameter EVENT_DATE = 081 new EventSearchParameter(OccurrenceSearchParameter.EVENT_DATE); 082 083 /** 084 * An identifier for the set of information associated with an Event (something that occurs at a 085 * place and time). Maybe a global unique identifier or an identifier specific to the data set. 086 * 087 * @link {@link OccurrenceSearchParameter#EVENT_ID} 088 */ 089 public static final EventSearchParameter EVENT_ID = 090 new EventSearchParameter(OccurrenceSearchParameter.EVENT_ID); 091 092 /** See @link {@link OccurrenceSearchParameter#PARENT_EVENT_ID} */ 093 public static final EventSearchParameter PARENT_EVENT_ID = 094 new EventSearchParameter(OccurrenceSearchParameter.PARENT_EVENT_ID); 095 096 /** See @link {@link OccurrenceSearchParameter#SAMPLING_PROTOCOL} */ 097 public static final EventSearchParameter SAMPLING_PROTOCOL = 098 new EventSearchParameter(OccurrenceSearchParameter.SAMPLING_PROTOCOL); 099 100 /** See @link {@link OccurrenceSearchParameter#LAST_INTERPRETED} */ 101 public static final EventSearchParameter LAST_INTERPRETED = 102 new EventSearchParameter(OccurrenceSearchParameter.LAST_INTERPRETED); 103 104 /** See @link {@link OccurrenceSearchParameter#MODIFIED} */ 105 public static final EventSearchParameter MODIFIED = 106 new EventSearchParameter(OccurrenceSearchParameter.MODIFIED); 107 108 /** See @link {@link OccurrenceSearchParameter#DECIMAL_LATITUDE} */ 109 public static final EventSearchParameter DECIMAL_LATITUDE = 110 new EventSearchParameter(OccurrenceSearchParameter.DECIMAL_LATITUDE); 111 112 /** See @link {@link OccurrenceSearchParameter#DECIMAL_LONGITUDE} */ 113 public static final EventSearchParameter DECIMAL_LONGITUDE = 114 new EventSearchParameter(OccurrenceSearchParameter.DECIMAL_LONGITUDE); 115 116 /** See @link {@link OccurrenceSearchParameter#COORDINATE_UNCERTAINTY_IN_METERS} */ 117 public static final EventSearchParameter COORDINATE_UNCERTAINTY_IN_METERS = 118 new EventSearchParameter(OccurrenceSearchParameter.COORDINATE_UNCERTAINTY_IN_METERS); 119 120 /** See @link {@link OccurrenceSearchParameter#COUNTRY} */ 121 public static final EventSearchParameter COUNTRY = 122 new EventSearchParameter(OccurrenceSearchParameter.COUNTRY); 123 124 /** See @link {@link OccurrenceSearchParameter#GBIF_REGION} */ 125 public static final EventSearchParameter GBIF_REGION = 126 new EventSearchParameter(OccurrenceSearchParameter.GBIF_REGION); 127 128 /** See @link {@link OccurrenceSearchParameter#CONTINENT} */ 129 public static final EventSearchParameter CONTINENT = 130 new EventSearchParameter(OccurrenceSearchParameter.CONTINENT); 131 132 /** See @link {@link OccurrenceSearchParameter#PUBLISHING_COUNTRY} */ 133 public static final EventSearchParameter PUBLISHING_COUNTRY = 134 new EventSearchParameter(OccurrenceSearchParameter.PUBLISHING_COUNTRY); 135 136 /** See @link {@link OccurrenceSearchParameter#PUBLISHED_BY_GBIF_REGION} */ 137 public static final EventSearchParameter PUBLISHED_BY_GBIF_REGION = 138 new EventSearchParameter(OccurrenceSearchParameter.PUBLISHED_BY_GBIF_REGION); 139 140 /** See @link {@link OccurrenceSearchParameter#ELEVATION} */ 141 public static final EventSearchParameter ELEVATION = 142 new EventSearchParameter(OccurrenceSearchParameter.ELEVATION); 143 144 /** See @link {@link OccurrenceSearchParameter#DEPTH} */ 145 public static final EventSearchParameter DEPTH = 146 new EventSearchParameter(OccurrenceSearchParameter.DEPTH); 147 148 /** See @link {@link OccurrenceSearchParameter#INSTITUTION_CODE} */ 149 public static final EventSearchParameter INSTITUTION_CODE = 150 new EventSearchParameter(OccurrenceSearchParameter.INSTITUTION_CODE); 151 152 /** See @link {@link OccurrenceSearchParameter#COLLECTION_CODE} */ 153 public static final EventSearchParameter COLLECTION_CODE = 154 new EventSearchParameter(OccurrenceSearchParameter.COLLECTION_CODE); 155 156 /** See @link {@link OccurrenceSearchParameter#TAXON_KEY} */ 157 public static final EventSearchParameter TAXON_KEY = 158 new EventSearchParameter(OccurrenceSearchParameter.TAXON_KEY); 159 160 /** See @link {@link OccurrenceSearchParameter#ACCEPTED_TAXON_KEY} */ 161 public static final EventSearchParameter ACCEPTED_TAXON_KEY = 162 new EventSearchParameter(OccurrenceSearchParameter.ACCEPTED_TAXON_KEY); 163 164 /** See @link {@link OccurrenceSearchParameter#SCIENTIFIC_NAME} */ 165 public static final EventSearchParameter SCIENTIFIC_NAME = 166 new EventSearchParameter(OccurrenceSearchParameter.SCIENTIFIC_NAME); 167 168 /** See @link {@link OccurrenceSearchParameter#TAXON_ID} */ 169 public static final EventSearchParameter TAXON_ID = 170 new EventSearchParameter(OccurrenceSearchParameter.TAXON_ID); 171 172 /** See @link {@link OccurrenceSearchParameter#TAXONOMIC_STATUS} */ 173 public static final EventSearchParameter TAXONOMIC_STATUS = 174 new EventSearchParameter(OccurrenceSearchParameter.TAXONOMIC_STATUS); 175 176 /** See @link {@link OccurrenceSearchParameter#TAXONOMIC_ISSUE} */ 177 public static final EventSearchParameter TAXONOMIC_ISSUE = 178 new EventSearchParameter(OccurrenceSearchParameter.TAXONOMIC_ISSUE); 179 180 /** See @link {@link OccurrenceSearchParameter#IUCN_RED_LIST_CATEGORY} */ 181 public static final EventSearchParameter IUCN_RED_LIST_CATEGORY = 182 new EventSearchParameter(OccurrenceSearchParameter.IUCN_RED_LIST_CATEGORY); 183 184 /** See @link {@link OccurrenceSearchParameter#ENVIRONMENTS} */ 185 public static final EventSearchParameter ENVIRONMENTS = 186 new EventSearchParameter(OccurrenceSearchParameter.ENVIRONMENTS); 187 188 /** See @link {@link OccurrenceSearchParameter#HAS_COORDINATE} */ 189 public static final EventSearchParameter HAS_COORDINATE = 190 new EventSearchParameter(OccurrenceSearchParameter.HAS_COORDINATE); 191 192 /** See @link {@link OccurrenceSearchParameter#GEOMETRY} */ 193 public static final EventSearchParameter GEOMETRY = 194 new EventSearchParameter(OccurrenceSearchParameter.GEOMETRY); 195 196 /** See @link {@link OccurrenceSearchParameter#GEO_DISTANCE} */ 197 public static final EventSearchParameter GEO_DISTANCE = 198 new EventSearchParameter(OccurrenceSearchParameter.GEO_DISTANCE); 199 200 /** See @link {@link OccurrenceSearchParameter#HAS_GEOSPATIAL_ISSUE} */ 201 public static final EventSearchParameter HAS_GEOSPATIAL_ISSUE = 202 new EventSearchParameter(OccurrenceSearchParameter.HAS_GEOSPATIAL_ISSUE); 203 204 /** See @link {@link OccurrenceSearchParameter#MEDIA_TYPE} */ 205 public static final EventSearchParameter MEDIA_TYPE = 206 new EventSearchParameter(OccurrenceSearchParameter.MEDIA_TYPE); 207 208 /** See @link {@link OccurrenceSearchParameter#REPATRIATED} */ 209 public static final EventSearchParameter REPATRIATED = 210 new EventSearchParameter(OccurrenceSearchParameter.REPATRIATED); 211 212 /** See @link {@link OccurrenceSearchParameter#STATE_PROVINCE} */ 213 public static final EventSearchParameter STATE_PROVINCE = 214 new EventSearchParameter(OccurrenceSearchParameter.STATE_PROVINCE); 215 216 /** See @link {@link OccurrenceSearchParameter#WATER_BODY} */ 217 public static final EventSearchParameter WATER_BODY = 218 new EventSearchParameter(OccurrenceSearchParameter.WATER_BODY); 219 220 /** See @link {@link OccurrenceSearchParameter#LOCALITY} */ 221 public static final EventSearchParameter LOCALITY = 222 new EventSearchParameter(OccurrenceSearchParameter.LOCALITY); 223 224 /** See @link {@link OccurrenceSearchParameter#PROTOCOL} */ 225 public static final EventSearchParameter PROTOCOL = 226 new EventSearchParameter(OccurrenceSearchParameter.PROTOCOL); 227 228 /** See @link {@link OccurrenceSearchParameter#LICENSE} */ 229 public static final EventSearchParameter LICENSE = 230 new EventSearchParameter(OccurrenceSearchParameter.LICENSE); 231 232 /** See @link {@link OccurrenceSearchParameter#PUBLISHING_ORG} */ 233 public static final EventSearchParameter PUBLISHING_ORG = 234 new EventSearchParameter(OccurrenceSearchParameter.PUBLISHING_ORG); 235 236 /** See @link {@link OccurrenceSearchParameter#NETWORK_KEY} */ 237 public static final EventSearchParameter NETWORK_KEY = 238 new EventSearchParameter(OccurrenceSearchParameter.NETWORK_KEY); 239 240 /** See @link {@link OccurrenceSearchParameter#DATASET_CATEGORY} */ 241 public static final EventSearchParameter DATASET_CATEGORY = 242 new EventSearchParameter(OccurrenceSearchParameter.DATASET_CATEGORY); 243 244 /** See @link {@link OccurrenceSearchParameter#INSTALLATION_KEY} */ 245 public static final EventSearchParameter INSTALLATION_KEY = 246 new EventSearchParameter(OccurrenceSearchParameter.INSTALLATION_KEY); 247 248 /** See @link {@link OccurrenceSearchParameter#HOSTING_ORGANIZATION_KEY} */ 249 public static final EventSearchParameter HOSTING_ORGANIZATION_KEY = 250 new EventSearchParameter(OccurrenceSearchParameter.HOSTING_ORGANIZATION_KEY); 251 252 /** See @link {@link OccurrenceSearchParameter#CRAWL_ID} */ 253 public static final EventSearchParameter CRAWL_ID = 254 new EventSearchParameter(OccurrenceSearchParameter.CRAWL_ID); 255 256 /** See @link {@link OccurrenceSearchParameter#PROGRAMME} */ 257 public static final EventSearchParameter PROGRAMME = 258 new EventSearchParameter(OccurrenceSearchParameter.PROGRAMME); 259 260 /** See @link {@link OccurrenceSearchParameter#SAMPLE_SIZE_UNIT} */ 261 public static final EventSearchParameter SAMPLE_SIZE_UNIT = 262 new EventSearchParameter(OccurrenceSearchParameter.SAMPLE_SIZE_UNIT); 263 264 /** See @link {@link OccurrenceSearchParameter#SAMPLE_SIZE_VALUE} */ 265 public static final EventSearchParameter SAMPLE_SIZE_VALUE = 266 new EventSearchParameter(OccurrenceSearchParameter.SAMPLE_SIZE_VALUE); 267 268 /** See @link {@link OccurrenceSearchParameter#GADM_GID} */ 269 public static final EventSearchParameter GADM_GID = 270 new EventSearchParameter(OccurrenceSearchParameter.GADM_GID); 271 272 /** See @link {@link OccurrenceSearchParameter#GADM_LEVEL_0_GID} */ 273 public static final EventSearchParameter GADM_LEVEL_0_GID = 274 new EventSearchParameter(OccurrenceSearchParameter.GADM_LEVEL_0_GID); 275 276 /** See @link {@link OccurrenceSearchParameter#GADM_LEVEL_1_GID} */ 277 public static final EventSearchParameter GADM_LEVEL_1_GID = 278 new EventSearchParameter(OccurrenceSearchParameter.GADM_LEVEL_1_GID); 279 280 /** See @link {@link OccurrenceSearchParameter#GADM_LEVEL_2_GID} */ 281 public static final EventSearchParameter GADM_LEVEL_2_GID = 282 new EventSearchParameter(OccurrenceSearchParameter.GADM_LEVEL_2_GID); 283 284 /** See @link {@link OccurrenceSearchParameter#GADM_LEVEL_3_GID} */ 285 public static final EventSearchParameter GADM_LEVEL_3_GID = 286 new EventSearchParameter(OccurrenceSearchParameter.GADM_LEVEL_3_GID); 287 288 /** See @link {@link OccurrenceSearchParameter#DWCA_EXTENSION} */ 289 public static final EventSearchParameter DWCA_EXTENSION = 290 new EventSearchParameter(OccurrenceSearchParameter.DWCA_EXTENSION); 291 292 /** See @link {@link OccurrenceSearchParameter#DATASET_ID} */ 293 public static final EventSearchParameter DATASET_ID = 294 new EventSearchParameter(OccurrenceSearchParameter.DATASET_ID); 295 296 /** See @link {@link OccurrenceSearchParameter#DATASET_NAME} */ 297 public static final EventSearchParameter DATASET_NAME = 298 new EventSearchParameter(OccurrenceSearchParameter.DATASET_NAME); 299 300 /** See @link {@link OccurrenceSearchParameter#ISLAND} */ 301 public static final EventSearchParameter ISLAND = 302 new EventSearchParameter(OccurrenceSearchParameter.ISLAND); 303 304 /** See @link {@link OccurrenceSearchParameter#ISLAND_GROUP} */ 305 public static final EventSearchParameter ISLAND_GROUP = 306 new EventSearchParameter(OccurrenceSearchParameter.ISLAND_GROUP); 307 308 /** See @link {@link OccurrenceSearchParameter#GEOREFERENCED_BY} */ 309 public static final EventSearchParameter GEOREFERENCED_BY = 310 new EventSearchParameter(OccurrenceSearchParameter.GEOREFERENCED_BY); 311 312 /** See @link {@link OccurrenceSearchParameter#HIGHER_GEOGRAPHY} */ 313 public static final EventSearchParameter HIGHER_GEOGRAPHY = 314 new EventSearchParameter(OccurrenceSearchParameter.HIGHER_GEOGRAPHY); 315 316 /** See @link {@link OccurrenceSearchParameter#FIELD_NUMBER} */ 317 public static final EventSearchParameter FIELD_NUMBER = 318 new EventSearchParameter(OccurrenceSearchParameter.FIELD_NUMBER); 319 320 /** See @link {@link OccurrenceSearchParameter#GBIF_ID} */ 321 public static final EventSearchParameter GBIF_ID = 322 new EventSearchParameter(OccurrenceSearchParameter.GBIF_ID); 323 324 /** An identifier for an Event and its children events. */ 325 public static final EventSearchParameter EVENT_ID_HIERARCHY = 326 new EventSearchParameter("EVENT_ID_HIERARCHY", String.class); 327 328 /** An identifier for the vocabulary-backed Event Type. */ 329 public static final EventSearchParameter EVENT_TYPE = 330 new EventSearchParameter("EVENT_TYPE", String.class); 331 332 /** An identifier for the verbatim Event Type. */ 333 @Experimental 334 public static final EventSearchParameter VERBATIM_EVENT_TYPE = 335 new EventSearchParameter("VERBATIM_EVENT_TYPE", String.class); 336 337 /** Searches events for those that have a specific issue. */ 338 public static final EventSearchParameter ISSUE = 339 new EventSearchParameter("ISSUE", EventIssue.class); 340 341 /** The event project ID. */ 342 public static final EventSearchParameter PROJECT_ID = 343 new EventSearchParameter("PROJECT_ID", String.class); 344 345 /** The event project title. */ 346 public static final EventSearchParameter PROJECT_TITLE = 347 new EventSearchParameter("PROJECT_TITLE", String.class); 348 349 /** The event funding attribution. */ 350 public static final EventSearchParameter FUNDING_ATTRIBUTION = 351 new EventSearchParameter("FUNDING_ATTRIBUTION", String.class); 352 353 /** The event funding attribution ID. */ 354 public static final EventSearchParameter FUNDING_ATTRIBUTION_ID = 355 new EventSearchParameter("FUNDING_ATTRIBUTION_ID", String.class); 356 357 /** The event location ID. */ 358 public static final EventSearchParameter LOCATION_ID = 359 new EventSearchParameter("LOCATION_ID", String.class); 360 361 /** See @link {@link OccurrenceSearchParameter#MEASUREMENT_TYPE} */ 362 public static final EventSearchParameter MEASUREMENT_TYPE = 363 new EventSearchParameter(OccurrenceSearchParameter.MEASUREMENT_TYPE); 364 365 /** See @link {@link OccurrenceSearchParameter#MEASUREMENT_TYPE_ID} */ 366 public static final EventSearchParameter MEASUREMENT_TYPE_ID = 367 new EventSearchParameter(OccurrenceSearchParameter.MEASUREMENT_TYPE_ID); 368 369 /** Humboldt fields * */ 370 public static final EventSearchParameter HUMBOLDT_SITE_COUNT = 371 new EventSearchParameter("HUMBOLDT_SITE_COUNT", Integer.class); 372 373 public static final EventSearchParameter HUMBOLDT_VERBATIM_SITE_NAMES = 374 new EventSearchParameter("HUMBOLDT_VERBATIM_SITE_NAMES", String.class); 375 public static final EventSearchParameter HUMBOLDT_GEOSPATIAL_SCOPE_AREA_VALUE = 376 new EventSearchParameter("HUMBOLDT_GEOSPATIAL_SCOPE_AREA_VALUE", Double.class); 377 public static final EventSearchParameter HUMBOLDT_GEOSPATIAL_SCOPE_AREA_UNIT = 378 new EventSearchParameter("HUMBOLDT_GEOSPATIAL_SCOPE_AREA_UNIT", String.class); 379 public static final EventSearchParameter HUMBOLDT_TOTAL_AREA_SAMPLED_VALUE = 380 new EventSearchParameter("HUMBOLDT_TOTAL_AREA_SAMPLED_VALUE", Double.class); 381 public static final EventSearchParameter HUMBOLDT_TOTAL_AREA_SAMPLED_UNIT = 382 new EventSearchParameter("HUMBOLDT_TOTAL_AREA_SAMPLED_UNIT", String.class); 383 public static final EventSearchParameter HUMBOLDT_TARGET_HABITAT_SCOPE = 384 new EventSearchParameter("HUMBOLDT_TARGET_HABITAT_SCOPE", String.class); 385 public static final EventSearchParameter HUMBOLDT_EVENT_DURATION = 386 new EventSearchParameter("HUMBOLDT_EVENT_DURATION", String.class); 387 388 @Hidden 389 public static final EventSearchParameter HUMBOLDT_EVENT_DURATION_VALUE_IN_MINUTES = 390 new EventSearchParameter("HUMBOLDT_EVENT_DURATION_VALUE_IN_MINUTES", Double.class); 391 392 public static final EventSearchParameter HUMBOLDT_EVENT_DURATION_VALUE = 393 new EventSearchParameter("HUMBOLDT_EVENT_DURATION_VALUE", Double.class); 394 public static final EventSearchParameter HUMBOLDT_EVENT_DURATION_UNIT = 395 new EventSearchParameter("HUMBOLDT_EVENT_DURATION_UNIT", DurationUnit.class); 396 397 public static final EventSearchParameter HUMBOLDT_TARGET_TAXONOMIC_SCOPE_ISSUE = 398 new EventSearchParameter("HUMBOLDT_TARGET_TAXONOMIC_SCOPE_ISSUE", EventIssue.class); 399 public static final EventSearchParameter HUMBOLDT_TARGET_TAXONOMIC_SCOPE_USAGE_NAME = 400 new EventSearchParameter("HUMBOLDT_TARGET_TAXONOMIC_SCOPE_USAGE_NAME", String.class); 401 public static final EventSearchParameter HUMBOLDT_TARGET_TAXONOMIC_SCOPE_USAGE_KEY = 402 new EventSearchParameter("HUMBOLDT_TARGET_TAXONOMIC_SCOPE_USAGE_KEY", String.class, SearchParameterFormat.TAXON_KEY); 403 public static final EventSearchParameter HUMBOLDT_TARGET_TAXONOMIC_SCOPE_ACCEPTED_USAGE_NAME = 404 new EventSearchParameter("HUMBOLDT_TARGET_TAXONOMIC_SCOPE_ACCEPTED_USAGE_NAME", String.class); 405 public static final EventSearchParameter HUMBOLDT_TARGET_TAXONOMIC_SCOPE_ACCEPTED_USAGE_KEY = 406 new EventSearchParameter("HUMBOLDT_TARGET_TAXONOMIC_SCOPE_ACCEPTED_USAGE_KEY", String.class, SearchParameterFormat.TAXON_KEY); 407 public static final EventSearchParameter HUMBOLDT_TARGET_TAXONOMIC_SCOPE_TAXON_KEY = 408 new EventSearchParameter("HUMBOLDT_TARGET_TAXONOMIC_SCOPE_TAXON_KEY", String.class, SearchParameterFormat.TAXON_KEY); 409 public static final EventSearchParameter HUMBOLDT_TARGET_TAXONOMIC_SCOPE_IUCN_RED_LIST_CATEGORY = 410 new EventSearchParameter( 411 "HUMBOLDT_TARGET_TAXONOMIC_SCOPE_IUCN_RED_LIST_CATEGORY", String.class, ALPHABETIC_UNDERSCORE); 412 public static final EventSearchParameter HUMBOLDT_TARGET_TAXONOMIC_SCOPE_ENVIRONMENTS = 413 new EventSearchParameter("HUMBOLDT_TARGET_TAXONOMIC_SCOPE_ENVIRONMENTS", String.class, ALPHABETIC_UNDERSCORE); 414 public static final EventSearchParameter HUMBOLDT_TAXON_COMPLETENESS_PROTOCOLS = 415 new EventSearchParameter("HUMBOLDT_TAXON_COMPLETENESS_PROTOCOLS", String.class); 416 public static final EventSearchParameter HUMBOLDT_IS_TAXONOMIC_SCOPE_FULLY_REPORTED = 417 new EventSearchParameter("HUMBOLDT_IS_TAXONOMIC_SCOPE_FULLY_REPORTED", Boolean.class); 418 public static final EventSearchParameter HUMBOLDT_IS_ABSENCE_REPORTED = 419 new EventSearchParameter("HUMBOLDT_IS_ABSENCE_REPORTED", Boolean.class); 420 public static final EventSearchParameter HUMBOLDT_HAS_NON_TARGET_TAXA = 421 new EventSearchParameter("HUMBOLDT_HAS_NON_TARGET_TAXA", Boolean.class); 422 public static final EventSearchParameter HUMBOLDT_ARE_NON_TARGET_TAXA_FULLY_REPORTED = 423 new EventSearchParameter("HUMBOLDT_ARE_NON_TARGET_TAXA_FULLY_REPORTED", Boolean.class); 424 public static final EventSearchParameter HUMBOLDT_TARGET_LIFE_STAGE_SCOPE = 425 new EventSearchParameter("HUMBOLDT_TARGET_LIFE_STAGE_SCOPE", String.class); 426 public static final EventSearchParameter HUMBOLDT_IS_LIFE_STAGE_SCOPE_FULLY_REPORTED = 427 new EventSearchParameter("HUMBOLDT_IS_LIFE_STAGE_SCOPE_FULLY_REPORTED", Boolean.class); 428 public static final EventSearchParameter HUMBOLDT_TARGET_DEGREE_OF_ESTABLISHMENT_SCOPE = 429 new EventSearchParameter("HUMBOLDT_TARGET_DEGREE_OF_ESTABLISHMENT_SCOPE", String.class); 430 public static final EventSearchParameter 431 HUMBOLDT_IS_DEGREE_OF_ESTABLISHMENT_SCOPE_FULLY_REPORTED = 432 new EventSearchParameter( 433 "HUMBOLDT_IS_DEGREE_OF_ESTABLISHMENT_SCOPE_FULLY_REPORTED", Boolean.class); 434 public static final EventSearchParameter HUMBOLDT_TARGET_GROWTH_FORM_SCOPE = 435 new EventSearchParameter("HUMBOLDT_TARGET_GROWTH_FORM_SCOPE", String.class); 436 public static final EventSearchParameter HUMBOLDT_IS_GROWTH_FORM_SCOPE_FULLY_REPORTED = 437 new EventSearchParameter("HUMBOLDT_IS_GROWTH_FORM_SCOPE_FULLY_REPORTED", Boolean.class); 438 public static final EventSearchParameter HUMBOLDT_HAS_NON_TARGET_ORGANISMS = 439 new EventSearchParameter("HUMBOLDT_HAS_NON_TARGET_ORGANISMS", Boolean.class); 440 public static final EventSearchParameter HUMBOLDT_COMPILATION_TYPES = 441 new EventSearchParameter("HUMBOLDT_COMPILATION_TYPES", String.class); 442 public static final EventSearchParameter HUMBOLDT_COMPILATION_SOURCE_TYPES = 443 new EventSearchParameter("HUMBOLDT_COMPILATION_SOURCE_TYPES", String.class); 444 public static final EventSearchParameter HUMBOLDT_INVENTORY_TYPES = 445 new EventSearchParameter("HUMBOLDT_INVENTORY_TYPES", String.class); 446 public static final EventSearchParameter HUMBOLDT_PROTOCOL_NAMES = 447 new EventSearchParameter("HUMBOLDT_PROTOCOL_NAMES", String.class); 448 public static final EventSearchParameter HUMBOLDT_IS_ABUNDANCE_REPORTED = 449 new EventSearchParameter("HUMBOLDT_IS_ABUNDANCE_REPORTED", Boolean.class); 450 public static final EventSearchParameter HUMBOLDT_IS_ABUNDANCE_CAP_REPORTED = 451 new EventSearchParameter("HUMBOLDT_IS_ABUNDANCE_CAP_REPORTED", Boolean.class); 452 public static final EventSearchParameter HUMBOLDT_ABUNDANCE_CAP = 453 new EventSearchParameter("HUMBOLDT_ABUNDANCE_CAP", Integer.class); 454 public static final EventSearchParameter HUMBOLDT_IS_VEGETATION_COVER_REPORTED = 455 new EventSearchParameter("HUMBOLDT_IS_VEGETATION_COVER_REPORTED", Boolean.class); 456 public static final EventSearchParameter 457 HUMBOLDT_IS_LEAST_SPECIFIC_TARGET_CATEGORY_QUANTITY_INCLUSIVE = 458 new EventSearchParameter( 459 "HUMBOLDT_IS_LEAST_SPECIFIC_TARGET_CATEGORY_QUANTITY_INCLUSIVE", Boolean.class); 460 public static final EventSearchParameter HUMBOLDT_HAS_VOUCHERS = 461 new EventSearchParameter("HUMBOLDT_HAS_VOUCHERS", Boolean.class); 462 public static final EventSearchParameter HUMBOLDT_VOUCHER_INSTITUTIONS = 463 new EventSearchParameter("HUMBOLDT_VOUCHER_INSTITUTIONS", String.class); 464 public static final EventSearchParameter HUMBOLDT_HAS_MATERIAL_SAMPLES = 465 new EventSearchParameter("HUMBOLDT_HAS_MATERIAL_SAMPLES", Boolean.class); 466 public static final EventSearchParameter HUMBOLDT_MATERIAL_SAMPLE_TYPES = 467 new EventSearchParameter("HUMBOLDT_MATERIAL_SAMPLE_TYPES", String.class); 468 public static final EventSearchParameter HUMBOLDT_SAMPLING_PERFORMED_BY = 469 new EventSearchParameter("HUMBOLDT_SAMPLING_PERFORMED_BY", String.class); 470 public static final EventSearchParameter HUMBOLDT_IS_SAMPLING_EFFORT_REPORTED = 471 new EventSearchParameter("HUMBOLDT_IS_SAMPLING_EFFORT_REPORTED", Boolean.class); 472 public static final EventSearchParameter HUMBOLDT_SAMPLING_EFFORT_VALUE = 473 new EventSearchParameter("HUMBOLDT_SAMPLING_EFFORT_VALUE", Double.class); 474 public static final EventSearchParameter HUMBOLDT_SAMPLING_EFFORT_UNIT = 475 new EventSearchParameter("HUMBOLDT_SAMPLING_EFFORT_UNIT", String.class); 476 477 public static EventSearchParameter[] values() { 478 479 Field[] values = EventSearchParameter.class.getFields(); 480 List<EventSearchParameter> c = new ArrayList<>(); 481 for (Field field : values) { 482 try { 483 c.add((EventSearchParameter) field.get(EventSearchParameter.class)); 484 } catch (IllegalAccessException e) { 485 throw new RuntimeException(e); 486 } 487 } 488 return c.toArray(new EventSearchParameter[0]); 489 } 490 491 private Class<?> type; 492 private String name; 493 private SearchParameterFormat format; 494 495 public EventSearchParameter() {} 496 497 public EventSearchParameter(OccurrenceSearchParameter occurrenceSearchParameter) { 498 this.name = occurrenceSearchParameter.getName(); 499 this.type = occurrenceSearchParameter.getType(); 500 this.format = occurrenceSearchParameter.getFormat(); 501 } 502 503 public EventSearchParameter(String name, Class<?> type, SearchParameterFormat format) { 504 this.name = name; 505 this.type = type; 506 this.format = format; 507 } 508 509 public EventSearchParameter(String name, Class<?> type) { 510 this.name = name; 511 this.type = type; 512 } 513 514 @Override 515 public String name() { 516 return this.name; 517 } 518 519 public String getName() { 520 return name; 521 } 522 523 @Override 524 public Class<?> type() { 525 return this.type; 526 } 527 528 public Class<?> getType() { 529 return type; 530 } 531 532 public SearchParameterFormat format() { 533 return this.format; 534 } 535 536 public SearchParameterFormat getFormat() { 537 return format; 538 } 539 540 @Override 541 public String toString() { 542 return name; 543 } 544 545 @Override 546 public boolean equals(Object o) { 547 if (this == o) return true; 548 if (o == null || getClass() != o.getClass()) return false; 549 EventSearchParameter that = (EventSearchParameter) o; 550 return Objects.equals(type, that.type) && Objects.equals(name, that.name) && Objects.equals(format, that.format); 551 } 552 553 @JsonValue 554 public String getSerializedValue() { 555 return name; 556 } 557 558 @Override 559 public int hashCode() { 560 return Objects.hash(name, type, format); 561 } 562 563 /** 564 * Lookup a parameter by its name. 565 * 566 * @param name the name of the parameter 567 * @return the parameter if found, otherwise empty 568 */ 569 public static Optional<EventSearchParameter> lookupEventParam(String name) { 570 String normedType = name.toUpperCase().replaceAll("[. _-]", ""); 571 Field[] values = EventSearchParameter.class.getFields(); 572 for (Field field : values) { 573 574 String fieldName = field.getName(); 575 String normedVal = fieldName.replaceAll("[. _-]", ""); 576 if (normedType.equals(normedVal)) { 577 try { 578 return Optional.of((EventSearchParameter) field.get(EventSearchParameter.class)); 579 } catch (IllegalAccessException e) { 580 throw new RuntimeException(e); 581 } 582 } 583 } 584 return Optional.empty(); 585 } 586 587 public static class EventSearchParameterKeyDeserializer extends KeyDeserializer { 588 589 @Override 590 public Object deserializeKey(String value, DeserializationContext deserializationContext) 591 throws IOException { 592 Field[] values = EventSearchParameter.class.getFields(); 593 try { 594 for (Field field : values) { 595 if (field.getName().equalsIgnoreCase(value)) { 596 return (EventSearchParameter) field.get(EventSearchParameter.class); 597 } 598 } 599 } catch (IllegalAccessException e) { 600 log.warn("Error deserializing event search parameter key", e); 601 // DO NOTHING 602 } 603 return null; 604 } 605 } 606 607 public static class EventSearchParameterDeserializer 608 extends JsonDeserializer<EventSearchParameter> { 609 610 @Override 611 public EventSearchParameter deserialize( 612 com.fasterxml.jackson.core.JsonParser jsonParser, 613 DeserializationContext deserializationContext) 614 throws IOException, JacksonException { 615 616 Field[] values = EventSearchParameter.class.getFields(); 617 try { 618 String value = jsonParser.getText(); 619 for (Field field : values) { 620 if (field.getName().equalsIgnoreCase(value)) { 621 return (EventSearchParameter) field.get(EventSearchParameter.class); 622 } 623 } 624 625 } catch (IllegalAccessException e) { 626 log.warn("Error deserializing event search parameter", e); 627 } 628 629 try { 630 ObjectNode node = jsonParser.getCodec().readTree(jsonParser); 631 String value = node.get("name").asText(); 632 for (Field field : values) { 633 if (field.getName().equalsIgnoreCase(value)) { 634 return (EventSearchParameter) field.get(EventSearchParameter.class); 635 } 636 } 637 } catch (Exception e) { 638 log.warn("Error deserializing event search parameter from name", e); 639 } 640 641 return null; 642 } 643 } 644}