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.registry.metasync;
017
018import org.gbif.api.model.registry.PostPersist;
019import org.gbif.api.model.registry.PrePersist;
020
021import java.util.Date;
022import java.util.Objects;
023import java.util.StringJoiner;
024import java.util.UUID;
025
026import javax.annotation.Nullable;
027import javax.validation.constraints.NotNull;
028import javax.validation.constraints.Null;
029
030/**
031 * Metadata synchronization historical information.
032 */
033public class MetasyncHistory {
034
035  private UUID installationKey;
036  private Date syncDate;
037  private MetasyncResult result;
038  private String details;
039
040  /**
041   * Key of the synchronized installation.
042   *
043   * @return the installation key that was synchronized
044   */
045  @NotNull
046  public UUID getInstallationKey() {
047    return installationKey;
048  }
049
050  public void setInstallationKey(UUID installationKey) {
051    this.installationKey = installationKey;
052  }
053
054  /**
055   * Date when the metasync operation was executed.
056   * <br>
057   * NB: null before the record is persisted, not-null afterwards.
058   *
059   * @return timestamp when the synchronization was executed
060   */
061  @Nullable
062  @Null(groups = {PrePersist.class})
063  @NotNull(groups = {PostPersist.class})
064  public Date getSyncDate() {
065    return syncDate;
066  }
067
068  public void setSyncDate(Date syncDate) {
069    this.syncDate = syncDate;
070  }
071
072  /**
073   * Result of the metasync operation.
074   *
075   * @return the result of the metasync operation
076   */
077  @Nullable
078  public MetasyncResult getResult() {
079    return result;
080  }
081
082  public void setResult(MetasyncResult result) {
083    this.result = result;
084  }
085
086  /**
087   * Details about the metasync operation.
088   *
089   * @return the metasync details
090   */
091  @Nullable
092  public String getDetails() {
093    return details;
094  }
095
096  public void setDetails(String details) {
097    this.details = details;
098  }
099
100  @Override
101  public boolean equals(Object o) {
102    if (this == o) {
103      return true;
104    }
105    if (o == null || getClass() != o.getClass()) {
106      return false;
107    }
108    MetasyncHistory that = (MetasyncHistory) o;
109    return Objects.equals(installationKey, that.installationKey) &&
110      Objects.equals(syncDate, that.syncDate) &&
111      result == that.result &&
112      Objects.equals(details, that.details);
113  }
114
115  @Override
116  public int hashCode() {
117    return Objects.hash(installationKey, syncDate, result, details);
118  }
119
120  @Override
121  public String toString() {
122    return new StringJoiner(", ", MetasyncHistory.class.getSimpleName() + "[", "]")
123      .add("installationKey=" + installationKey)
124      .add("syncDate=" + syncDate)
125      .add("result=" + result)
126      .add("details='" + details + "'")
127      .toString();
128  }
129}