diff options
Diffstat (limited to 'cps-service/src/main')
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java | 10 | ||||
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetNotFoundException.java | 36 | ||||
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java | 6 | ||||
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java (renamed from cps-service/src/main/java/org/onap/cps/spi/model/ModuleRef.java) | 6 | ||||
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSet.java | 11 | ||||
-rw-r--r-- | cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java | 30 |
6 files changed, 93 insertions, 6 deletions
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 7feae367e8..df0f9f5a24 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java +++ b/cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java @@ -20,7 +20,9 @@ package org.onap.cps.spi; +import java.util.Collection; import java.util.Map; +import org.onap.cps.spi.model.ModuleReference; /** * Service to manage modules. @@ -52,4 +54,12 @@ public interface CpsModulePersistenceService { */ void storeSchemaSet(String dataspaceName, String schemaSetName, Map<String, String> yangResourcesNameToContentMap); + /** + * Returns Modules references per specific namespace / schemaSetName. + * + * @param namespace module namespace + * @param schemaSetName schema set name + * @return collection of ModuleRef + */ + Collection<ModuleReference> getModuleReferences(String namespace, String schemaSetName); } diff --git a/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetNotFoundException.java b/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetNotFoundException.java new file mode 100644 index 0000000000..f92ca37298 --- /dev/null +++ b/cps-service/src/main/java/org/onap/cps/spi/exceptions/SchemaSetNotFoundException.java @@ -0,0 +1,36 @@ +/* + * ============LICENSE_START======================================================= + * Copyright (C) 2020 Pantheon.tech + * ================================================================================ + * 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 SchemaSetNotFoundException extends CpsAdminException { + + private static final long serialVersionUID = 7422782395935450035L; + + /** + * Constructor. + * + * @param dataspaceName dataspace name + * @param schemaSetName schema set name + */ + public SchemaSetNotFoundException(final String dataspaceName, final String schemaSetName) { + super("Schema Set not found.", + String.format("Schema Set with name %s was not found for dataspace %s.", schemaSetName, dataspaceName)); + } +}
\ No newline at end of file diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java b/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java index 8bd4047007..f9eb22493c 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java +++ b/cps-service/src/main/java/org/onap/cps/spi/model/DataNode.java @@ -22,16 +22,20 @@ package org.onap.cps.spi.model; import java.util.Collection; import java.util.Map; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; @Data @Builder +@NoArgsConstructor +@AllArgsConstructor public class DataNode { private String dataspace; private String moduleSetName; - private ModuleRef moduleRef; + private ModuleReference moduleReference; private String xpath; private Map<String, Object> leaves; private Collection<String> xpathsChildren; diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/ModuleRef.java b/cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java index 1f4e64a949..5af355dcdb 100644 --- a/cps-service/src/main/java/org/onap/cps/spi/model/ModuleRef.java +++ b/cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java @@ -20,12 +20,16 @@ package org.onap.cps.spi.model; +import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; +import lombok.NoArgsConstructor; @Data @Builder -public class ModuleRef { +@NoArgsConstructor +@AllArgsConstructor +public class ModuleReference { private String namespace; private String revision; diff --git a/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSet.java b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSet.java index 5c337770dd..32ee324c54 100644 --- a/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSet.java +++ b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSet.java @@ -19,13 +19,24 @@ package org.onap.cps.yang; +import java.util.List; import org.checkerframework.checker.nullness.qual.NonNull; +import org.onap.cps.spi.model.ModuleReference; import org.opendaylight.yangtools.yang.model.api.SchemaContext; /** * CPS YangTextSchemaSource. */ public interface YangTextSchemaSourceSet { + + /** + * Returns list of modules references for given YangSchema. + * + * @return list of ModuleRef + */ + @NonNull + List<ModuleReference> getModuleReferences(); + /** * Return SchemaContext for given YangSchema. * @return SchemaContext diff --git a/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java index 1588c44d9c..89eea97f61 100644 --- a/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java +++ b/cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java @@ -27,8 +27,11 @@ import java.io.InputStream; import java.util.List; import java.util.Map; import java.util.stream.Collectors; +import org.onap.cps.spi.exceptions.CpsException; +import org.onap.cps.spi.model.ModuleReference; import org.opendaylight.yangtools.yang.common.Revision; import org.opendaylight.yangtools.yang.common.YangNames; +import org.opendaylight.yangtools.yang.model.api.Module; import org.opendaylight.yangtools.yang.model.api.SchemaContext; import org.opendaylight.yangtools.yang.model.parser.api.YangSyntaxErrorException; import org.opendaylight.yangtools.yang.model.repo.api.RevisionSourceIdentifier; @@ -55,13 +58,13 @@ public final class YangTextSchemaSourceSetBuilder { return this; } - public YangTextSchemaSourceSet build() throws ReactorException, IOException, YangSyntaxErrorException { + public YangTextSchemaSourceSet build() throws ReactorException, YangSyntaxErrorException { final SchemaContext schemaContext = generateSchemaContext(yangModelMap.build()); return new YangTextSchemaSourceSetImpl(schemaContext); } public static YangTextSchemaSourceSet of(final Map<String, String> yangResourceNameToContent) - throws ReactorException, IOException, YangSyntaxErrorException { + throws ReactorException, YangSyntaxErrorException { return new YangTextSchemaSourceSetBuilder().putAll(yangResourceNameToContent).build(); } @@ -74,6 +77,20 @@ public final class YangTextSchemaSourceSetBuilder { } @Override + public List<ModuleReference> getModuleReferences() { + return schemaContext.getModules().stream() + .map(YangTextSchemaSourceSetImpl::toModuleReference) + .collect(Collectors.toList()); + } + + private static ModuleReference toModuleReference(final Module module) { + return ModuleReference.builder() + .namespace(module.getName()) + .revision(module.getRevision().map(Revision::toString).orElse(null)) + .build(); + } + + @Override public SchemaContext getSchemaContext() { return schemaContext; } @@ -87,11 +104,16 @@ public final class YangTextSchemaSourceSetBuilder { * @return the schema context */ private SchemaContext generateSchemaContext(final Map<String, String> yangResourceNameToContent) - throws IOException, ReactorException, YangSyntaxErrorException { + throws ReactorException, YangSyntaxErrorException { final CrossSourceStatementReactor.BuildAction reactor = RFC7950Reactors.defaultReactor().newBuild(); final List<YangTextSchemaSource> yangTextSchemaSources = forResources(yangResourceNameToContent); for (final YangTextSchemaSource yangTextSchemaSource : yangTextSchemaSources) { - reactor.addSource(YangStatementStreamSource.create(yangTextSchemaSource)); + try { + reactor.addSource(YangStatementStreamSource.create(yangTextSchemaSource)); + } catch (final IOException e) { + throw new CpsException("Failed to read yangTextSchemaSource %s.", + yangTextSchemaSource.getIdentifier().getName(), e); + } } return reactor.buildEffective(); } |