aboutsummaryrefslogtreecommitdiffstats
path: root/cps-ri/src/main/java
diff options
context:
space:
mode:
authorRishi.Chail <rishi.chail@est.tech>2021-01-06 13:09:34 +0000
committerRishi.Chail <rishi.chail@est.tech>2021-01-15 14:32:35 +0000
commita16c3fb5f7f0bbe7bda9e4f21f71a3e958ed523f (patch)
treeb1e700f5c9915a38fc85af82df799072f3dd7035 /cps-ri/src/main/java
parent4118d94f71a4e5f5a4aef038f51c66fd2c1b8b60 (diff)
Retrieve the SchemaSet resources for an Anchor
Issue-ID: CPS-135 Signed-off-by: Rishi.Chail <rishi.chail@est.tech> Change-Id: Ib7c17c5180212c7dd3b96cf27797c84166041cf9
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.java10
-rwxr-xr-x[-rw-r--r--]cps-ri/src/main/java/org/onap/cps/spi/impl/CpsModulePersistenceServiceImpl.java12
-rwxr-xr-x[-rw-r--r--]cps-ri/src/main/java/org/onap/cps/spi/repository/AnchorRepository.java9
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