001/*
002 * Copyright 2020 Global Biodiversity Information Facility (GBIF)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.gbif.api.model.registry.search;
017
018import org.gbif.api.model.common.paging.Pageable;
019import org.gbif.api.model.common.search.FacetedSearchRequest;
020import org.gbif.api.model.registry.Tag;
021import org.gbif.api.vocabulary.Continent;
022import org.gbif.api.vocabulary.Country;
023import org.gbif.api.vocabulary.DatasetSubtype;
024import org.gbif.api.vocabulary.DatasetType;
025
026import java.util.UUID;
027
028/**
029 * A dataset specific search request with convenience methods to add facet filters.
030 */
031public class DatasetSearchRequest extends FacetedSearchRequest<DatasetSearchParameter> {
032  private Integer highlightContext = -1;
033
034  public DatasetSearchRequest() {
035  }
036
037  public DatasetSearchRequest(Pageable page) {
038    super(page);
039  }
040
041  public DatasetSearchRequest(long offset, int limit) {
042    super(offset, limit);
043  }
044
045  /**
046   * @return the number of characters of the context to show for the highlighted match, including the match itself.
047   */
048  public Integer getHighlightContext() {
049    return highlightContext;
050  }
051
052  public void setHighlightContext(Integer highlightContext) {
053    this.highlightContext = highlightContext;
054  }
055
056  /**
057   * Filters dataset by the owning organizations country.
058   */
059  public void addPublishingCountryFilter(Country country) {
060    addParameter(DatasetSearchParameter.PUBLISHING_COUNTRY, country.getIso2LetterCode());
061  }
062
063  /**
064   * Filters dataset by a country of the geospatial coverage.
065   *
066   * @param country appearing in geospatial coverage
067   */
068  public void addCountryFilter(Country country) {
069    addParameter(DatasetSearchParameter.COUNTRY, country.getIso2LetterCode());
070  }
071
072  /**
073   * Filters dataset by a continent of the geospatial coverage.
074   *
075   * @param continent appearing in geospatial coverage
076   */
077  public void addContinentFilter(Continent continent) {
078    addParameter(DatasetSearchParameter.CONTINENT, continent);
079  }
080
081  /**
082   * Filters datasets by their temporal coverage broken down to decades.
083   *
084   * @param decade the decade given as a 4 digit integer
085   */
086  public void addDecadeFilter(int decade) {
087    addParameter(DatasetSearchParameter.DECADE, decade);
088  }
089
090  public void addHostingOrgFilter(UUID orgKey) {
091    addParameter(DatasetSearchParameter.HOSTING_ORG, orgKey.toString());
092  }
093
094  /**
095   * Filters datasets by a keyword given in EML or as simple, public tags.
096   *
097   * @param keyword a plain keyword e.g. created by Tag.toString()
098   */
099  public void addKeywordFilter(String keyword) {
100    addParameter(DatasetSearchParameter.KEYWORD, keyword);
101  }
102
103  /**
104   * Filters dataset by a tag.
105   *
106   * @param keyword given as a tag
107   */
108  public void addKeywordFilter(Tag keyword) {
109    addParameter(DatasetSearchParameter.KEYWORD, keyword.toString());
110  }
111
112  public void addPublishingOrgFilter(UUID orgKey) {
113    addParameter(DatasetSearchParameter.PUBLISHING_ORG, orgKey.toString());
114  }
115
116  public void addSubTypeFilter(DatasetSubtype subtype) {
117    addParameter(DatasetSearchParameter.SUBTYPE, subtype);
118  }
119
120  public void addTypeFilter(DatasetType type) {
121    addParameter(DatasetSearchParameter.TYPE, type);
122  }
123
124  public void addProjectIdentifier(String identifier) {
125    addParameter(DatasetSearchParameter.PROJECT_ID, identifier);
126  }
127
128  public void addTaxonKey(int taxonKey) {
129    addParameter(DatasetSearchParameter.TAXON_KEY, taxonKey);
130  }
131
132  public void addYear(int year) {
133    addParameter(DatasetSearchParameter.YEAR, year);
134  }
135}