2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Pantheon.tech
4 * Modifications Copyright (C) 2022 TechMahindra Ltd.
5 * Modifications Copyright (C) 2023 Nordix Foundation
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * SPDX-License-Identifier: Apache-2.0
19 * ============LICENSE_END=========================================================
22 package org.onap.cps.spi.repository;
24 import java.util.Collection;
25 import java.util.List;
26 import java.util.Optional;
27 import java.util.stream.Collectors;
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.data.jpa.repository.Modifying;
33 import org.springframework.data.jpa.repository.Query;
34 import org.springframework.data.repository.query.Param;
35 import org.springframework.stereotype.Repository;
38 public interface SchemaSetRepository extends JpaRepository<SchemaSetEntity, Integer> {
40 Optional<SchemaSetEntity> findByDataspaceAndName(DataspaceEntity dataspaceEntity, String schemaSetName);
43 * Gets schema sets by dataspace.
44 * @param dataspaceEntity dataspace entity
45 * @return list of schema set entity
47 Collection<SchemaSetEntity> findByDataspace(DataspaceEntity dataspaceEntity);
49 Integer countByDataspace(DataspaceEntity dataspaceEntity);
52 * Gets a schema set by dataspace and schema set name.
54 * @param dataspaceEntity dataspace entity
55 * @param schemaSetName schema set name
56 * @return schema set entity
57 * @throws SchemaSetNotFoundException if SchemaSet not found
59 default SchemaSetEntity getByDataspaceAndName(final DataspaceEntity dataspaceEntity, final String schemaSetName) {
60 return findByDataspaceAndName(dataspaceEntity, schemaSetName)
61 .orElseThrow(() -> new SchemaSetNotFoundException(dataspaceEntity.getName(), schemaSetName));
65 * Gets all schema sets for a given dataspace.
67 * @param dataspaceEntity dataspace entity
68 * @return list of schema set entity
69 * @throws SchemaSetNotFoundException if SchemaSet not found
71 default List<SchemaSetEntity> getByDataspace(final DataspaceEntity dataspaceEntity) {
72 return findByDataspace(dataspaceEntity).stream().collect(Collectors.toList());
76 * Delete multiple schema sets in a given dataspace.
77 * @param dataspaceEntity dataspace entity
78 * @param schemaSetNames schema set names
81 @Query("DELETE FROM SchemaSetEntity s WHERE s.dataspace = :dataspaceEntity AND s.name IN (:schemaSetNames)")
82 void deleteByDataspaceAndNameIn(@Param("dataspaceEntity") DataspaceEntity dataspaceEntity,
83 @Param("schemaSetNames") Collection<String> schemaSetNames);