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.CollectionEntity;
017import org.gbif.api.model.collections.Institution;
018import org.gbif.api.model.collections.latimercore.OrganisationalUnit;
019import org.gbif.api.model.collections.request.InstitutionSearchRequest;
020import org.gbif.api.model.common.paging.PagingResponse;
021import org.gbif.api.model.registry.search.collections.KeyCodeNameResult;
022
023import java.util.List;
024import java.util.UUID;
025
026import javax.annotation.Nullable;
027import javax.validation.Valid;
028import javax.validation.constraints.NotNull;
029
030import org.geojson.FeatureCollection;
031
032/** Service for institutions in the collections context. */
033public interface InstitutionService extends CollectionEntityService<Institution> {
034
035  /**
036   * Pages {@link Institution} 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 InstitutionSearchRequest} with all the parameters
043   * @return a list of entities ordered by their creation date, newest coming first
044   */
045  PagingResponse<Institution> list(InstitutionSearchRequest searchRequest);
046
047  /**
048   * Similar to the {@link #list(InstitutionSearchRequest)} method but returns the results in
049   * Latimer Core format.
050   */
051  PagingResponse<OrganisationalUnit> listAsLatimerCore(InstitutionSearchRequest searchRequest);
052
053  /** Similar to the {@link #get(UUID)} method but returns the results in Latimer Core format. */
054  OrganisationalUnit getAsLatimerCore(@NotNull UUID key);
055
056  /** Similar to {@link #create(CollectionEntity)} but it accepts Latimer Core. */
057  UUID createFromLatimerCore(@NotNull @Valid OrganisationalUnit organisationalUnit);
058
059  /** Similar to {@link #update(CollectionEntity)})} but it accepts Latimer Core. */
060  void updateFromLatimerCore(@NotNull @Valid OrganisationalUnit entity);
061
062  /** Provides access to deleted institutions. */
063  PagingResponse<Institution> listDeleted(InstitutionSearchRequest searchRequest);
064
065  /** Provides a simple suggest service. */
066  List<KeyCodeNameResult> suggest(@Nullable String q);
067
068  /** Converts an institution into a collection. The institution converted is deleted. */
069  void convertToCollection(UUID targetEntityKey, UUID collectionKey);
070
071  /**
072   * Creates a {@link Institution} from a {@link org.gbif.api.model.registry.Organization}.
073   *
074   * @param organizationKey key of the dataset to create the institution from
075   * @param institutionCode the code to assign to the institution since it can't be inferred from
076   *     the organization
077   * @return UUID of the created institution
078   */
079  UUID createFromOrganization(UUID organizationKey, String institutionCode);
080
081  /**
082   * Lists the institutions in GeoJson format.
083   *
084   * @param searchRequest parameters to filter the request
085   * @return a {@link FeatureCollection} object that conforms with GeoJson
086   */
087  FeatureCollection listGeojson(InstitutionSearchRequest searchRequest);
088}