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.predicate;
015
016import org.gbif.api.util.PreconditionUtils;
017
018import java.util.Objects;
019import java.util.StringJoiner;
020
021import javax.validation.constraints.NotNull;
022
023import com.fasterxml.jackson.annotation.JsonCreator;
024import com.fasterxml.jackson.annotation.JsonProperty;
025
026import io.swagger.v3.oas.annotations.media.Schema;
027
028/**
029 * This predicate checks performs a full text search based on a query parameter.
030 * Not all predicate back-ends support this predicate.
031 */
032@Schema(
033  description = "This predicate performs a full-text search based on a query parameter.\n\n" +
034    "This predicate type is not currently supported for occurrence downloads.",
035  hidden = true
036)
037public class FullTextSearchPredicate implements Predicate {
038
039  @NotNull
040  private final String q;
041
042  @JsonCreator
043  public FullTextSearchPredicate(@NotNull @JsonProperty("key") String q) {
044    PreconditionUtils.checkArgument( q != null && !q.trim().isEmpty(), "Query parameter can't be null or empty");
045    this.q = q.trim();
046  }
047
048  /**
049   * Text query parameter.
050   */
051  public String getQ() {
052    return q;
053  }
054
055  @Override
056  public boolean equals(Object o) {
057    if (this == o) {
058      return true;
059    }
060    if (o == null || getClass() != o.getClass()) {
061      return false;
062    }
063    FullTextSearchPredicate that = (FullTextSearchPredicate) o;
064    return q.equals(that.q);
065  }
066
067  @Override
068  public int hashCode() {
069    return Objects.hash(q);
070  }
071
072  @Override
073  public String toString() {
074    return new StringJoiner(", ", FullTextSearchPredicate.class.getSimpleName() + "[", "]")
075      .add("q=" + q)
076      .toString();
077  }
078}