diff options
Diffstat (limited to 'cps-ri/src/main/java')
-rwxr-xr-x[-rw-r--r--] | cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java | 10 | ||||
-rwxr-xr-x[-rw-r--r--] | cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java | 12 | ||||
-rwxr-xr-x[-rw-r--r--] | cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java | 9 |
3 files changed, 29 insertions, 2 deletions
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 index dfe3ecc119..ddbfeb2283 100644..100755 --- 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 index cbc945da60..0a870bac14 100644..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 @@ -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<String, String> 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 index 318b4daa6b..cc9c2e09c7 100644..100755 --- 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<AnchorEntity, Integer> { Optional<AnchorEntity> 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<AnchorEntity> findAllByDataspace(@NotNull DataspaceEntity dataspaceEntity); -} +}
\ No newline at end of file |