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.service.collections;
015
016import org.gbif.api.model.collections.Collection;
017import org.gbif.api.model.collections.CollectionEntity;
018import org.gbif.api.model.collections.latimercore.ObjectGroup;
019import org.gbif.api.model.collections.latimercore.OrganisationalUnit;
020import org.gbif.api.model.collections.request.CollectionSearchRequest;
021import org.gbif.api.model.collections.view.CollectionView;
022import org.gbif.api.model.common.paging.PagingResponse;
023import org.gbif.api.model.registry.search.collections.KeyCodeNameResult;
024
025import java.util.List;
026import java.util.UUID;
027
028import javax.annotation.Nullable;
029import javax.validation.Valid;
030import javax.validation.constraints.NotNull;
031
032/** API Service to work with collections. */
033public interface CollectionService extends CollectionEntityService<Collection> {
034
035  /**
036   * Pages {@link Collection} entities based on the parameters received.
037   *
038   * <p>To iterate over <em>all</em> entities you can use code like this: {@code PagingRequest req =
039   * new PagingRequest(); PagingResponse<T> response; do { response = service.list(req); for (T obj
040   * : response.getResults()) { doStuff(); } req.nextPage(); } while (!response.isEndOfRecords()); }
041   *
042   * @param searchRequest {@link CollectionSearchRequest} with all the parameters
043   * @return a list of entities ordered by their creation date, newest coming first
044   */
045  PagingResponse<CollectionView> list(CollectionSearchRequest searchRequest);
046
047  /**
048   * Similar to the {@link #list(CollectionSearchRequest)} method but returns the results in Latimer
049   * Core format.
050   */
051  PagingResponse<ObjectGroup> listAsLatimerCore(CollectionSearchRequest searchRequest);
052
053  /** Provides access to deleted collections. */
054  PagingResponse<CollectionView> listDeleted(CollectionSearchRequest searchRequest);
055
056  /** Similar to {@link #get(UUID)} but it returns the result in Latimer Core format. */
057  ObjectGroup getAsLatimerCore(@NotNull UUID key);
058
059  /** Similar to {@link #create(CollectionEntity)} but it accepts Latimer Core. */
060  UUID createFromLatimerCore(@NotNull @Valid ObjectGroup objectGroup);
061
062  /** Similar to {@link #update(CollectionEntity)})} but it accepts Latimer Core. */
063  void updateFromLatimerCore(@NotNull @Valid ObjectGroup entity);
064
065  /** Retrieves a {@link CollectionView} by the collection key. */
066  CollectionView getCollectionView(@NotNull UUID key);
067
068  /** Provides a simple suggest service. */
069  List<KeyCodeNameResult> suggest(@Nullable String q);
070
071  /**
072   * Creates a {@link Collection} from a {@link org.gbif.api.model.registry.Dataset}.
073   *
074   * @param datasetKey key of the dataset to create the collection from
075   * @param collectionCode the code to assign to the collection since it can't be inferred from the
076   *     dataset
077   * @return UUID of the created collection
078   */
079  UUID createFromDataset(UUID datasetKey, String collectionCode);
080}