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.vocabulary.InstallationType;
016
017import java.util.Date;
018import java.util.List;
019import java.util.UUID;
020
021import javax.annotation.Nullable;
022import javax.validation.constraints.NotNull;
023import javax.validation.constraints.Null;
024
025import com.google.common.base.Objects;
026import com.google.common.collect.Lists;
027import org.codehaus.jackson.annotate.JsonIgnore;
028
029/**
030 * A technical installation which can serve dataset(s).
031 * Note: An Installation may be marked as disabled, meaning that some process has identified it is out of action.
032 * For the GBIF crawling infrastructure, this means it will not be "metasynced" nor will any dataset associated be
033 * eligble for crawling.
034 */
035// TODO: Only allow adding of Endpoints of the correct type, I would argue for removing all the set(List) methods
036public class Installation implements NetworkEntity, Contactable, Endpointable, MachineTaggable, Taggable, Commentable,
037  Identifiable, LenientEquals<Installation> {
038
039  private UUID key;
040  private UUID organizationKey;
041  private String password;
042  private InstallationType type;
043  private String title;
044  private String description;
045  private String createdBy;
046  private String modifiedBy;
047  private Date created;
048  private Date modified;
049  private Date deleted;
050  private boolean disabled;
051  private List<Contact> contacts = Lists.newArrayList();
052  private List<Endpoint> endpoints = Lists.newArrayList();
053  private List<MachineTag> machineTags = Lists.newArrayList();
054  private List<Tag> tags = Lists.newArrayList();
055  private List<Identifier> identifiers = Lists.newArrayList();
056  private List<Comment> comments = Lists.newArrayList();
057
058  @Null(groups = {PrePersist.class})
059  @NotNull(groups = {PostPersist.class})
060  @Override
061  public UUID getKey() {
062    return key;
063  }
064
065  @Override
066  public void setKey(UUID key) {
067    this.key = key;
068  }
069
070  @Override
071  public String getTitle() {
072    return title;
073  }
074
075  public boolean isDisabled() {
076    return disabled;
077  }
078
079  public void setDisabled(boolean disabled) {
080    this.disabled = disabled;
081  }
082
083  @Override
084  public void setTitle(String title) {
085    this.title = title;
086  }
087
088  @Override
089  public String getDescription() {
090    return description;
091  }
092
093  @Override
094  public void setDescription(String description) {
095    this.description = description;
096  }
097
098  @Null(groups = {PrePersist.class})
099  @NotNull(groups = {PostPersist.class})
100  @Override
101  public Date getCreated() {
102    return created;
103  }
104
105  @Override
106  public void setCreated(Date created) {
107    this.created = created;
108  }
109
110  @Null(groups = {PrePersist.class})
111  @NotNull(groups = {PostPersist.class})
112  @Override
113  public Date getModified() {
114    return modified;
115  }
116
117  @Override
118  public void setModified(Date modified) {
119    this.modified = modified;
120  }
121
122  @Override
123  public Date getDeleted() {
124    return deleted;
125  }
126
127  @Override
128  public void setDeleted(Date deleted) {
129    this.deleted = deleted;
130  }
131
132  @NotNull
133  public UUID getOrganizationKey() {
134    return organizationKey;
135  }
136
137  public void setOrganizationKey(UUID organizationKey) {
138    this.organizationKey = organizationKey;
139  }
140
141  /**
142   * Get the installation password. This method is to be ignored on serialization, so that the password is not
143   * revealed in the web service response.
144   * 
145   * @return organization password
146   */
147  @JsonIgnore
148  @Nullable
149  public String getPassword() {
150    return password;
151  }
152
153  public void setPassword(String password) {
154    this.password = password;
155  }
156
157  @NotNull
158  public InstallationType getType() {
159    return type;
160  }
161
162  public void setType(InstallationType type) {
163    this.type = type;
164  }
165
166  @Override
167  public String getCreatedBy() {
168    return createdBy;
169  }
170
171  @Override
172  public void setCreatedBy(String createdBy) {
173    this.createdBy = createdBy;
174  }
175
176  @Override
177  public String getModifiedBy() {
178    return modifiedBy;
179  }
180
181  @Override
182  public void setModifiedBy(String modifiedBy) {
183    this.modifiedBy = modifiedBy;
184  }
185
186  @Override
187  public List<Contact> getContacts() {
188    return contacts;
189  }
190
191  @Override
192  public void setContacts(List<Contact> contacts) {
193    this.contacts = contacts;
194  }
195
196  @Override
197  public List<Endpoint> getEndpoints() {
198    return endpoints;
199  }
200
201  @Override
202  public void setEndpoints(List<Endpoint> endpoints) {
203    this.endpoints = endpoints;
204  }
205
206  @Override
207  public void addEndpoint(Endpoint endpoint) {
208    endpoints.add(endpoint);
209  }
210
211  @Override
212  public List<MachineTag> getMachineTags() {
213    return machineTags;
214  }
215
216  @Override
217  public void setMachineTags(List<MachineTag> machineTags) {
218    this.machineTags = machineTags;
219  }
220
221  @Override
222  public void addMachineTag(MachineTag machineTag) {
223    machineTags.add(machineTag);
224  }
225
226  @Override
227  public List<Tag> getTags() {
228    return tags;
229  }
230
231  @Override
232  public void setTags(List<Tag> tags) {
233    this.tags = tags;
234  }
235
236  @Override
237  public List<Identifier> getIdentifiers() {
238    return identifiers;
239  }
240
241  @Override
242  public void setIdentifiers(List<Identifier> identifiers) {
243    this.identifiers = identifiers;
244  }
245
246  @Override
247  public List<Comment> getComments() {
248    return comments;
249  }
250
251  @Override
252  public void setComments(List<Comment> comments) {
253    this.comments = comments;
254  }
255
256  @Override
257  public int hashCode() {
258    return Objects
259      .hashCode(key, organizationKey, password, type, title, description, createdBy, modifiedBy, created, modified,
260        deleted, disabled, contacts, endpoints, machineTags, tags, identifiers, comments);
261  }
262
263  @Override
264  public boolean equals(Object object) {
265    if (object instanceof Installation) {
266      Installation that = (Installation) object;
267      return Objects.equal(this.key, that.key)
268        && Objects.equal(this.organizationKey, that.organizationKey)
269        && Objects.equal(this.password, that.password)
270        && Objects.equal(this.type, that.type)
271        && Objects.equal(this.title, that.title)
272        && Objects.equal(this.description, that.description)
273        && Objects.equal(this.createdBy, that.createdBy)
274        && Objects.equal(this.modifiedBy, that.modifiedBy)
275        && Objects.equal(this.created, that.created)
276        && Objects.equal(this.modified, that.modified)
277        && Objects.equal(this.deleted, that.deleted)
278        && Objects.equal(this.disabled, that.disabled)
279        && Objects.equal(this.contacts, that.contacts)
280        && Objects.equal(this.endpoints, that.endpoints)
281        && Objects.equal(this.machineTags, that.machineTags)
282        && Objects.equal(this.tags, that.tags)
283        && Objects.equal(this.identifiers, that.identifiers)
284        && Objects.equal(this.comments, that.comments);
285    }
286    return false;
287  }
288
289  @Override
290  public String toString() {
291    return Objects.toStringHelper(this)
292      .add("key", key)
293      .add("organizationKey", organizationKey)
294      .add("password", password)
295      .add("type", type)
296      .add("title", title)
297      .add("description", description)
298      .add("createdBy", createdBy)
299      .add("modifiedBy", modifiedBy)
300      .add("created", created)
301      .add("modified", modified)
302      .add("deleted", deleted)
303      .add("disabled", disabled)
304      .add("contacts", contacts)
305      .add("endpoints", endpoints)
306      .add("machineTags", machineTags)
307      .add("tags", tags)
308      .add("identifiers", identifiers)
309      .add("comments", comments)
310      .toString();
311  }
312
313  /**
314   * Does not include the nested properties, or server controlled values (key, createdBy etc) or the password,
315   * for security reasons.
316   */
317  @Override
318  public boolean lenientEquals(Installation other) {
319    if (this == other) {
320      return true;
321    }
322    return Objects.equal(this.organizationKey, other.organizationKey)
323      && Objects.equal(this.type, other.type)
324      && Objects.equal(this.title, other.title)
325      && Objects.equal(this.description, other.description);
326  }
327}