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