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; 015 016import java.util.Date; 017import java.util.Optional; 018import java.util.UUID; 019import org.gbif.api.annotation.Experimental; 020import org.gbif.api.model.common.paging.Pageable; 021import org.gbif.api.model.common.search.FacetedSearchRequest; 022import org.gbif.api.util.IsoDateInterval; 023import org.gbif.api.vocabulary.BasisOfRecord; 024import org.gbif.api.vocabulary.Continent; 025import org.gbif.api.vocabulary.Country; 026import org.gbif.api.vocabulary.EstablishmentMeans; 027import org.gbif.api.vocabulary.MediaType; 028import org.gbif.api.vocabulary.OccurrenceIssue; 029import org.gbif.api.vocabulary.OccurrenceStatus; 030import org.gbif.api.vocabulary.TypeStatus; 031 032/** Request class for issuing search request to the occurrence search service. */ 033public class OccurrenceSearchRequest extends FacetedSearchRequest<OccurrenceSearchParameter> { 034 035 private Boolean matchCase; 036 private String shuffle; 037 038 public OccurrenceSearchRequest() { 039 // empty block 040 super(); 041 } 042 043 /** 044 * This flag enables the use of case-sensitive matches and aggregations on certain search 045 * parameters. 046 * 047 * <p>Fields that support this feature are: occurrenceId, recordedBy, samplingProtocol, 048 * catalogNumber, collectionCode, institutionCode, eventId, parentEventId, waterBody, 049 * stateProvince, recordNumber, identifiedBy, organismId and locality. 050 * 051 * <p>This is an experimental feature and its implementation map change or be removed at any time. 052 * 053 * <p>Be aware that this is not a per-field flag, all possible fields will match case sensitively. 054 */ 055 @Experimental 056 public Boolean isMatchCase() { 057 return Optional.ofNullable(matchCase).orElse(Boolean.FALSE); 058 } 059 060 @Experimental 061 public void setMatchCase(Boolean matchCase) { 062 this.matchCase = matchCase; 063 } 064 065 /** 066 * This flag allows to sort the results in a random order by specifying a seed. The seed makes the 067 * random results reproducible so we can use paging. The same seed has to be sent for each page. 068 */ 069 @Experimental 070 public String getShuffle() { 071 return shuffle; 072 } 073 074 @Experimental 075 public void setShuffle(String shuffle) { 076 this.shuffle = shuffle; 077 } 078 079 080 public OccurrenceSearchRequest(long offset, int limit) { 081 super(offset, limit); 082 } 083 084 public OccurrenceSearchRequest(Pageable page) { 085 super(page); 086 } 087 088 public void addOccurrenceIDFilter(String occurrenceID) { 089 addParameter(OccurrenceSearchParameter.OCCURRENCE_ID, occurrenceID); 090 } 091 092 public void addEstablishmentMeansFilter(EstablishmentMeans establishmentMeans) { 093 addParameter(OccurrenceSearchParameter.ESTABLISHMENT_MEANS, establishmentMeans); 094 } 095 096 public void addBasisOfRecordFilter(BasisOfRecord basisOfRecord) { 097 addParameter(OccurrenceSearchParameter.BASIS_OF_RECORD, basisOfRecord); 098 } 099 100 public void addTypeStatusFilter(TypeStatus typeStatus) { 101 addParameter(OccurrenceSearchParameter.TYPE_STATUS, typeStatus); 102 } 103 104 public void addCatalogNumberFilter(String catalogNumber) { 105 addParameter(OccurrenceSearchParameter.CATALOG_NUMBER, catalogNumber); 106 } 107 108 public void addRecordedByFilter(String collectorName) { 109 addParameter(OccurrenceSearchParameter.RECORDED_BY, collectorName); 110 } 111 112 public void addIdentifiedByFilter(String collectorName) { 113 addParameter(OccurrenceSearchParameter.IDENTIFIED_BY, collectorName); 114 } 115 116 public void addRecordNumberFilter(String recordNumber) { 117 addParameter(OccurrenceSearchParameter.RECORD_NUMBER, recordNumber); 118 } 119 120 public void addCountryFilter(Country country) { 121 addParameter(OccurrenceSearchParameter.COUNTRY, country.getIso2LetterCode()); 122 } 123 124 public void addContinentFilter(Continent continent) { 125 addParameter(OccurrenceSearchParameter.CONTINENT, continent); 126 } 127 128 public void addDatasetKeyFilter(UUID datasetKey) { 129 addParameter(OccurrenceSearchParameter.DATASET_KEY, datasetKey.toString()); 130 } 131 132 public void addGeometryFilter(String geometryAsWkt) { 133 addParameter(OccurrenceSearchParameter.GEOMETRY, geometryAsWkt); 134 } 135 136 public void addDecimalLatitudeFilter(double latitude) { 137 addParameter(OccurrenceSearchParameter.DECIMAL_LATITUDE, latitude); 138 } 139 140 public void addDecimalLongitudeFilter(double longitude) { 141 addParameter(OccurrenceSearchParameter.DECIMAL_LONGITUDE, longitude); 142 } 143 144 public void addCoordinateUncertaintyInMetersFilter(double uncertainty) { 145 addParameter(OccurrenceSearchParameter.COORDINATE_UNCERTAINTY_IN_METERS, uncertainty); 146 } 147 148 public void addMonthFilter(int month) { 149 addParameter(OccurrenceSearchParameter.MONTH, month); 150 } 151 152 public void addTaxonKeyFilter(int taxonKey) { 153 addParameter(OccurrenceSearchParameter.TAXON_KEY, taxonKey); 154 } 155 156 public void addKingdomKeyFilter(int kingdomKey) { 157 addParameter(OccurrenceSearchParameter.KINGDOM_KEY, kingdomKey); 158 } 159 160 public void addPhylumKeyFilter(int phylumKey) { 161 addParameter(OccurrenceSearchParameter.PHYLUM_KEY, phylumKey); 162 } 163 164 public void addClassKeyFilter(int classKey) { 165 addParameter(OccurrenceSearchParameter.CLASS_KEY, classKey); 166 } 167 168 public void addOrderKeyFilter(int orderKey) { 169 addParameter(OccurrenceSearchParameter.ORDER_KEY, orderKey); 170 } 171 172 public void addFamilyKeyFilter(int familyKey) { 173 addParameter(OccurrenceSearchParameter.FAMILY_KEY, familyKey); 174 } 175 176 public void addGenusKeyFilter(int genusKey) { 177 addParameter(OccurrenceSearchParameter.GENUS_KEY, genusKey); 178 } 179 180 public void addSubGenusKeyFilter(int subGenusKey) { 181 addParameter(OccurrenceSearchParameter.SUBGENUS_KEY, subGenusKey); 182 } 183 184 public void addSpeciesKeyFilter(int speciesKey) { 185 addParameter(OccurrenceSearchParameter.SPECIES_KEY, speciesKey); 186 } 187 188 public void addYearFilter(int year) { 189 addParameter(OccurrenceSearchParameter.YEAR, year); 190 } 191 192 public void addEventDateFilter(IsoDateInterval date) { 193 addParameter(OccurrenceSearchParameter.EVENT_DATE, date); 194 } 195 196 public void addLastInterpretedFilter(Date modified) { 197 addParameter(OccurrenceSearchParameter.LAST_INTERPRETED, modified); 198 } 199 200 public void addPublishingCountryFilter(Country country) { 201 addParameter(OccurrenceSearchParameter.PUBLISHING_COUNTRY, country.getIso2LetterCode()); 202 } 203 204 public void addInstitutionCodeFilter(String code) { 205 addParameter(OccurrenceSearchParameter.INSTITUTION_CODE, code); 206 } 207 208 public void addHasCoordinateFilter(boolean hasCoordinate) { 209 addParameter(OccurrenceSearchParameter.HAS_COORDINATE, hasCoordinate); 210 } 211 212 public void addSpatialIssueFilter(boolean hasSpatialIssue) { 213 addParameter(OccurrenceSearchParameter.HAS_GEOSPATIAL_ISSUE, hasSpatialIssue); 214 } 215 216 public void addIssueFilter(OccurrenceIssue issue) { 217 addParameter(OccurrenceSearchParameter.ISSUE, issue); 218 } 219 220 public void addElevationFilter(double elevation) { 221 addParameter(OccurrenceSearchParameter.ELEVATION, elevation); 222 } 223 224 public void addMediaTypeFilter(MediaType mediaType) { 225 addParameter(OccurrenceSearchParameter.MEDIA_TYPE, mediaType); 226 } 227 228 public void addRecordedByIdsFilter(String recordedByIds) { 229 addParameter(OccurrenceSearchParameter.RECORDED_BY_ID, recordedByIds); 230 } 231 232 public void addIdentifiedByIdsFilter(String identifiedByIds) { 233 addParameter(OccurrenceSearchParameter.IDENTIFIED_BY_ID, identifiedByIds); 234 } 235 236 public void addOccurrenceStatusFilter(OccurrenceStatus occurrenceStatus) { 237 addParameter(OccurrenceSearchParameter.OCCURRENCE_STATUS, occurrenceStatus); 238 } 239 240 public void addGadmGidFilter(String gadmGid) { 241 addParameter(OccurrenceSearchParameter.GADM_GID, gadmGid); 242 } 243 244 public void addGadmLevel0GidFilter(String gadm0) { 245 addParameter(OccurrenceSearchParameter.GADM_LEVEL_0_GID, gadm0); 246 } 247 248 public void addGadmLevel1GidFilter(String gadm1) { 249 addParameter(OccurrenceSearchParameter.GADM_LEVEL_1_GID, gadm1); 250 } 251 252 public void addGadmLevel2GidFilter(String gadm2) { 253 addParameter(OccurrenceSearchParameter.GADM_LEVEL_2_GID, gadm2); 254 } 255 256 public void addGadmLevel3GidFilter(String gadm3) { 257 addParameter(OccurrenceSearchParameter.GADM_LEVEL_3_GID, gadm3); 258 } 259 260 @Experimental 261 public void addInstitutionKeyFilter(String institutionKey) { 262 addParameter(OccurrenceSearchParameter.INSTITUTION_KEY, institutionKey); 263 } 264 265 @Experimental 266 public void addCollectionKeyFilter(String collectionKey) { 267 addParameter(OccurrenceSearchParameter.COLLECTION_KEY, collectionKey); 268 } 269}