001/*
002 * Licensed under the Apache License, Version 2.0 (the "License");
003 * you may not use this file except in compliance with the License.
004 * You may obtain a copy of the License at
005 *
006 *     http://www.apache.org/licenses/LICENSE-2.0
007 *
008 * Unless required by applicable law or agreed to in writing, software
009 * distributed under the License is distributed on an "AS IS" BASIS,
010 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
011 * See the License for the specific language governing permissions and
012 * limitations under the License.
013 */
014package org.gbif.api.model.occurrence;
015
016import java.time.LocalDate;
017import java.util.Objects;
018import java.util.StringJoiner;
019import java.util.UUID;
020
021import com.fasterxml.jackson.annotation.JsonIgnore;
022
023import io.swagger.v3.oas.annotations.media.Schema;
024
025/**
026 * Monthly dataset download statistics.
027 */
028public class DownloadStatistics {
029
030  @Schema(
031    description = "The GBIF dataset key for the dataset."
032  )
033  private UUID datasetKey;
034
035  @Schema(
036    description = "The total number of records in downloads from the given dataset.  Records present in multiple " +
037      "downloads will be counted more than once."
038  )
039  private Long totalRecords;
040
041  @Schema(
042    description = "The number of downloads including at least one record from the dataset."
043  )
044  private Long numberDownloads;
045
046  @Schema(
047    description = "The year and month."
048  )
049  private LocalDate yearMonth;
050
051  public DownloadStatistics(){
052
053  }
054
055  public DownloadStatistics(UUID datasetKey, Long totalRecords, Long numberDownloads, LocalDate yearMonth) {
056    this.datasetKey = datasetKey;
057    this.totalRecords = totalRecords;
058    this.numberDownloads = numberDownloads;
059    this.yearMonth = yearMonth;
060  }
061
062  public UUID getDatasetKey() {
063    return datasetKey;
064  }
065
066  public void setDatasetKey(UUID datasetKey) {
067    this.datasetKey = datasetKey;
068  }
069
070  public Long getTotalRecords() {
071    return totalRecords;
072  }
073
074  public void setTotalRecords(Long totalRecords) {
075    this.totalRecords = totalRecords;
076  }
077
078  public Long getNumberDownloads() {
079    return numberDownloads;
080  }
081
082  public void setNumberDownloads(Long numberDownloads) {
083    this.numberDownloads = numberDownloads;
084  }
085
086  /**
087   * Ignore in serialization, only year and month is relevant.
088   */
089  @JsonIgnore
090  public LocalDate getYearMonth() {
091    return yearMonth;
092  }
093
094  public void setYearMonth(LocalDate yearMonth) {
095    this.yearMonth = yearMonth;
096  }
097
098  public int getYear() {
099    return yearMonth.getYear();
100  }
101
102  public int getMonth() {
103    return yearMonth.getMonthValue();
104  }
105
106  @Override
107  public boolean equals(Object o) {
108    if (this == o) return true;
109    if (o == null || getClass() != o.getClass()) return false;
110    DownloadStatistics that = (DownloadStatistics) o;
111    return datasetKey.equals(that.datasetKey)
112           && totalRecords.equals(that.totalRecords)
113           && numberDownloads.equals(that.numberDownloads)
114           && yearMonth.equals(that.yearMonth);
115  }
116
117  @Override
118  public int hashCode() {
119    return Objects.hash(datasetKey, totalRecords, numberDownloads, yearMonth);
120  }
121
122  @Override
123  public String toString() {
124    return new StringJoiner(", ", DownloadStatistics.class.getSimpleName() + "[", "]")
125      .add("datasetKey=" + datasetKey)
126      .add("totalRecords=" + totalRecords)
127      .add("numberDownloads=" + numberDownloads)
128      .add("yearMonth=" + yearMonth)
129      .toString();
130  }
131}