001/* 002 * Copyright 2020-2021 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.collections.lookup; 017 018import org.gbif.api.vocabulary.Country; 019 020import java.util.Objects; 021import java.util.StringJoiner; 022import java.util.UUID; 023 024import org.apache.commons.lang3.StringUtils; 025 026/** Holds the parameters that the collections lookup accepts. */ 027public class LookupParams { 028 029 private String institutionCode; 030 private String ownerInstitutionCode; 031 private String institutionId; 032 private String collectionCode; 033 private String collectionId; 034 private UUID datasetKey; 035 private Country country; 036 private boolean verbose; 037 038 public String getInstitutionCode() { 039 return institutionCode; 040 } 041 042 public void setInstitutionCode(String institutionCode) { 043 this.institutionCode = institutionCode; 044 } 045 046 public String getOwnerInstitutionCode() { 047 return ownerInstitutionCode; 048 } 049 050 public void setOwnerInstitutionCode(String ownerInstitutionCode) { 051 this.ownerInstitutionCode = ownerInstitutionCode; 052 } 053 054 public String getInstitutionId() { 055 return institutionId; 056 } 057 058 public void setInstitutionId(String institutionId) { 059 this.institutionId = institutionId; 060 } 061 062 public String getCollectionCode() { 063 return collectionCode; 064 } 065 066 public void setCollectionCode(String collectionCode) { 067 this.collectionCode = collectionCode; 068 } 069 070 public String getCollectionId() { 071 return collectionId; 072 } 073 074 public void setCollectionId(String collectionId) { 075 this.collectionId = collectionId; 076 } 077 078 public UUID getDatasetKey() { 079 return datasetKey; 080 } 081 082 public void setDatasetKey(UUID datasetKey) { 083 this.datasetKey = datasetKey; 084 } 085 086 public Country getCountry() { 087 return country; 088 } 089 090 public void setCountry(Country country) { 091 this.country = country; 092 } 093 094 public boolean isVerbose() { 095 return verbose; 096 } 097 098 public void setVerbose(boolean verbose) { 099 this.verbose = verbose; 100 } 101 102 public boolean containsInstitutionParams() { 103 return StringUtils.isNotBlank(institutionCode) 104 || StringUtils.isNotBlank(institutionId) 105 || StringUtils.isNotBlank(ownerInstitutionCode); 106 } 107 108 public boolean containsCollectionParams() { 109 return StringUtils.isNotBlank(collectionCode) || StringUtils.isNotBlank(collectionId); 110 } 111 112 @Override 113 public boolean equals(Object o) { 114 if (this == o) { 115 return true; 116 } 117 if (o == null || getClass() != o.getClass()) { 118 return false; 119 } 120 LookupParams that = (LookupParams) o; 121 return verbose == that.verbose 122 && Objects.equals(institutionCode, that.institutionCode) 123 && Objects.equals(ownerInstitutionCode, that.ownerInstitutionCode) 124 && Objects.equals(institutionId, that.institutionId) 125 && Objects.equals(collectionCode, that.collectionCode) 126 && Objects.equals(collectionId, that.collectionId) 127 && Objects.equals(datasetKey, that.datasetKey) 128 && country == that.country; 129 } 130 131 @Override 132 public int hashCode() { 133 return Objects.hash( 134 institutionCode, 135 ownerInstitutionCode, 136 institutionId, 137 collectionCode, 138 collectionId, 139 datasetKey, 140 country, 141 verbose); 142 } 143 144 @Override 145 public String toString() { 146 return new StringJoiner(", ", LookupParams.class.getSimpleName() + "[", "]") 147 .add("institutionCode='" + institutionCode + "'") 148 .add("ownerInstitutionCode='" + ownerInstitutionCode + "'") 149 .add("institutionId='" + institutionId + "'") 150 .add("collectionCode='" + collectionCode + "'") 151 .add("collectionId='" + collectionId + "'") 152 .add("datasetKey=" + datasetKey) 153 .add("country=" + country) 154 .add("verbose=" + verbose) 155 .toString(); 156 } 157}