diff options
Diffstat (limited to 'cps-ri/src/main/java')
-rwxr-xr-x | cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java | 15 | ||||
-rw-r--r-- | cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java | 22 |
2 files changed, 37 insertions, 0 deletions
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java index 8008e0324a..03f021e76d 100755 --- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java @@ -3,6 +3,7 @@ * Copyright (C) 2020-2022 Nordix Foundation * Modifications Copyright (C) 2020-2022 Bell Canada. * Modifications Copyright (C) 2021 Pantheon.tech + * Modifications Copyright (C) 2022 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -55,6 +56,7 @@ import org.onap.cps.spi.exceptions.DuplicatedYangResourceException; import org.onap.cps.spi.exceptions.ModelValidationException; import org.onap.cps.spi.model.ModuleDefinition; import org.onap.cps.spi.model.ModuleReference; +import org.onap.cps.spi.model.SchemaSet; import org.onap.cps.spi.repository.DataspaceRepository; import org.onap.cps.spi.repository.ModuleReferenceRepository; import org.onap.cps.spi.repository.SchemaSetRepository; @@ -155,6 +157,14 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ } @Override + public Collection<SchemaSet> getSchemaSetsByDataspaceName(final String dataspaceName) { + final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName); + final List<SchemaSetEntity> schemaSetEntities = schemaSetRepository.getByDataspace(dataspaceEntity); + return schemaSetEntities.stream() + .map(CpsModulePersistenceServiceImpl::toSchemaSet).collect(Collectors.toList()); + } + + @Override @Transactional // A retry is made to store the schema set if it fails because of duplicated yang resource exception that // can occur in case of specific concurrent requests. @@ -364,4 +374,9 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ yangResourceEntity.getRevision(), yangResourceEntity.getContent()); } + + private static SchemaSet toSchemaSet(final SchemaSetEntity schemaSetEntity) { + return SchemaSet.builder().name(schemaSetEntity.getName()) + .dataspaceName(schemaSetEntity.getDataspace().getName()).build(); + } } diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java index a15ce622c2..8cecb0a8e3 100644 --- a/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/SchemaSetRepository.java @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2020 Pantheon.tech + * Modifications Copyright (C) 2022 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +20,10 @@ package org.onap.cps.spi.repository; +import java.util.Collection; +import java.util.List; import java.util.Optional; +import java.util.stream.Collectors; import javax.validation.constraints.NotNull; import org.onap.cps.spi.entities.DataspaceEntity; import org.onap.cps.spi.entities.SchemaSetEntity; @@ -33,6 +37,13 @@ public interface SchemaSetRepository extends JpaRepository<SchemaSetEntity, Inte Optional<SchemaSetEntity> findByDataspaceAndName(@NotNull DataspaceEntity dataspaceEntity, @NotNull String schemaSetName); + /** + * Gets schema sets by dataspace. + * @param dataspaceEntity dataspace entity + * @return list of schema set entity + */ + Collection<SchemaSetEntity> findByDataspace(@NotNull DataspaceEntity dataspaceEntity); + Integer countByDataspace(@NotNull DataspaceEntity dataspaceEntity); /** @@ -48,4 +59,15 @@ public interface SchemaSetRepository extends JpaRepository<SchemaSetEntity, Inte return findByDataspaceAndName(dataspaceEntity, schemaSetName) .orElseThrow(() -> new SchemaSetNotFoundException(dataspaceEntity.getName(), schemaSetName)); } + + /** + * Gets all schema sets for a given dataspace. + * + * @param dataspaceEntity dataspace entity + * @return list of schema set entity + * @throws SchemaSetNotFoundException if SchemaSet not found + */ + default List<SchemaSetEntity> getByDataspace(@NotNull final DataspaceEntity dataspaceEntity) { + return findByDataspace(dataspaceEntity).stream().collect(Collectors.toList()); + } } |