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