From b0d930752fd6be436061226c7395038f6828438e Mon Sep 17 00:00:00 2001 From: niamhcore Date: Thu, 28 Oct 2021 13:39:24 +0100 Subject: Add get cm handles by modules names - service layer Issue-ID: CPS-644 Signed-off-by: niamhcore Change-Id: Ic2a57df02d533a0066382c12c35be8d524b6cdad --- .../src/main/java/org/onap/cps/api/CpsAdminService.java | 11 +++++++++++ .../main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java | 7 +++++++ .../java/org/onap/cps/spi/CpsAdminPersistenceService.java | 8 +++++--- .../org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy | 8 ++++++++ 4 files changed, 31 insertions(+), 3 deletions(-) (limited to 'cps-service') diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java b/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java index 5b2e10428..1d08cde7b 100755 --- a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java @@ -77,4 +77,15 @@ public interface CpsAdminService { * @param anchorName anchor name */ void deleteAnchor(@NonNull String dataspaceName, @NonNull String anchorName); + + /** + * Query anchor names for the given module names in the provided dataspace. + * + * + * @param dataspaceName dataspace name + * @param moduleNames a collection of module names + * @return a collection of anchor names in the given dataspace. The schema set for each anchor must include all the + * given module names + */ + Collection queryAnchorNames(String dataspaceName, Collection moduleNames); } diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java index 47da64895..4640a0fb3 100755 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java @@ -23,6 +23,7 @@ package org.onap.cps.api.impl; import java.util.Collection; +import java.util.stream.Collectors; import org.onap.cps.api.CpsAdminService; import org.onap.cps.spi.CpsAdminPersistenceService; import org.onap.cps.spi.model.Anchor; @@ -59,4 +60,10 @@ public class CpsAdminServiceImpl implements CpsAdminService { public void deleteAnchor(final String dataspaceName, final String anchorName) { cpsAdminPersistenceService.deleteAnchor(dataspaceName, anchorName); } + + @Override + public Collection queryAnchorNames(final String dataspaceName, final Collection moduleNames) { + final Collection anchors = cpsAdminPersistenceService.queryAnchors(dataspaceName, moduleNames); + return anchors.stream().map(anchor -> anchor.getName()).collect(Collectors.toList()); + } } diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java index f29735fa0..104ac4f3f 100755 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java @@ -59,13 +59,15 @@ public interface CpsAdminPersistenceService { Collection getAnchors(@NonNull String dataspaceName); /** - * Get anchors for the given dataspace name and collection of module names. + * Query anchor names for the given module names in the provided dataspace. + * * * @param dataspaceName dataspace name * @param moduleNames a collection of module names - * @return a collection of anchors + * @return a collection of anchor names in the given dataspace. The schema set for each anchor must include all the + * given module names */ - Collection getAnchors(String dataspaceName, Collection moduleNames); + Collection queryAnchors(String dataspaceName, Collection moduleNames); /** * Get an anchor in the given dataspace using the anchor name. diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy index be213c0fa..95afeb417 100755 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy @@ -70,4 +70,12 @@ class CpsAdminServiceImplSpec extends Specification { then: 'associated persistence service method is invoked with same parameters' 1 * mockCpsAdminPersistenceService.deleteAnchor('someDataspace','someAnchor') } + + def 'Query all anchor identifiers for a dataspace and module names.'() { + given: 'the persistence service is invoked with the expected parameters and returns a list of anchors' + mockCpsAdminPersistenceService.queryAnchors('some-dataspace-name', ['some-module-name']) >> [new Anchor(name:'some-anchor-identifier')] + expect: 'get anchor identifiers returns the same anchor identifier returned by the persistence layer' + objectUnderTest.queryAnchorNames('some-dataspace-name', ['some-module-name']) == ['some-anchor-identifier'] + + } } -- cgit 1.2.3-korg