001/*
002 * Copyright 2020 Global Biodiversity Information Facility (GBIF)
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016package org.gbif.api.model.collections.suggestions;
017
018import io.swagger.v3.oas.annotations.media.Schema;
019
020import org.gbif.api.model.collections.CollectionEntity;
021import org.gbif.api.model.registry.PrePersist;
022import org.gbif.api.util.validators.email.ValidEmail;
023import org.gbif.api.vocabulary.Country;
024
025import java.util.ArrayList;
026import java.util.Date;
027import java.util.List;
028import java.util.Objects;
029import java.util.UUID;
030
031import javax.validation.Valid;
032import javax.validation.constraints.NotNull;
033
034public abstract class BaseChangeSuggestion<T extends CollectionEntity>
035    implements ChangeSuggestion<T> {
036
037  @Schema(
038    description = "Identifier for the change suggestion.",
039    accessMode = Schema.AccessMode.READ_ONLY
040  )
041  private Integer key;
042
043  @NotNull private Type type;
044  private Status status;
045  private UUID entityKey;
046  private String entityName;
047  private Country entityCountry;
048  @Valid private T suggestedEntity;
049  private Date proposed;
050  private String proposedBy;
051
052  @NotNull(groups = PrePersist.class)
053  @ValidEmail
054  private String proposerEmail;
055
056  private Date applied;
057  private String appliedBy;
058  private Date discarded;
059  private String discardedBy;
060  private List<String> comments = new ArrayList<>();
061  private UUID mergeTargetKey;
062  private List<Change> changes = new ArrayList<>();
063  private Date modified;
064  private String modifiedBy;
065
066  @Override
067  public Integer getKey() {
068    return key;
069  }
070
071  @Override
072  public void setKey(Integer key) {
073    this.key = key;
074  }
075
076  @Override
077  public Type getType() {
078    return type;
079  }
080
081  @Override
082  public void setType(Type type) {
083    this.type = type;
084  }
085
086  @Override
087  public Status getStatus() {
088    return status;
089  }
090
091  @Override
092  public void setStatus(Status status) {
093    this.status = status;
094  }
095
096  @Override
097  public UUID getEntityKey() {
098    return entityKey;
099  }
100
101  @Override
102  public void setEntityKey(UUID entityKey) {
103    this.entityKey = entityKey;
104  }
105
106  @Override
107  public String getEntityName() {
108    return entityName;
109  }
110
111  @Override
112  public void setEntityName(String entityName) {
113    this.entityName = entityName;
114  }
115
116  @Override
117  public Country getEntityCountry() {
118    return entityCountry;
119  }
120
121  @Override
122  public void setEntityCountry(Country entityCountry) {
123    this.entityCountry = entityCountry;
124  }
125
126  @Override
127  public T getSuggestedEntity() {
128    return suggestedEntity;
129  }
130
131  @Override
132  public void setSuggestedEntity(T suggestedEntity) {
133    this.suggestedEntity = suggestedEntity;
134  }
135
136  @Override
137  public Date getProposed() {
138    return proposed;
139  }
140
141  @Override
142  public void setProposed(Date proposed) {
143    this.proposed = proposed;
144  }
145
146  @Override
147  public String getProposedBy() {
148    return proposedBy;
149  }
150
151  @Override
152  public void setProposedBy(String proposedBy) {
153    this.proposedBy = proposedBy;
154  }
155
156  @Override
157  public String getProposerEmail() {
158    return proposerEmail;
159  }
160
161  @Override
162  public void setProposerEmail(String proposerEmail) {
163    this.proposerEmail = proposerEmail;
164  }
165
166  @Override
167  public Date getApplied() {
168    return applied;
169  }
170
171  @Override
172  public void setApplied(Date applied) {
173    this.applied = applied;
174  }
175
176  @Override
177  public String getAppliedBy() {
178    return appliedBy;
179  }
180
181  @Override
182  public void setAppliedBy(String appliedBy) {
183    this.appliedBy = appliedBy;
184  }
185
186  @Override
187  public Date getDiscarded() {
188    return discarded;
189  }
190
191  @Override
192  public void setDiscarded(Date discarded) {
193    this.discarded = discarded;
194  }
195
196  @Override
197  public String getDiscardedBy() {
198    return discardedBy;
199  }
200
201  @Override
202  public void setDiscardedBy(String discardedBy) {
203    this.discardedBy = discardedBy;
204  }
205
206  @Override
207  public List<String> getComments() {
208    return comments;
209  }
210
211  @Override
212  public void setComments(List<String> comments) {
213    this.comments = comments;
214  }
215
216  @Override
217  public UUID getMergeTargetKey() {
218    return mergeTargetKey;
219  }
220
221  @Override
222  public void setMergeTargetKey(UUID mergeTargetKey) {
223    this.mergeTargetKey = mergeTargetKey;
224  }
225
226  @Override
227  public List<Change> getChanges() {
228    return changes;
229  }
230
231  @Override
232  public void setChanges(List<Change> changes) {
233    this.changes = changes;
234  }
235
236  @Override
237  public Date getModified() {
238    return modified;
239  }
240
241  @Override
242  public void setModified(Date modified) {
243    this.modified = modified;
244  }
245
246  @Override
247  public String getModifiedBy() {
248    return modifiedBy;
249  }
250
251  @Override
252  public void setModifiedBy(String modifiedBy) {
253    this.modifiedBy = modifiedBy;
254  }
255
256  @Override
257  public boolean equals(Object o) {
258    if (this == o) {
259      return true;
260    }
261    if (o == null || getClass() != o.getClass()) {
262      return false;
263    }
264    BaseChangeSuggestion<?> that = (BaseChangeSuggestion<?>) o;
265    return Objects.equals(key, that.key)
266        && type == that.type
267        && status == that.status
268        && Objects.equals(entityKey, that.entityKey)
269        && Objects.equals(entityName, that.entityName)
270        && entityCountry == that.entityCountry
271        && Objects.equals(suggestedEntity, that.suggestedEntity)
272        && Objects.equals(proposed, that.proposed)
273        && Objects.equals(proposedBy, that.proposedBy)
274        && Objects.equals(proposerEmail, that.proposerEmail)
275        && Objects.equals(applied, that.applied)
276        && Objects.equals(appliedBy, that.appliedBy)
277        && Objects.equals(discarded, that.discarded)
278        && Objects.equals(discardedBy, that.discardedBy)
279        && Objects.equals(comments, that.comments)
280        && Objects.equals(mergeTargetKey, that.mergeTargetKey)
281        && Objects.equals(changes, that.changes)
282        && Objects.equals(modified, that.modified)
283        && Objects.equals(modifiedBy, that.modifiedBy);
284  }
285
286  @Override
287  public int hashCode() {
288    return Objects.hash(
289        key,
290        type,
291        status,
292        entityKey,
293        entityName,
294        entityCountry,
295        suggestedEntity,
296        proposed,
297        proposedBy,
298        proposerEmail,
299        applied,
300        appliedBy,
301        discarded,
302        discardedBy,
303        comments,
304        mergeTargetKey,
305        changes,
306        modified,
307        modifiedBy);
308  }
309
310  @Override
311  public String toString() {
312    return "BaseChangeSuggestion{" +
313      "key=" + key +
314      ", type=" + type +
315      ", status=" + status +
316      ", entityKey=" + entityKey +
317      ", entityName='" + entityName + '\'' +
318      ", entityCountry=" + entityCountry +
319      ", suggestedEntity=" + suggestedEntity +
320      ", proposed=" + proposed +
321      ", proposedBy='" + proposedBy + '\'' +
322      ", proposerEmail='" + proposerEmail + '\'' +
323      ", applied=" + applied +
324      ", appliedBy='" + appliedBy + '\'' +
325      ", discarded=" + discarded +
326      ", discardedBy='" + discardedBy + '\'' +
327      ", comments=" + comments +
328      ", mergeTargetKey=" + mergeTargetKey +
329      ", changes=" + changes +
330      ", modified=" + modified +
331      ", modifiedBy='" + modifiedBy + '\'' +
332      '}';
333  }
334}