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.collections; 015 016import java.io.Serializable; 017import java.util.ArrayList; 018import java.util.Date; 019import java.util.List; 020import java.util.Objects; 021import java.util.StringJoiner; 022 023import org.gbif.api.model.registry.LenientEquals; 024import org.gbif.api.model.registry.PostPersist; 025import org.gbif.api.model.registry.PrePersist; 026import org.gbif.api.util.validators.email.ValidEmail; 027import org.gbif.api.vocabulary.Country; 028 029import javax.validation.Valid; 030import javax.validation.constraints.NotNull; 031import javax.validation.constraints.Null; 032 033/** Contact associated to a GRSciColl {@link Collection} or {@link Institution}. */ 034public class Contact implements LenientEquals<Contact>, Serializable { 035 036 private Integer key; 037 private String firstName; 038 private String lastName; 039 private List<String> position = new ArrayList<>(); 040 private List<String> phone = new ArrayList<>(); 041 private List<String> fax = new ArrayList<>(); 042 private List<@ValidEmail String> email = new ArrayList<>(); 043 private List<String> address = new ArrayList<>(); 044 private String city; 045 private String province; 046 private Country country; 047 private String postalCode; 048 private boolean primary; 049 private List<String> taxonomicExpertise = new ArrayList<>(); 050 private String notes; 051 private List<@Valid UserId> userIds = new ArrayList<>(); 052 private String createdBy; 053 private String modifiedBy; 054 private Date created; 055 private Date modified; 056 057 @Null(groups = {PrePersist.class}) 058 @NotNull(groups = {PostPersist.class}) 059 public Integer getKey() { 060 return key; 061 } 062 063 public void setKey(Integer key) { 064 this.key = key; 065 } 066 067 public String getFirstName() { 068 return firstName; 069 } 070 071 public void setFirstName(String firstName) { 072 this.firstName = firstName; 073 } 074 075 public String getLastName() { 076 return lastName; 077 } 078 079 public void setLastName(String lastName) { 080 this.lastName = lastName; 081 } 082 083 public List<String> getPosition() { 084 return position; 085 } 086 087 public void setPosition(List<String> position) { 088 this.position = position; 089 } 090 091 public List<String> getPhone() { 092 return phone; 093 } 094 095 public void setPhone(List<String> phone) { 096 this.phone = phone; 097 } 098 099 public List<String> getFax() { 100 return fax; 101 } 102 103 public void setFax(List<String> fax) { 104 this.fax = fax; 105 } 106 107 public List<String> getEmail() { 108 return email; 109 } 110 111 public void setEmail(List<String> email) { 112 this.email = email; 113 } 114 115 public List<String> getAddress() { 116 return address; 117 } 118 119 public void setAddress(List<String> address) { 120 this.address = address; 121 } 122 123 public String getCity() { 124 return city; 125 } 126 127 public void setCity(String city) { 128 this.city = city; 129 } 130 131 public String getProvince() { 132 return province; 133 } 134 135 public void setProvince(String province) { 136 this.province = province; 137 } 138 139 public Country getCountry() { 140 return country; 141 } 142 143 public void setCountry(Country country) { 144 this.country = country; 145 } 146 147 public String getPostalCode() { 148 return postalCode; 149 } 150 151 public void setPostalCode(String postalCode) { 152 this.postalCode = postalCode; 153 } 154 155 public boolean isPrimary() { 156 return primary; 157 } 158 159 public void setPrimary(boolean primary) { 160 this.primary = primary; 161 } 162 163 public List<String> getTaxonomicExpertise() { 164 return taxonomicExpertise; 165 } 166 167 public void setTaxonomicExpertise(List<String> taxonomicExpertise) { 168 this.taxonomicExpertise = taxonomicExpertise; 169 } 170 171 public String getNotes() { 172 return notes; 173 } 174 175 public void setNotes(String notes) { 176 this.notes = notes; 177 } 178 179 public List<UserId> getUserIds() { 180 return userIds; 181 } 182 183 public void setUserIds(List<UserId> userIds) { 184 this.userIds = userIds; 185 } 186 187 public String getCreatedBy() { 188 return createdBy; 189 } 190 191 public void setCreatedBy(String createdBy) { 192 this.createdBy = createdBy; 193 } 194 195 public String getModifiedBy() { 196 return modifiedBy; 197 } 198 199 public void setModifiedBy(String modifiedBy) { 200 this.modifiedBy = modifiedBy; 201 } 202 203 public Date getCreated() { 204 return created; 205 } 206 207 public void setCreated(Date created) { 208 this.created = created; 209 } 210 211 public Date getModified() { 212 return modified; 213 } 214 215 public void setModified(Date modified) { 216 this.modified = modified; 217 } 218 219 @Override 220 public boolean equals(Object o) { 221 if (this == o) { 222 return true; 223 } 224 if (o == null || getClass() != o.getClass()) { 225 return false; 226 } 227 Contact contact = (Contact) o; 228 return Objects.equals(key, contact.key) 229 && Objects.equals(firstName, contact.firstName) 230 && Objects.equals(lastName, contact.lastName) 231 && Objects.equals(position, contact.position) 232 && Objects.equals(phone, contact.phone) 233 && Objects.equals(fax, contact.fax) 234 && Objects.equals(email, contact.email) 235 && Objects.equals(address, contact.address) 236 && Objects.equals(city, contact.city) 237 && Objects.equals(province, contact.province) 238 && country == contact.country 239 && Objects.equals(postalCode, contact.postalCode) 240 && primary == contact.primary 241 && Objects.equals(taxonomicExpertise, contact.taxonomicExpertise) 242 && Objects.equals(notes, contact.notes) 243 && Objects.equals(userIds, contact.userIds) 244 && Objects.equals(createdBy, contact.createdBy) 245 && Objects.equals(modifiedBy, contact.modifiedBy) 246 && Objects.equals(created, contact.created) 247 && Objects.equals(modified, contact.modified); 248 } 249 250 @Override 251 public boolean lenientEquals(Contact contact) { 252 if (this == contact) { 253 return true; 254 } 255 256 return Objects.equals(firstName, contact.firstName) 257 && Objects.equals(lastName, contact.lastName) 258 && Objects.equals(position, contact.position) 259 && Objects.equals(phone, contact.phone) 260 && Objects.equals(fax, contact.fax) 261 && Objects.equals(email, contact.email) 262 && Objects.equals(address, contact.address) 263 && Objects.equals(city, contact.city) 264 && Objects.equals(province, contact.province) 265 && country == contact.country 266 && Objects.equals(postalCode, contact.postalCode) 267 && primary == contact.primary 268 && Objects.equals(taxonomicExpertise, contact.taxonomicExpertise) 269 && Objects.equals(notes, contact.notes) 270 && Objects.equals(userIds, contact.userIds); 271 } 272 273 @Override 274 public int hashCode() { 275 return Objects.hash( 276 key, 277 firstName, 278 lastName, 279 position, 280 phone, 281 fax, 282 email, 283 address, 284 city, 285 province, 286 country, 287 postalCode, 288 primary, 289 taxonomicExpertise, 290 notes, 291 userIds, 292 createdBy, 293 modifiedBy, 294 created, 295 modified); 296 } 297 298 @Override 299 public String toString() { 300 return new StringJoiner(", ", Contact.class.getSimpleName() + "[", "]") 301 .add("key=" + key) 302 .add("firstName='" + firstName + "'") 303 .add("lastName='" + lastName + "'") 304 .add("position='" + position + "'") 305 .add("phone=" + phone) 306 .add("fax=" + fax) 307 .add("email=" + email) 308 .add("address=" + address) 309 .add("city='" + city + "'") 310 .add("province='" + province + "'") 311 .add("country=" + country) 312 .add("postalCode='" + postalCode + "'") 313 .add("primary='" + primary + "'") 314 .add("taxonomicExpertise='" + taxonomicExpertise + "'") 315 .add("notes='" + notes + "'") 316 .add("userIds=" + userIds) 317 .add("createdBy='" + createdBy + "'") 318 .add("modifiedBy='" + modifiedBy + "'") 319 .add("created=" + created) 320 .add("modified=" + modified) 321 .toString(); 322 } 323}