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 java.util.Date;
016import javax.validation.constraints.NotNull;
017import javax.validation.constraints.Null;
018import javax.validation.constraints.Size;
019
020import com.google.common.base.Objects;
021
022public class Comment implements LenientEquals<Comment> {
023
024  private Integer key;
025  private String content;
026  private String createdBy;
027  private String modifiedBy;
028  private Date created;
029  private Date modified;
030
031  @Null(groups = {PrePersist.class})
032  @NotNull(groups = {PostPersist.class})
033  public Integer getKey() {
034    return key;
035  }
036
037  public void setKey(Integer key) {
038    this.key = key;
039  }
040
041  @NotNull
042  @Size(min = 1)
043  public String getContent() {
044    return content;
045  }
046
047  public void setContent(String content) {
048    this.content = content;
049  }
050
051  @Size(min = 3)
052  public String getCreatedBy() {
053    return createdBy;
054  }
055
056  public void setCreatedBy(String createdBy) {
057    this.createdBy = createdBy;
058  }
059
060  @Size(min = 3)
061  public String getModifiedBy() {
062    return modifiedBy;
063  }
064
065  public void setModifiedBy(String modifiedBy) {
066    this.modifiedBy = modifiedBy;
067  }
068
069  @Null(groups = {PrePersist.class})
070  @NotNull(groups = {PostPersist.class})
071  public Date getCreated() {
072    return created;
073  }
074
075  public void setCreated(Date created) {
076    this.created = created;
077  }
078
079  @Null(groups = {PrePersist.class})
080  @NotNull(groups = {PostPersist.class})
081  public Date getModified() {
082    return modified;
083  }
084
085  public void setModified(Date modified) {
086    this.modified = modified;
087  }
088
089  @Override
090  public int hashCode() {
091    return Objects.hashCode(key, content, createdBy, modifiedBy, created, modified);
092  }
093
094  @Override
095  public boolean equals(Object object) {
096    if (object instanceof Comment) {
097      Comment that = (Comment) object;
098      return Objects.equal(this.key, that.key)
099        && Objects.equal(this.content, that.content)
100        && Objects.equal(this.createdBy, that.createdBy)
101        && Objects.equal(this.modifiedBy, that.modifiedBy)
102        && Objects.equal(this.created, that.created)
103        && Objects.equal(this.modified, that.modified);
104    }
105    return false;
106  }
107
108  @Override
109  public String toString() {
110    return Objects.toStringHelper(this)
111      .add("key", key)
112      .add("content", content)
113      .add("createdBy", createdBy)
114      .add("modifiedBy", modifiedBy)
115      .add("created", created)
116      .add("modified", modified)
117      .toString();
118  }
119
120  /**
121   * A lenient equality check ignoring server side fields. If the objects are equal or have the same content, they are
122   * considered the same.
123   */
124  @Override
125  public boolean lenientEquals(Comment other) {
126    if (this == other) {
127      return true;
128    }
129    return Objects.equal(this.content, other.content);
130  }
131}