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.Country;
017import org.gbif.api.vocabulary.Language;
018
019import java.net.URI;
020import java.util.Date;
021import java.util.List;
022import java.util.UUID;
023import javax.annotation.Nullable;
024import javax.validation.constraints.Min;
025import javax.validation.constraints.NotNull;
026import javax.validation.constraints.Size;
027
028import com.google.common.base.Objects;
029import com.google.common.collect.Lists;
030import org.codehaus.jackson.annotate.JsonIgnore;
031
032/**
033 * A GBIF network.
034 */
035public class Network implements NetworkEntity, Contactable, Endpointable, MachineTaggable, Taggable, Commentable,
036  Identifiable, LenientEquals<Network>, Address {
037
038  private UUID key;
039  private String title;
040  private String description;
041  private Language language;
042  private int numConstituents;
043  private List<String> email;
044  private List<String> phone;
045  private List<URI> homepage;
046  private URI logoUrl;
047  private List<String> address;
048  private String city;
049  private String province;
050  private Country country;
051  private String postalCode;
052  private String createdBy;
053  private String modifiedBy;
054  private Date created;
055  private Date modified;
056  private Date deleted;
057  private List<Contact> contacts = Lists.newArrayList();
058  private List<Endpoint> endpoints = Lists.newArrayList();
059  private List<MachineTag> machineTags = Lists.newArrayList();
060  private List<Tag> tags = Lists.newArrayList();
061  private List<Identifier> identifiers = Lists.newArrayList();
062  private List<Comment> comments = Lists.newArrayList();
063
064  @Override
065  public UUID getKey() {
066    return key;
067  }
068
069  @Override
070  public void setKey(UUID key) {
071    this.key = key;
072  }
073
074  @Override
075  public String getTitle() {
076    return title;
077  }
078
079  @Override
080  public void setTitle(String title) {
081    this.title = title;
082  }
083
084  @Override
085  public String getDescription() {
086    return description;
087  }
088
089  @Override
090  public void setDescription(String description) {
091    this.description = description;
092  }
093
094  @Override
095  public Date getCreated() {
096    return created;
097  }
098
099  @Override
100  public void setCreated(Date created) {
101    this.created = created;
102  }
103
104  @Override
105  public Date getModified() {
106    return modified;
107  }
108
109  @Override
110  public void setModified(Date modified) {
111    this.modified = modified;
112  }
113
114  @Override
115  public Date getDeleted() {
116    return deleted;
117  }
118
119  @Override
120  public void setDeleted(Date deleted) {
121    this.deleted = deleted;
122  }
123
124  @NotNull
125  public Language getLanguage() {
126    return language;
127  }
128
129  public void setLanguage(Language language) {
130    this.language = language;
131  }
132
133  @Nullable
134  public List<String> getEmail() {
135    return email;
136  }
137
138  public void setEmail(List<String> email) {
139    this.email = email;
140  }
141
142  @Nullable
143  public List<String> getPhone() {
144    return phone;
145  }
146
147  public void setPhone(List<String> phone) {
148    this.phone = phone;
149  }
150
151  @Nullable
152  public List<URI> getHomepage() {
153    return homepage;
154  }
155
156  public void setHomepage(List<URI> homepage) {
157    this.homepage = homepage;
158  }
159
160  @HttpURI
161  @Nullable
162  public URI getLogoUrl() {
163    return logoUrl;
164  }
165
166  public void setLogoUrl(URI logoUrl) {
167    this.logoUrl = logoUrl;
168  }
169
170  @Nullable
171  public List<String> getAddress() {
172    return address;
173  }
174
175  public void setAddress(List<String> address) {
176    this.address = address;
177  }
178
179  @Nullable
180  @Size(min = 1)
181  public String getCity() {
182    return city;
183  }
184
185  public void setCity(String city) {
186    this.city = city;
187  }
188
189  @Nullable
190  @Size(min = 1)
191  public String getProvince() {
192    return province;
193  }
194
195  public void setProvince(String province) {
196    this.province = province;
197  }
198
199  @Nullable
200  public Country getCountry() {
201    return country;
202  }
203
204  public void setCountry(Country country) {
205    this.country = country;
206  }
207
208  @Nullable
209  @Size(min = 1)
210  public String getPostalCode() {
211    return postalCode;
212  }
213
214  public void setPostalCode(String postalCode) {
215    this.postalCode = postalCode;
216  }
217
218  @Override
219  public String getCreatedBy() {
220    return createdBy;
221  }
222
223  @Override
224  public void setCreatedBy(String createdBy) {
225    this.createdBy = createdBy;
226  }
227
228  @Override
229  public String getModifiedBy() {
230    return modifiedBy;
231  }
232
233  @Override
234  public void setModifiedBy(String modifiedBy) {
235    this.modifiedBy = modifiedBy;
236  }
237
238  @Override
239  public List<Contact> getContacts() {
240    return contacts;
241  }
242
243  @Override
244  public void setContacts(List<Contact> contacts) {
245    this.contacts = contacts;
246  }
247
248  @Override
249  public List<Endpoint> getEndpoints() {
250    return endpoints;
251  }
252
253  @Override
254  public void setEndpoints(List<Endpoint> endpoints) {
255    this.endpoints = endpoints;
256  }
257
258  @Override
259  public void addEndpoint(Endpoint endpoint) {
260    endpoints.add(endpoint);
261  }
262
263  @Override
264  public List<MachineTag> getMachineTags() {
265    return machineTags;
266  }
267
268  @Override
269  public void setMachineTags(List<MachineTag> machineTags) {
270    this.machineTags = machineTags;
271  }
272
273  @Override
274  public void addMachineTag(MachineTag machineTag) {
275    machineTags.add(machineTag);
276  }
277
278  @Override
279  public List<Tag> getTags() {
280    return tags;
281  }
282
283  @Override
284  public void setTags(List<Tag> tags) {
285    this.tags = tags;
286  }
287
288  @Override
289  public List<Identifier> getIdentifiers() {
290    return identifiers;
291  }
292
293  @Override
294  public void setIdentifiers(List<Identifier> identifiers) {
295    this.identifiers = identifiers;
296  }
297
298  @Override
299  public List<Comment> getComments() {
300    return comments;
301  }
302
303  @Override
304  public void setComments(List<Comment> comments) {
305    this.comments = comments;
306  }
307
308  @Min(0)
309  public int getNumConstituents() {
310    return numConstituents;
311  }
312
313  public void setNumConstituents(int numConstituents) {
314    this.numConstituents = numConstituents;
315  }
316
317  /**
318   * Alias for the network title
319   */
320  @Nullable
321  @Override
322  @JsonIgnore
323  public String getOrganization() {
324    return getTitle();
325  }
326
327  /**
328   * Alias for the network title
329   */
330  @Override
331  public void setOrganization(String organization) {
332    setTitle(organization);
333  }
334
335  @Override
336  public int hashCode() {
337    return Objects
338      .hashCode(key, title, description, language, email, phone, homepage, logoUrl, address, city, province, country,
339        postalCode, createdBy, modifiedBy, created, modified, deleted, contacts, endpoints, machineTags, tags,
340        identifiers, comments, numConstituents);
341  }
342
343  @Override
344  public boolean equals(Object object) {
345    if (object instanceof Network) {
346      Network that = (Network) object;
347      return Objects.equal(this.key, that.key)
348        && Objects.equal(this.title, that.title)
349        && Objects.equal(this.description, that.description)
350        && Objects.equal(this.language, that.language)
351        && Objects.equal(this.email, that.email)
352        && Objects.equal(this.phone, that.phone)
353        && Objects.equal(this.homepage, that.homepage)
354        && Objects.equal(this.logoUrl, that.logoUrl)
355        && Objects.equal(this.address, that.address)
356        && Objects.equal(this.city, that.city)
357        && Objects.equal(this.province, that.province)
358        && Objects.equal(this.country, that.country)
359        && Objects.equal(this.postalCode, that.postalCode)
360        && Objects.equal(this.createdBy, that.createdBy)
361        && Objects.equal(this.modifiedBy, that.modifiedBy)
362        && Objects.equal(this.created, that.created)
363        && Objects.equal(this.modified, that.modified)
364        && Objects.equal(this.deleted, that.deleted)
365        && Objects.equal(this.contacts, that.contacts)
366        && Objects.equal(this.endpoints, that.endpoints)
367        && Objects.equal(this.machineTags, that.machineTags)
368        && Objects.equal(this.tags, that.tags)
369        && Objects.equal(this.identifiers, that.identifiers)
370        && Objects.equal(this.comments, that.comments)
371        && Objects.equal(this.numConstituents, that.numConstituents);
372    }
373    return false;
374  }
375
376  @Override
377  public String toString() {
378    return Objects.toStringHelper(this)
379      .add("key", key)
380      .add("title", title)
381      .add("description", description)
382      .add("language", language)
383      .add("email", email)
384      .add("phone", phone)
385      .add("homepage", homepage)
386      .add("logoUrl", logoUrl)
387      .add("address", address)
388      .add("city", city)
389      .add("province", province)
390      .add("country", country)
391      .add("postalCode", postalCode)
392      .add("createdBy", createdBy)
393      .add("modifiedBy", modifiedBy)
394      .add("created", created)
395      .add("modified", modified)
396      .add("deleted", deleted)
397      .add("contacts", contacts)
398      .add("endpoints", endpoints)
399      .add("machineTags", machineTags)
400      .add("tags", tags)
401      .add("identifiers", identifiers)
402      .add("comments", comments)
403      .add("numConstituents", numConstituents)
404      .toString();
405  }
406
407  /**
408   * Tests persisted fields, excluding the server controlled values such as key and createdBy. Does not included nested
409   * properties in the test.
410   */
411  @Override
412  public boolean lenientEquals(Network other) {
413    if (this == other) {
414      return true;
415    }
416    return Objects.equal(this.title, other.title)
417      && Objects.equal(this.description, other.description)
418      && Objects.equal(this.language, other.language)
419      && Objects.equal(this.email, other.email)
420      && Objects.equal(this.phone, other.phone)
421      && Objects.equal(this.homepage, other.homepage)
422      && Objects.equal(this.logoUrl, other.logoUrl)
423      && Objects.equal(this.address, other.address)
424      && Objects.equal(this.city, other.city)
425      && Objects.equal(this.province, other.province)
426      && Objects.equal(this.country, other.country)
427      && Objects.equal(this.postalCode, other.postalCode);
428  }
429
430}