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.MetadataType;
016
017import java.util.Date;
018import java.util.UUID;
019import javax.validation.constraints.Min;
020import javax.validation.constraints.NotNull;
021import javax.validation.constraints.Size;
022
023import com.google.common.base.Objects;
024
025public class Metadata implements LenientEquals<Metadata> {
026
027  private Integer key;
028  private UUID datasetKey;
029  private MetadataType type;
030  private String content;
031
032  private String createdBy;
033  private String modifiedBy;
034  private Date created;
035  private Date modified;
036
037  @Min(1)
038  public Integer getKey() {
039    return key;
040  }
041
042  public void setKey(Integer key) {
043    this.key = key;
044  }
045
046  @NotNull
047  public UUID getDatasetKey() {
048    return datasetKey;
049  }
050
051  public void setDatasetKey(UUID datasetKey) {
052    this.datasetKey = datasetKey;
053  }
054
055  @NotNull
056  public MetadataType getType() {
057    return type;
058  }
059
060  public void setType(MetadataType type) {
061    this.type = type;
062  }
063
064  @NotNull
065  @Size(min = 1)
066  public String getContent() {
067    return content;
068  }
069
070  public void setContent(String content) {
071    this.content = content;
072  }
073
074  @NotNull
075  @Size(min = 3)
076  public String getCreatedBy() {
077    return createdBy;
078  }
079
080  public void setCreatedBy(String createdBy) {
081    this.createdBy = createdBy;
082  }
083
084  @NotNull
085  @Size(min = 3)
086  public String getModifiedBy() {
087    return modifiedBy;
088  }
089
090  public void setModifiedBy(String modifiedBy) {
091    this.modifiedBy = modifiedBy;
092  }
093
094  @NotNull
095  public Date getCreated() {
096    return created;
097  }
098
099  public void setCreated(Date created) {
100    this.created = created;
101  }
102
103  @NotNull
104  public Date getModified() {
105    return modified;
106  }
107
108  public void setModified(Date modified) {
109    this.modified = modified;
110  }
111
112  @Override
113  public int hashCode() {
114    return Objects.hashCode(key, datasetKey, type, content, createdBy, modifiedBy, created, modified);
115  }
116
117  @Override
118  public boolean equals(Object object) {
119    if (object instanceof Metadata) {
120      Metadata that = (Metadata) object;
121      return Objects.equal(this.key, that.key)
122        && Objects.equal(this.datasetKey, that.datasetKey)
123        && Objects.equal(this.type, that.type)
124        && Objects.equal(this.content, that.content)
125        && Objects.equal(this.createdBy, that.createdBy)
126        && Objects.equal(this.modifiedBy, that.modifiedBy)
127        && Objects.equal(this.created, that.created)
128        && Objects.equal(this.modified, that.modified);
129    }
130    return false;
131  }
132
133  @Override
134  public String toString() {
135    return Objects.toStringHelper(this)
136      .add("key", key)
137      .add("datasetKey", datasetKey)
138      .add("type", type)
139      .add("content", content)
140      .add("createdBy", createdBy)
141      .add("modifiedBy", modifiedBy)
142      .add("created", created)
143      .add("modified", modified)
144      .toString();
145  }
146
147  /**
148   * Does not include the key or server controlled values (created, createdBy etc).
149   */
150  @Override
151  public boolean lenientEquals(Metadata other) {
152    if (this == other) {
153      return true;
154    }
155    return Objects.equal(this.datasetKey, other.datasetKey)
156      && Objects.equal(this.type, other.type)
157      && Objects.equal(this.content, other.content);
158  }
159}