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.math.BigDecimal;
020import java.net.URI;
021import java.util.Date;
022import java.util.List;
023import java.util.UUID;
024import javax.annotation.Nullable;
025import javax.validation.constraints.Max;
026import javax.validation.constraints.Min;
027import javax.validation.constraints.NotNull;
028import javax.validation.constraints.Size;
029
030import com.google.common.base.Objects;
031import com.google.common.collect.Lists;
032import org.codehaus.jackson.annotate.JsonIgnore;
033
034/**
035 * A GBIF data publisher.
036 */
037public class Organization
038  implements NetworkEntity, Contactable, Endpointable, MachineTaggable, Taggable, Identifiable, Commentable,
039  LenientEquals<Organization>, Address {
040
041  private UUID key;
042  private UUID endorsingNodeKey;
043  private boolean endorsementApproved;
044  private String password;
045  private String title;
046  private String abbreviation;
047  private String description;
048  private Language language;
049  private List<String> email;
050  private List<String> phone;
051  private List<URI> homepage;
052  private URI logoUrl;
053  private List<String> address;
054  private String city;
055  private String province;
056  private Country country;
057  private String postalCode;
058  private BigDecimal latitude;
059  private BigDecimal longitude;
060  private int numPublishedDatasets;
061  private String createdBy;
062  private String modifiedBy;
063  private Date created;
064  private Date modified;
065  private Date deleted;
066  private List<Contact> contacts = Lists.newArrayList();
067  private List<Endpoint> endpoints = Lists.newArrayList();
068  private List<MachineTag> machineTags = Lists.newArrayList();
069  private List<Tag> tags = Lists.newArrayList();
070  private List<Identifier> identifiers = Lists.newArrayList();
071  private List<Comment> comments = Lists.newArrayList();
072
073  @Override
074  public UUID getKey() {
075    return key;
076  }
077
078  @Override
079  public void setKey(UUID key) {
080    this.key = key;
081  }
082
083  @Override
084  public String getTitle() {
085    return title;
086  }
087
088  @Override
089  public void setTitle(String title) {
090    this.title = title;
091  }
092
093  @Override
094  public String getDescription() {
095    return description;
096  }
097
098  @Override
099  public void setDescription(String description) {
100    this.description = description;
101  }
102
103  @Override
104  public Date getCreated() {
105    return created;
106  }
107
108  @Override
109  public void setCreated(Date created) {
110    this.created = created;
111  }
112
113  @Override
114  public Date getModified() {
115    return modified;
116  }
117
118  @Override
119  public void setModified(Date modified) {
120    this.modified = modified;
121  }
122
123  @Override
124  public Date getDeleted() {
125    return deleted;
126  }
127
128  @Override
129  public void setDeleted(Date deleted) {
130    this.deleted = deleted;
131  }
132
133  @NotNull
134  public UUID getEndorsingNodeKey() {
135    return endorsingNodeKey;
136  }
137
138  public void setEndorsingNodeKey(UUID endorsingNodeKey) {
139    this.endorsingNodeKey = endorsingNodeKey;
140  }
141
142  public boolean isEndorsementApproved() {
143    return endorsementApproved;
144  }
145
146  public void setEndorsementApproved(boolean endorsementApproved) {
147    this.endorsementApproved = endorsementApproved;
148  }
149
150  /**
151   * Get the organization password. This method is to be ignored on serialization, so that the password is not
152   * revealed in the web service response.
153   *
154   * @return organization password
155   */
156  @JsonIgnore
157  @Nullable
158  public String getPassword() {
159    return password;
160  }
161
162  public void setPassword(String password) {
163    this.password = password;
164  }
165
166  @Nullable
167  @Size(min = 1, max = 10)
168  public String getAbbreviation() {
169    return abbreviation;
170  }
171
172  public void setAbbreviation(String abbreviation) {
173    this.abbreviation = abbreviation;
174  }
175
176  @NotNull
177  public Language getLanguage() {
178    return language;
179  }
180
181  public void setLanguage(Language language) {
182    this.language = language;
183  }
184
185  @Nullable
186  public List<String> getEmail() {
187    return email;
188  }
189
190  public void setEmail(List<String> email) {
191    this.email = email;
192  }
193
194  @Nullable
195  public List<String> getPhone() {
196    return phone;
197  }
198
199  public void setPhone(List<String> phone) {
200    this.phone = phone;
201  }
202
203  @Nullable
204  public List<URI> getHomepage() {
205    return homepage;
206  }
207
208  public void setHomepage(List<URI> homepage) {
209    this.homepage = homepage;
210  }
211
212  @HttpURI
213  @Nullable
214  public URI getLogoUrl() {
215    return logoUrl;
216  }
217
218  public void setLogoUrl(URI logoUrl) {
219    this.logoUrl = logoUrl;
220  }
221
222  @Nullable
223  public List<String> getAddress() {
224    return address;
225  }
226
227  public void setAddress(List<String> address) {
228    this.address = address;
229  }
230
231  @Nullable
232  public String getCity() {
233    return city;
234  }
235
236  public void setCity(String city) {
237    this.city = city;
238  }
239
240  @Nullable
241  public String getProvince() {
242    return province;
243  }
244
245  public void setProvince(String province) {
246    this.province = province;
247  }
248
249  @Nullable
250  public Country getCountry() {
251    return country;
252  }
253
254  public void setCountry(Country country) {
255    this.country = country;
256  }
257
258  @Nullable
259  public String getPostalCode() {
260    return postalCode;
261  }
262
263  public void setPostalCode(String postalCode) {
264    this.postalCode = postalCode;
265  }
266
267  @Nullable
268  @Override
269  @JsonIgnore
270  public String getOrganization() {
271    return getTitle();
272  }
273
274  @Override
275  public void setOrganization(String organization) {
276    setTitle(organization);
277  }
278
279  @Nullable
280  @Min(-90)
281  @Max(90)
282  public BigDecimal getLatitude() {
283    return latitude;
284  }
285
286  public void setLatitude(BigDecimal latitude) {
287    this.latitude = latitude;
288  }
289
290  @Nullable
291  @Min(-180)
292  @Max(180)
293  public BigDecimal getLongitude() {
294    return longitude;
295  }
296
297  public void setLongitude(BigDecimal longitude) {
298    this.longitude = longitude;
299  }
300
301  @Min(0)
302  public int getNumPublishedDatasets() {
303    return numPublishedDatasets;
304  }
305
306  public void setNumPublishedDatasets(int numPublishedDatasets) {
307    this.numPublishedDatasets = numPublishedDatasets;
308  }
309
310  @Override
311  public String getCreatedBy() {
312    return createdBy;
313  }
314
315  @Override
316  public void setCreatedBy(String createdBy) {
317    this.createdBy = createdBy;
318  }
319
320  @Override
321  public String getModifiedBy() {
322    return modifiedBy;
323  }
324
325  @Override
326  public void setModifiedBy(String modifiedBy) {
327    this.modifiedBy = modifiedBy;
328  }
329
330  @Override
331  public List<Contact> getContacts() {
332    return contacts;
333  }
334
335  @Override
336  public void setContacts(List<Contact> contacts) {
337    this.contacts = contacts;
338  }
339
340  @Override
341  public List<Endpoint> getEndpoints() {
342    return endpoints;
343  }
344
345  @Override
346  public void setEndpoints(List<Endpoint> endpoints) {
347    this.endpoints = endpoints;
348  }
349
350  @Override
351  public void addEndpoint(Endpoint endpoint) {
352    endpoints.add(endpoint);
353  }
354
355  @Override
356  public List<MachineTag> getMachineTags() {
357    return machineTags;
358  }
359
360  @Override
361  public void setMachineTags(List<MachineTag> machineTags) {
362    this.machineTags = machineTags;
363  }
364
365  @Override
366  public void addMachineTag(MachineTag machineTag) {
367    machineTags.add(machineTag);
368  }
369
370  @Override
371  public List<Tag> getTags() {
372    return tags;
373  }
374
375  @Override
376  public void setTags(List<Tag> tags) {
377    this.tags = tags;
378  }
379
380  @Override
381  public List<Identifier> getIdentifiers() {
382    return identifiers;
383  }
384
385  @Override
386  public void setIdentifiers(List<Identifier> identifiers) {
387    this.identifiers = identifiers;
388  }
389
390  @Override
391  public List<Comment> getComments() {
392    return comments;
393  }
394
395  @Override
396  public void setComments(List<Comment> comments) {
397    this.comments = comments;
398  }
399
400  @Override
401  public int hashCode() {
402    return Objects
403      .hashCode(key, endorsingNodeKey, endorsementApproved, password, title, abbreviation, description, language, email,
404        phone, homepage, logoUrl, address, city, province, country, postalCode, latitude, longitude,
405        numPublishedDatasets,
406        createdBy, modifiedBy, created, modified, deleted, contacts, endpoints, machineTags, tags, identifiers,
407        comments);
408  }
409
410  @Override
411  public boolean equals(Object object) {
412    if (object instanceof Organization) {
413      Organization that = (Organization) object;
414      return Objects.equal(this.key, that.key)
415        && Objects.equal(this.endorsingNodeKey, that.endorsingNodeKey)
416        && Objects.equal(this.endorsementApproved, that.endorsementApproved)
417        && Objects.equal(this.password, that.password)
418        && Objects.equal(this.title, that.title)
419        && Objects.equal(this.abbreviation, that.abbreviation)
420        && Objects.equal(this.description, that.description)
421        && Objects.equal(this.language, that.language)
422        && Objects.equal(this.email, that.email)
423        && Objects.equal(this.phone, that.phone)
424        && Objects.equal(this.homepage, that.homepage)
425        && Objects.equal(this.logoUrl, that.logoUrl)
426        && Objects.equal(this.address, that.address)
427        && Objects.equal(this.city, that.city)
428        && Objects.equal(this.province, that.province)
429        && Objects.equal(this.country, that.country)
430        && Objects.equal(this.postalCode, that.postalCode)
431        && Objects.equal(this.latitude, that.latitude)
432        && Objects.equal(this.longitude, that.longitude)
433        && Objects.equal(this.numPublishedDatasets, that.numPublishedDatasets)
434        && Objects.equal(this.createdBy, that.createdBy)
435        && Objects.equal(this.modifiedBy, that.modifiedBy)
436        && Objects.equal(this.created, that.created)
437        && Objects.equal(this.modified, that.modified)
438        && Objects.equal(this.deleted, that.deleted)
439        && Objects.equal(this.contacts, that.contacts)
440        && Objects.equal(this.endpoints, that.endpoints)
441        && Objects.equal(this.machineTags, that.machineTags)
442        && Objects.equal(this.tags, that.tags)
443        && Objects.equal(this.identifiers, that.identifiers)
444        && Objects.equal(this.comments, that.comments);
445    }
446    return false;
447  }
448
449  @Override
450  public String toString() {
451    return Objects.toStringHelper(this)
452      .add("key", key)
453      .add("endorsingNodeKey", endorsingNodeKey)
454      .add("endorsementApproved", endorsementApproved)
455      .add("password", password)
456      .add("title", title)
457      .add("abbreviation", abbreviation)
458      .add("description", description)
459      .add("language", language)
460      .add("email", email)
461      .add("phone", phone)
462      .add("homepage", homepage)
463      .add("logoUrl", logoUrl)
464      .add("address", address)
465      .add("city", city)
466      .add("province", province)
467      .add("country", country)
468      .add("postalCode", postalCode)
469      .add("latitude", latitude)
470      .add("longitude", longitude)
471      .add("numDatasets", numPublishedDatasets)
472      .add("createdBy", createdBy)
473      .add("modifiedBy", modifiedBy)
474      .add("created", created)
475      .add("modified", modified)
476      .add("deleted", deleted)
477      .add("contacts", contacts)
478      .add("endpoints", endpoints)
479      .add("machineTags", machineTags)
480      .add("tags", tags)
481      .add("identifiers", identifiers)
482      .add("comments", comments)
483      .toString();
484  }
485
486  /**
487   * A lenient equality check for business logic uniqueness. Does not include server side controlled fields such as key
488   * and createdBy, nested objects and does not include password for security reasons.
489   */
490  @Override
491  public boolean lenientEquals(Organization other) {
492    if (this == other) {
493      return true;
494    }
495    return Objects.equal(this.endorsingNodeKey, other.endorsingNodeKey)
496      && Objects.equal(this.endorsementApproved, other.endorsementApproved)
497      && Objects.equal(this.title, other.title)
498      && Objects.equal(this.abbreviation, other.abbreviation)
499      && Objects.equal(this.description, other.description)
500      && Objects.equal(this.language, other.language)
501      && Objects.equal(this.email, other.email)
502      && Objects.equal(this.phone, other.phone)
503      && Objects.equal(this.homepage, other.homepage)
504      && Objects.equal(this.logoUrl, other.logoUrl)
505      && Objects.equal(this.address, other.address)
506      && Objects.equal(this.city, other.city)
507      && Objects.equal(this.province, other.province)
508      && Objects.equal(this.country, other.country)
509      && Objects.equal(this.postalCode, other.postalCode)
510      && Objects.equal(this.latitude, other.latitude)
511      && Objects.equal(this.longitude, other.longitude)
512      && Objects.equal(this.deleted, other.deleted);
513  }
514}