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.collections; 017 018import org.gbif.api.model.collections.CollectionEntity; 019 020import java.util.UUID; 021 022import javax.validation.Valid; 023import javax.validation.constraints.NotNull; 024 025/** Base CRUD service for {@link CollectionEntity} entities. */ 026public interface CrudService<T extends CollectionEntity> { 027 028 /** 029 * Creates a new entity. 030 * 031 * @param entity to create 032 * @return UUID of the created entity. 033 */ 034 UUID create(@NotNull @Valid T entity); 035 036 /** 037 * Deletes an entity by key. 038 * 039 * @param key of the entity to be deleted. 040 */ 041 void delete(@NotNull UUID key); 042 043 /** 044 * Retrieves an entity by its key. 045 * 046 * @param key of the entity to be retrieved. 047 * @return the entity 048 */ 049 T get(@NotNull UUID key); 050 051 /** 052 * Updates an existing entity. 053 * 054 * @param entity that will replace the existing entity. 055 */ 056 void update(@NotNull @Valid T entity); 057 058 /** 059 * Checks if there is an entity with the key received. 060 * 061 * @param key of the entity to be retrieved. 062 * @return true if found, false otherwise 063 */ 064 boolean exists(@NotNull UUID key); 065}