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/CpsAdminPersistenceService.java | 12 ++++++- .../onap/cps/spi/CpsModulePersistenceService.java | 22 ++++++++++--- .../spi/exceptions/AnchorNotFoundException.java | 38 ++++++++++++++++++++++ .../cps/api/impl/CpsAdminServiceImplSpec.groovy | 9 +++-- .../cps/spi/exceptions/CpsExceptionsSpec.groovy | 8 ++++- 5 files changed, 77 insertions(+), 12 deletions(-) mode change 100644 => 100755 cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java mode change 100644 => 100755 cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java create mode 100755 cps-service/src/main/java/org/onap/cps/spi/exceptions/AnchorNotFoundException.java mode change 100644 => 100755 cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy mode change 100644 => 100755 cps-service/src/test/groovy/org/onap/cps/spi/exceptions/CpsExceptionsSpec.groovy (limited to 'cps-service/src') 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 old mode 100644 new mode 100755 index 5643aedb72..06c04ceb62 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java @@ -57,4 +57,14 @@ public interface CpsAdminPersistenceService { */ @NonNull Collection getAnchors(@NonNull String dataspaceName); -} + + /** + * Get an anchor in the given dataspace using the anchor name. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @return an anchor + */ + @NonNull + Anchor getAnchor(@NonNull String dataspaceName, @NonNull String anchorName); +} \ No newline at end of file diff --git a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java old mode 100644 new mode 100755 index a82d69acbd..dc4e26b913 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java @@ -36,15 +36,27 @@ public interface CpsModulePersistenceService { * @param yangResourcesNameToContentMap YANG resources (files) map where key is a name and value is content */ void storeSchemaSet(@NonNull String dataspaceName, @NonNull String schemaSetName, - @NonNull Map yangResourcesNameToContentMap); + @NonNull Map yangResourcesNameToContentMap); /** - * Returns YANG resources per specific namespace / schemaSetName. + * Returns YANG resources per specific dataspace / schemaSetName. * - * @param namespace module namespace + * @param dataspaceName dataspace name * @param schemaSetName schema set name * @return YANG resources (files) map where key is a name and value is content */ @NonNull - Map getYangSchemaResources(@NonNull String namespace, @NonNull String schemaSetName); -} + Map getYangSchemaResources(@NonNull String dataspaceName, + @NonNull String schemaSetName); + + /** + * Returns YANG resources per specific dataspace / anchorName. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @return YANG resources (files) map where key is a name and value is content + */ + @NonNull + Map getYangSchemaSetResources(@NonNull String dataspaceName, + @NonNull String anchorName); +} \ No newline at end of file diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/AnchorNotFoundException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/AnchorNotFoundException.java new file mode 100755 index 0000000000..847959fc05 --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/AnchorNotFoundException.java @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * Copyright (C) 2021 Nordix Foundation. All rights reserved. + * ================================================================================ + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + * SPDX-License-Identifier: Apache-2.0 + * ============LICENSE_END========================================================= + */ + +package org.onap.cps.spi.exceptions; + +public class AnchorNotFoundException extends CpsAdminException { + + private static final long serialVersionUID = -1821064664642194882L; + + /** + * Constructor. + * + * @param anchorName the name of the anchor + * @param dataspaceName the dataspace name + */ + public AnchorNotFoundException(final String anchorName, final String dataspaceName) { + super("Anchor not found", + String.format("Anchor with name %s does not exist in dataspace %s.", anchorName, + dataspaceName)); + } +} \ No newline at end of file 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 old mode 100644 new mode 100755 index 022282493b..5aaa340271 --- 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 @@ -41,17 +41,16 @@ class CpsAdminServiceImplSpec extends Specification { def 'Create anchor method invokes persistence service'() { when: 'Create anchor method is invoked' - objectUnderTest.createAnchor('dummyDataspace', 'dummySchemaSet', 'dummyAnchorName') + objectUnderTest.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName') then: 'The persistence service method is invoked with same parameters' - 1 * mockCpsAdminPersistenceService.createAnchor('dummyDataspace', 'dummySchemaSet', 'dummyAnchorName') + 1 * mockCpsAdminPersistenceService.createAnchor('someDataspace', 'someSchemaSet', 'someAnchorName') } def 'Retrieve all anchors for dataspace'() { given: 'that anchor is associated with the dataspace' Collection anchorCollection = Arrays.asList(new Anchor()) - mockCpsAdminPersistenceService.getAnchors('dummyDataspace') >> { anchorCollection } + mockCpsAdminPersistenceService.getAnchors('someDataspace') >> { anchorCollection } expect: 'the collection provided by persistence service is returned as result' - objectUnderTest.getAnchors('dummyDataspace') == anchorCollection + objectUnderTest.getAnchors('someDataspace') == anchorCollection } - } diff --git a/cps-service/src/test/groovy/org/onap/cps/spi/exceptions/CpsExceptionsSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/spi/exceptions/CpsExceptionsSpec.groovy old mode 100644 new mode 100755 index 067556dd58..e00a640d47 --- a/cps-service/src/test/groovy/org/onap/cps/spi/exceptions/CpsExceptionsSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/spi/exceptions/CpsExceptionsSpec.groovy @@ -104,4 +104,10 @@ class CpsExceptionsSpec extends Specification { (new SchemaSetNotFoundException(dataspaceName,schemaSetName)).details == "Schema Set with name ${schemaSetName} was not found for dataspace ${dataspaceName}." } -} + + def 'Creating a exception that an anchor cannot be found.'() { + expect: 'the exception details contains the correct message with dataspace and anchor name' + (new AnchorNotFoundException(anchorName, dataspaceName)).details + == "Anchor with name ${anchorName} does not exist in dataspace ${dataspaceName}." + } +} \ No newline at end of file -- cgit 1.2.3-korg