From a16c3fb5f7f0bbe7bda9e4f21f71a3e958ed523f Mon Sep 17 00:00:00 2001 From: "Rishi.Chail" Date: Wed, 6 Jan 2021 13:09:34 +0000 Subject: Retrieve the SchemaSet resources for an Anchor Issue-ID: CPS-135 Signed-off-by: Rishi.Chail Change-Id: Ib7c17c5180212c7dd3b96cf27797c84166041cf9 --- .../onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java | 10 +++++++++- .../onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java | 12 ++++++++++++ .../java/org/onap/cps/spi/repository/AnchorRepository.java | 9 ++++++++- 3 files changed, 29 insertions(+), 2 deletions(-) mode change 100644 => 100755 cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java mode change 100644 => 100755 cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java mode change 100644 => 100755 cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java (limited to 'cps-ri/src/main/java/org/onap') diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java old mode 100644 new mode 100755 index dfe3ecc119..ddbfeb2283 --- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java @@ -82,6 +82,14 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic return anchorEntities.stream().map(CpsAdminPersistenceServiceImpl::toAnchor).collect(Collectors.toList()); } + @Override + public Anchor getAnchor(final String dataspaceName, final String anchorName) { + final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName); + final AnchorEntity anchorEntity = + anchorRepository.getByDataspaceAndName(dataspaceEntity, anchorName); + return toAnchor(anchorEntity); + } + private static Anchor toAnchor(final AnchorEntity anchorEntity) { return Anchor.builder() .name(anchorEntity.getName()) @@ -89,4 +97,4 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic .schemaSetName(anchorEntity.getSchemaSet().getName()) .build(); } -} +} \ No newline at end of file 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 old mode 100644 new mode 100755 index cbc945da60..0a870bac14 --- 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 @@ -28,11 +28,13 @@ import java.util.Map; import java.util.Set; import java.util.stream.Collectors; import javax.transaction.Transactional; +import org.onap.cps.spi.CpsAdminPersistenceService; import org.onap.cps.spi.CpsModulePersistenceService; import org.onap.cps.spi.entities.DataspaceEntity; import org.onap.cps.spi.entities.SchemaSetEntity; import org.onap.cps.spi.entities.YangResourceEntity; import org.onap.cps.spi.exceptions.SchemaSetAlreadyDefinedException; +import org.onap.cps.spi.model.Anchor; import org.onap.cps.spi.repository.DataspaceRepository; import org.onap.cps.spi.repository.SchemaSetRepository; import org.onap.cps.spi.repository.YangResourceRepository; @@ -53,6 +55,9 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ @Autowired private DataspaceRepository dataspaceRepository; + @Autowired + private CpsAdminPersistenceService cpsAdminPersistenceService; + @Override @Transactional public void storeSchemaSet(final String dataspaceName, final String schemaSetName, @@ -109,4 +114,11 @@ public class CpsModulePersistenceServiceImpl implements CpsModulePersistenceServ return schemaSetEntity.getYangResources().stream().collect( Collectors.toMap(YangResourceEntity::getName, YangResourceEntity::getContent)); } + + @Override + public Map getYangSchemaSetResources(final String dataspaceName, + final String anchorName) { + final Anchor anchor = cpsAdminPersistenceService.getAnchor(dataspaceName, anchorName); + return getYangSchemaResources(dataspaceName, anchor.getSchemaSetName()); + } } diff --git a/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java b/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java old mode 100644 new mode 100755 index 318b4daa6b..cc9c2e09c7 --- a/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java +++ b/cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java @@ -24,11 +24,18 @@ import java.util.Optional; import javax.validation.constraints.NotNull; import org.onap.cps.spi.entities.AnchorEntity; import org.onap.cps.spi.entities.DataspaceEntity; +import org.onap.cps.spi.exceptions.AnchorNotFoundException; import org.springframework.data.jpa.repository.JpaRepository; public interface AnchorRepository extends JpaRepository { Optional findByDataspaceAndName(@NotNull DataspaceEntity dataspaceEntity, @NotNull String name); + default AnchorEntity getByDataspaceAndName(@NotNull DataspaceEntity dataspace, + @NotNull String anchorName) { + return findByDataspaceAndName(dataspace, anchorName) + .orElseThrow(() -> new AnchorNotFoundException(anchorName, dataspace.getName())); + } + Collection findAllByDataspace(@NotNull DataspaceEntity dataspaceEntity); -} +} \ No newline at end of file -- cgit 1.2.3-korg