001/*
002 * Copyright 2013 Global Biodiversity Information Facility (GBIF)
003 * Licensed under the Apache License, Version 2.0 (the "License");
004 * you may not use this file except in compliance with the License.
005 * You may obtain a copy of the License at
006 * http://www.apache.org/licenses/LICENSE-2.0
007 * Unless required by applicable law or agreed to in writing, software
008 * distributed under the License is distributed on an "AS IS" BASIS,
009 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
010 * See the License for the specific language governing permissions and
011 * limitations under the License.
012 */
013package org.gbif.api.model.registry;
014
015import org.gbif.api.util.HttpURI;
016import org.gbif.api.vocabulary.Continent;
017import org.gbif.api.vocabulary.Country;
018import org.gbif.api.vocabulary.GbifRegion;
019import org.gbif.api.vocabulary.NodeType;
020import org.gbif.api.vocabulary.ParticipationStatus;
021
022import java.net.URI;
023import java.util.Date;
024import java.util.List;
025import java.util.UUID;
026import javax.annotation.Nullable;
027import javax.validation.constraints.NotNull;
028import javax.validation.constraints.Size;
029
030import com.google.common.base.Objects;
031import com.google.common.collect.Lists;
032
033/**
034 * A GBIF participant node.
035 */
036public class Node implements NetworkEntity, Contactable, Taggable, MachineTaggable, Commentable, Identifiable,
037  Endpointable, LenientEquals<Node>, Address {
038
039  private UUID key;
040  private NodeType type;
041  private ParticipationStatus participationStatus;
042  private Integer participantSince;
043  private Date dateSignedMOU;
044  private GbifRegion gbifRegion;
045  private Continent continent;
046  private String title;
047  private String participantTitle;
048  private String abbreviation;
049  private String description;
050  private List<String> email = Lists.newArrayList();
051  private List<String> phone = Lists.newArrayList();
052  private List<URI> homepage = Lists.newArrayList();
053  private URI logoUrl;
054  private String organization;
055  private List<String> address = Lists.newArrayList();
056  private String city;
057  private String province;
058  private Country country;
059  private String postalCode;
060  private String createdBy;
061  private String modifiedBy;
062  private Date created;
063  private Date modified;
064  private Date deleted;
065  private List<Contact> contacts = Lists.newArrayList();
066  private List<Endpoint> endpoints = Lists.newArrayList();
067  private List<MachineTag> machineTags = Lists.newArrayList();
068  private List<Tag> tags = Lists.newArrayList();
069  private List<Identifier> identifiers = Lists.newArrayList();
070  private List<Comment> comments = Lists.newArrayList();
071
072  @Override
073  public UUID getKey() {
074    return key;
075  }
076
077  @Override
078  public void setKey(UUID key) {
079    this.key = key;
080  }
081
082  @Override
083  public String getTitle() {
084    return title;
085  }
086
087  @Override
088  public void setTitle(String title) {
089    this.title = title;
090  }
091
092  public String getParticipantTitle() {
093    return participantTitle;
094  }
095
096  public void setParticipantTitle(String participantTitle) {
097    this.participantTitle = participantTitle;
098  }
099
100  @Nullable
101  @Size(min = 1, max = 10)
102  public String getAbbreviation() {
103    return abbreviation;
104  }
105
106  public void setAbbreviation(String abbreviation) {
107    this.abbreviation = abbreviation;
108  }
109
110  @Override
111  public String getDescription() {
112    return description;
113  }
114
115  @Override
116  public void setDescription(String description) {
117    this.description = description;
118  }
119
120  @Override
121  public Date getCreated() {
122    return created;
123  }
124
125  @Override
126  public void setCreated(Date created) {
127    this.created = created;
128  }
129
130  @Override
131  public Date getModified() {
132    return modified;
133  }
134
135  @Override
136  public void setModified(Date modified) {
137    this.modified = modified;
138  }
139
140  @Override
141  public Date getDeleted() {
142    return deleted;
143  }
144
145  @Override
146  public void setDeleted(Date deleted) {
147    this.deleted = deleted;
148  }
149
150  @NotNull
151  public NodeType getType() {
152    return type;
153  }
154
155  public void setType(NodeType type) {
156    this.type = type;
157  }
158
159  @NotNull
160  public ParticipationStatus getParticipationStatus() {
161    return participationStatus;
162  }
163
164  public void setParticipationStatus(ParticipationStatus participationStatus) {
165    this.participationStatus = participationStatus;
166  }
167
168  /**
169   * 4 digit year since the node participant first joined GBIF.
170   */
171  @Nullable
172  public Integer getParticipantSince() {
173    return participantSince;
174  }
175
176  public void setParticipantSince(Integer participantSince) {
177    this.participantSince = participantSince;
178  }
179
180  public Date getDateSignedMOU() {
181    return dateSignedMOU;
182  }
183
184  public void setDateSignedMOU(Date dateSignedMOU) {
185    this.dateSignedMOU = dateSignedMOU;
186  }
187
188  @Nullable
189  public GbifRegion getGbifRegion() {
190    return gbifRegion;
191  }
192
193  public void setGbifRegion(GbifRegion gbifRegion) {
194    this.gbifRegion = gbifRegion;
195  }
196
197  @Nullable
198  public Continent getContinent() {
199    return continent;
200  }
201
202  public void setContinent(Continent continent) {
203    this.continent = continent;
204  }
205
206  @Nullable
207  public List<String> getEmail() {
208    return email;
209  }
210
211  public void setEmail(List<String> email) {
212    this.email = email;
213  }
214
215  @Nullable
216  public List<String> getPhone() {
217    return phone;
218  }
219
220  public void setPhone(List<String> phone) {
221    this.phone = phone;
222  }
223
224  @Nullable
225  public List<URI> getHomepage() {
226    return homepage;
227  }
228
229  public void setHomepage(List<URI> homepage) {
230    this.homepage = homepage;
231  }
232
233  @HttpURI
234  @Nullable
235  public URI getLogoUrl() {
236    return logoUrl;
237  }
238
239  public void setLogoUrl(URI logoUrl) {
240    this.logoUrl = logoUrl;
241  }
242
243  @Nullable
244  public String getOrganization() {
245    return organization;
246  }
247
248  public void setOrganization(String organization) {
249    this.organization = organization;
250  }
251
252  @Nullable
253  public List<String> getAddress() {
254    return address;
255  }
256
257  public void setAddress(List<String> address) {
258    this.address = address;
259  }
260
261  @Nullable
262  @Size(min = 1)
263  public String getCity() {
264    return city;
265  }
266
267  public void setCity(String city) {
268    this.city = city;
269  }
270
271  @Nullable
272  @Size(min = 1)
273  public String getProvince() {
274    return province;
275  }
276
277  public void setProvince(String province) {
278    this.province = province;
279  }
280
281  @Nullable
282  public Country getCountry() {
283    return country;
284  }
285
286  public void setCountry(Country country) {
287    this.country = country;
288  }
289
290  @Nullable
291  @Size(min = 1)
292  public String getPostalCode() {
293    return postalCode;
294  }
295
296  public void setPostalCode(String postalCode) {
297    this.postalCode = postalCode;
298  }
299
300  @Override
301  public String getCreatedBy() {
302    return createdBy;
303  }
304
305  @Override
306  public void setCreatedBy(String createdBy) {
307    this.createdBy = createdBy;
308  }
309
310  @Override
311  public String getModifiedBy() {
312    return modifiedBy;
313  }
314
315  @Override
316  public void setModifiedBy(String modifiedBy) {
317    this.modifiedBy = modifiedBy;
318  }
319
320  @Override
321  public List<Contact> getContacts() {
322    return contacts;
323  }
324
325  @Override
326  public void setContacts(List<Contact> contacts) {
327    this.contacts = contacts;
328  }
329
330  @Override
331  public List<Endpoint> getEndpoints() {
332    return endpoints;
333  }
334
335  @Override
336  public void setEndpoints(List<Endpoint> endpoints) {
337    this.endpoints = endpoints;
338  }
339
340  @Override
341  public void addEndpoint(Endpoint endpoint) {
342    endpoints.add(endpoint);
343  }
344
345  @Override
346  public List<MachineTag> getMachineTags() {
347    return machineTags;
348  }
349
350  @Override
351  public void setMachineTags(List<MachineTag> machineTags) {
352    this.machineTags = machineTags;
353  }
354
355  @Override
356  public void addMachineTag(MachineTag machineTag) {
357    machineTags.add(machineTag);
358  }
359
360  @Override
361  public List<Tag> getTags() {
362    return tags;
363  }
364
365  @Override
366  public void setTags(List<Tag> tags) {
367    this.tags = tags;
368  }
369
370  @Override
371  public List<Identifier> getIdentifiers() {
372    return identifiers;
373  }
374
375  @Override
376  public void setIdentifiers(List<Identifier> identifiers) {
377    this.identifiers = identifiers;
378  }
379
380  @Override
381  public List<Comment> getComments() {
382    return comments;
383  }
384
385  @Override
386  public void setComments(List<Comment> comments) {
387    this.comments = comments;
388  }
389
390  @Override
391  public int hashCode() {
392    return Objects
393      .hashCode(key, type, participationStatus, participantSince, dateSignedMOU, gbifRegion, continent, title, abbreviation,
394        description, email, phone, homepage, logoUrl,
395        organization, address, city, province, country, postalCode,
396        createdBy, modifiedBy, created, modified, deleted, contacts, endpoints, machineTags, tags, identifiers,
397        comments, participantTitle);
398  }
399
400  @Override
401  public boolean equals(Object object) {
402    if (object instanceof Node) {
403      Node that = (Node) object;
404      return Objects.equal(this.key, that.key)
405        && Objects.equal(this.type, that.type)
406        && Objects.equal(this.participationStatus, that.participationStatus)
407        && Objects.equal(this.participantSince, that.participantSince)
408        && Objects.equal(this.dateSignedMOU, that.dateSignedMOU)
409        && Objects.equal(this.gbifRegion, that.gbifRegion)
410        && Objects.equal(this.continent, that.continent)
411        && Objects.equal(this.title, that.title)
412        && Objects.equal(this.participantTitle, that.participantTitle)
413        && Objects.equal(this.abbreviation, that.abbreviation)
414        && Objects.equal(this.description, that.description)
415        && Objects.equal(this.email, that.email)
416        && Objects.equal(this.phone, that.phone)
417        && Objects.equal(this.homepage, that.homepage)
418        && Objects.equal(this.logoUrl, that.logoUrl)
419        && Objects.equal(this.organization, that.organization)
420        && Objects.equal(this.address, that.address)
421        && Objects.equal(this.city, that.city)
422        && Objects.equal(this.province, that.province)
423        && Objects.equal(this.country, that.country)
424        && Objects.equal(this.postalCode, that.postalCode)
425        && Objects.equal(this.createdBy, that.createdBy)
426        && Objects.equal(this.modifiedBy, that.modifiedBy)
427        && Objects.equal(this.created, that.created)
428        && Objects.equal(this.modified, that.modified)
429        && Objects.equal(this.deleted, that.deleted)
430        && Objects.equal(this.contacts, that.contacts)
431        && Objects.equal(this.endpoints, that.endpoints)
432        && Objects.equal(this.machineTags, that.machineTags)
433        && Objects.equal(this.tags, that.tags)
434        && Objects.equal(this.identifiers, that.identifiers)
435        && Objects.equal(this.comments, that.comments);
436    }
437    return false;
438  }
439
440  @Override
441  public String toString() {
442    return Objects.toStringHelper(this)
443      .add("key", key)
444      .add("type", type)
445      .add("participationStatus", participationStatus)
446      .add("participantSince", participantSince)
447      .add("dateSignedMOU", dateSignedMOU)
448      .add("gbifRegion", gbifRegion)
449      .add("continent", continent)
450      .add("title", title)
451      .add("participantTitle", participantTitle)
452      .add("abbreviation", abbreviation)
453      .add("description", description)
454      .add("email", email)
455      .add("phone", phone)
456      .add("homepage", homepage)
457      .add("logoUrl", logoUrl)
458      .add("organization", organization)
459      .add("address", address)
460      .add("city", city)
461      .add("province", province)
462      .add("country", country)
463      .add("postalCode", postalCode)
464      .add("createdBy", createdBy)
465      .add("modifiedBy", modifiedBy)
466      .add("created", created)
467      .add("modified", modified)
468      .add("deleted", deleted)
469      .add("contacts", contacts)
470      .add("endpoints", endpoints)
471      .add("machineTags", machineTags)
472      .add("tags", tags)
473      .add("identifiers", identifiers)
474      .add("comments", comments)
475      .toString();
476  }
477
478  /**
479   * Compares the entities for business logic equality using a very lenient approach.
480   * Only fields persisted in the registry database are used in the comparison, excluding any nested properties and
481   * supplementary information which can be added from external databases such as the IMS. Server controlled values such
482   * as key and createdBy are omitted.
483   */
484  @Override
485  public boolean lenientEquals(Node other) {
486    if (this == other) {
487      return true;
488    }
489    return Objects.equal(this.type, other.type)
490      && Objects.equal(this.participationStatus, other.participationStatus)
491      && Objects.equal(this.gbifRegion, other.gbifRegion)
492      && Objects.equal(this.continent, other.continent)
493      && Objects.equal(this.title, other.title)
494      && Objects.equal(this.participantTitle, other.participantTitle)
495      && Objects.equal(this.country, other.country);
496  }
497
498}