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.util.iterables;
017
018import org.gbif.api.model.common.paging.Pageable;
019import org.gbif.api.model.common.paging.PagingRequest;
020import org.gbif.api.model.common.paging.PagingResponse;
021import org.gbif.api.model.occurrence.DownloadStatistics;
022import org.gbif.api.service.registry.OccurrenceDownloadService;
023import org.gbif.api.vocabulary.Country;
024
025import java.util.Date;
026import java.util.UUID;
027
028import javax.annotation.Nullable;
029
030/**
031 * Iterates over results of {@link OccurrenceDownloadService#getDownloadStatistics(Date, Date, Country, UUID, UUID, Pageable)}.
032 */
033public class DownloadStatisticPager extends BasePager<DownloadStatistics> {
034
035    private final OccurrenceDownloadService service;
036    private final Date fromDate;
037    private final Date toDate;
038    private final Country publishingCountry;
039    private final UUID datasetKey;
040    private final UUID publishingOrgKey;
041
042    public DownloadStatisticPager(OccurrenceDownloadService service,
043                                  @Nullable Date fromDate,
044                                  @Nullable Date toDate,
045                                  @Nullable Country publishingCountry,
046                                  @Nullable UUID datasetKey,
047                                  @Nullable UUID publishingOrgKey,
048                                  int pageSize) {
049        super(pageSize);
050        this.service = service;
051        this.fromDate = fromDate;
052        this.toDate = toDate;
053        this.publishingCountry = publishingCountry;
054        this.datasetKey = datasetKey;
055        this.publishingOrgKey = publishingOrgKey;
056
057    }
058
059    @Override
060    public PagingResponse<DownloadStatistics> nextPage(PagingRequest page) {
061        return service.getDownloadStatistics(fromDate, toDate, publishingCountry, datasetKey, publishingOrgKey, page);
062    }
063
064}