From e1f73e264e2dca1f10c273620653f541c2f25d69 Mon Sep 17 00:00:00 2001 From: emaclee Date: Fri, 17 Jun 2022 17:42:56 +0100 Subject: Add method to get YANG module sources for CM handle - part of this commit includes renaming the enum SyncState to DataStoreSyncState Issue-ID: CPS-1064 Signed-off-by: emaclee Change-Id: I6bf419141a1b33f09871946445cdfff422c8c354 --- .../java/org/onap/cps/api/CpsModuleService.java | 10 ++++++ .../onap/cps/api/impl/CpsModuleServiceImpl.java | 8 +++++ .../onap/cps/spi/CpsModulePersistenceService.java | 12 ++++++- .../org/onap/cps/spi/model/ModuleDefinition.java | 37 ++++++++++++++++++++++ .../cps/api/impl/CpsModuleServiceImplSpec.groovy | 8 ++++- 5 files changed, 73 insertions(+), 2 deletions(-) create mode 100644 cps-service/src/main/java/org/onap/cps/spi/model/ModuleDefinition.java (limited to 'cps-service/src') diff --git a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java index 79d6e03d4a..5e8eb9f6cf 100644 --- a/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java +++ b/cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java @@ -25,6 +25,7 @@ import java.util.Collection; import java.util.Map; import org.onap.cps.spi.CascadeDeleteAllowed; import org.onap.cps.spi.exceptions.DataInUseException; +import org.onap.cps.spi.model.ModuleDefinition; import org.onap.cps.spi.model.ModuleReference; import org.onap.cps.spi.model.SchemaSet; @@ -93,6 +94,15 @@ public interface CpsModuleService { */ Collection getYangResourcesModuleReferences(String dataspaceName, String anchorName); + /** + * Retrieve module definitions for the given dataspace name and anchor name. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @return a collection of module definitions (moduleName, revision, yang resource content) + */ + Collection getModuleDefinitionsByAnchorName(String dataspaceName, String anchorName); + /** * Identify previously unknown Yang Resource module references. * The system will ignore the namespace of all module references. diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java index db8a81f276..ff725a617f 100644 --- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java +++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java @@ -31,6 +31,7 @@ import org.onap.cps.spi.CascadeDeleteAllowed; import org.onap.cps.spi.CpsModulePersistenceService; import org.onap.cps.spi.exceptions.SchemaSetInUseException; import org.onap.cps.spi.model.Anchor; +import org.onap.cps.spi.model.ModuleDefinition; import org.onap.cps.spi.model.ModuleReference; import org.onap.cps.spi.model.SchemaSet; import org.onap.cps.utils.CpsValidator; @@ -105,6 +106,13 @@ public class CpsModuleServiceImpl implements CpsModuleService { return cpsModulePersistenceService.getYangResourceModuleReferences(dataspaceName, anchorName); } + @Override + public Collection getModuleDefinitionsByAnchorName(final String dataspaceName, + final String anchorName) { + CpsValidator.validateNameCharacters(dataspaceName, anchorName); + return cpsModulePersistenceService.getYangResourceDefinitions(dataspaceName, anchorName); + } + @Override public Collection identifyNewModuleReferences( final Collection moduleReferencesToCheck) { 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 index 0e90e84f1e..db2cb60f34 100755 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java @@ -23,6 +23,7 @@ package org.onap.cps.spi; import java.util.Collection; import java.util.Map; +import org.onap.cps.spi.model.ModuleDefinition; import org.onap.cps.spi.model.ModuleReference; /** @@ -89,10 +90,19 @@ public interface CpsModulePersistenceService { * * @param dataspaceName dataspace name * @param anchorName anchor name - * @return a collection of module names and revisions + * @return a collection of module reference (moduleName and revision) */ Collection getYangResourceModuleReferences(String dataspaceName, String anchorName); + /** + * Get YANG resource definitions for the given anchor name and dataspace name. + * + * @param dataspaceName dataspace name + * @param anchorName anchor name + * @return a collection of module definitions (moduleName, revision and yang resource content) + */ + Collection getYangResourceDefinitions(String dataspaceName, String anchorName); + /** * Remove unused Yang Resource Modules. */ diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/ModuleDefinition.java b/cps-service/src/main/java/org/onap/cps/spi/model/ModuleDefinition.java new file mode 100644 index 0000000000..d7a5b38dcc --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/model/ModuleDefinition.java @@ -0,0 +1,37 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2022 Nordix Foundation + * ================================================================================ + * 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.model; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class ModuleDefinition extends ModuleReference { + + private static final long serialVersionUID = -6591435720836327732L; + private final String content; + + public ModuleDefinition(final String moduleName, final String revision, final String content) { + super(moduleName, revision); + this.content = content; + } +} \ No newline at end of file diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy index 95d731478f..429de7d51b 100644 --- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy +++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsModuleServiceImplSpec.groovy @@ -24,7 +24,6 @@ package org.onap.cps.api.impl import org.onap.cps.TestUtils import org.onap.cps.api.CpsAdminService -import org.onap.cps.spi.CascadeDeleteAllowed import org.onap.cps.spi.CpsModulePersistenceService import org.onap.cps.spi.exceptions.DataValidationException import org.onap.cps.spi.exceptions.ModelValidationException @@ -243,4 +242,11 @@ class CpsModuleServiceImplSpec extends Specification { then: 'cps module persistence service is called with module references to check' 1 * mockCpsModulePersistenceService.identifyNewModuleReferences(moduleReferencesToCheck); } + + def 'Getting module definitions.'() { + when: 'get module definitions method is called with a valid dataspace and anchor name' + objectUnderTest.getModuleDefinitionsByAnchorName('some-dataspace-name', 'some-anchor-name') + then: 'CPS module persistence service is invoked the correct number of times' + 1 * mockCpsModulePersistenceService.getYangResourceDefinitions('some-dataspace-name', 'some-anchor-name') + } } -- cgit 1.2.3-korg