2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Pantheon.tech
4 * Modifications Copyright (C) 2022 TechMahindra Ltd.
5 * ================================================================================
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.spi.repository;
23 import java.util.Collection;
24 import java.util.List;
25 import java.util.Optional;
26 import java.util.stream.Collectors;
27 import javax.validation.constraints.NotNull;
28 import org.onap.cps.spi.entities.DataspaceEntity;
29 import org.onap.cps.spi.entities.SchemaSetEntity;
30 import org.onap.cps.spi.exceptions.SchemaSetNotFoundException;
31 import org.springframework.data.jpa.repository.JpaRepository;
32 import org.springframework.stereotype.Repository;
35 public interface SchemaSetRepository extends JpaRepository<SchemaSetEntity, Integer> {
37 Optional<SchemaSetEntity> findByDataspaceAndName(@NotNull DataspaceEntity dataspaceEntity,
38 @NotNull String schemaSetName);
41 * Gets schema sets by dataspace.
42 * @param dataspaceEntity dataspace entity
43 * @return list of schema set entity
45 Collection<SchemaSetEntity> findByDataspace(@NotNull DataspaceEntity dataspaceEntity);
47 Integer countByDataspace(@NotNull DataspaceEntity dataspaceEntity);
50 * Gets a schema set by dataspace and schema set name.
52 * @param dataspaceEntity dataspace entity
53 * @param schemaSetName schema set name
54 * @return schema set entity
55 * @throws SchemaSetNotFoundException if SchemaSet not found
57 default SchemaSetEntity getByDataspaceAndName(@NotNull final DataspaceEntity dataspaceEntity,
58 @NotNull final String schemaSetName) {
59 return findByDataspaceAndName(dataspaceEntity, schemaSetName)
60 .orElseThrow(() -> new SchemaSetNotFoundException(dataspaceEntity.getName(), schemaSetName));
64 * Gets all schema sets for a given dataspace.
66 * @param dataspaceEntity dataspace entity
67 * @return list of schema set entity
68 * @throws SchemaSetNotFoundException if SchemaSet not found
70 default List<SchemaSetEntity> getByDataspace(@NotNull final DataspaceEntity dataspaceEntity) {
71 return findByDataspace(dataspaceEntity).stream().collect(Collectors.toList());