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.service.registry;
017
018import org.gbif.api.model.common.paging.Pageable;
019import org.gbif.api.model.common.paging.PagingResponse;
020import org.gbif.api.model.registry.Dataset;
021import org.gbif.api.model.registry.Grid;
022import org.gbif.api.model.registry.Metadata;
023import org.gbif.api.model.registry.Network;
024import org.gbif.api.model.registry.search.DatasetRequestSearchParams;
025import org.gbif.api.vocabulary.Country;
026import org.gbif.api.vocabulary.DatasetType;
027import org.gbif.api.vocabulary.MetadataType;
028
029import java.io.InputStream;
030import java.util.List;
031import java.util.UUID;
032
033import javax.annotation.Nullable;
034
035@SuppressWarnings("unused")
036public interface DatasetService extends NetworkEntityService<Dataset> {
037
038  /**
039   * Pages through constituents of a dataset, i.e. returns datasets which have a parentDatasetKey
040   * equals to the one requested.
041   *
042   * @param datasetKey the parent datasets key
043   */
044  PagingResponse<Dataset> listConstituents(UUID datasetKey, @Nullable Pageable page);
045
046  /**
047   * Pages through all constituent datasets, i.e. returns datasets which have a non null
048   * parentDatasetKey.
049   */
050  PagingResponse<Dataset> listConstituents(@Nullable Pageable page);
051
052  /**
053   * Provides paging service to list datasets published, i.e. owned by organizations from a given
054   * country.
055   *
056   * @param country the hosting country
057   * @param type the optional dataset type filter
058   * @return list of datasets ordered by creation date with latest coming first
059   */
060  PagingResponse<Dataset> listByCountry(
061      Country country, @Nullable DatasetType type, @Nullable Pageable page);
062
063  /**
064   * Provides paging service to list datasets published filtered by a particular dataset type.
065   *
066   * @param type the dataset type filter
067   * @return list of datasets ordered by creation date with latest coming first
068   */
069  PagingResponse<Dataset> listByType(DatasetType type, @Nullable Pageable page);
070
071  /**
072   * Lists all metadata descriptions available for a dataset and optionally filters them by document
073   * type. The list is sorted by priority with the first result ranking highest. Highest priority in
074   * this sense means most relevant for augmenting/updating a dataset with EML being the most
075   * relevant cause informative type.
076   *
077   * @return the list of metadata entries sorted by priority
078   */
079  List<Metadata> listMetadata(UUID datasetKey, @Nullable MetadataType type);
080
081  /**
082   * Lists all networks that this dataset is a constituent of.
083   *
084   * @param datasetKey the dataset in question
085   * @return list of networks that have this dataset as a constituent
086   */
087  List<Network> listNetworks(UUID datasetKey);
088
089  /** Get a metadata description by its key. */
090  Metadata getMetadata(int metadataKey);
091
092  /** Removes a metadata entry and its document by its key. */
093  void deleteMetadata(int metadataKey);
094
095  /**
096   * Inserts a metadata document, replacing any previously existing document of the same type.
097   * Updates dataset from metadata document, but only if metadata document does not exist already.
098   * The document type is discovered by the service and returned in the Metadata instance.
099   *
100   * @param datasetKey the dataset in question
101   * @param document metadata document to insert
102   * @throws IllegalArgumentException if document is not parsable
103   */
104  Metadata insertMetadata(UUID datasetKey, InputStream document);
105
106  /**
107   * Retrieves a GBIF generated EML document overlaying GBIF information with any existing metadata
108   * document data.
109   */
110  InputStream getMetadataDocument(UUID datasetKey);
111
112  /** Gets the actual metadata document content by its key. */
113  InputStream getMetadataDocument(int metadataKey);
114
115  /** Provides access to deleted datasets. */
116  PagingResponse<Dataset> listDeleted(DatasetRequestSearchParams searchParams);
117
118  /**
119   * Provides access to datasets that are marked as a duplicate of another. When 2 datasets are
120   * considered duplicates, one is marked as a duplicate of the other. Only the marked dataset is
121   * returned in this call.
122   */
123  PagingResponse<Dataset> listDuplicates(@Nullable Pageable page);
124
125  /**
126   * Provides access to internal (e.g. not marked as external) datasets, that are not sub datasets
127   * that have no endpoint.
128   */
129  PagingResponse<Dataset> listDatasetsWithNoEndpoint(@Nullable Pageable page);
130
131  /**
132   * Get a Dataset list from a DOI. GBIF assigned DOIs and alternate identifiers are returned.
133   * Multiple dataset could share the same DOI since this is not enforced.
134   */
135  PagingResponse<Dataset> listByDOI(String doi, @Nullable Pageable page);
136
137  /**
138   * Get gridded datasets processing info
139   *
140   * @param datasetKey the dataset in question
141   * @return List of grids
142   */
143  List<Grid> listGrids(UUID datasetKey);
144
145  /**
146   * Provides paging service to list datasets that can be filtered by multiple parameters.
147   *
148   * @param searchParams {@link DatasetRequestSearchParams}
149   * @return list of datasets ordered by creation date with the latest coming first
150   */
151  PagingResponse<Dataset> list(DatasetRequestSearchParams searchParams);
152}