summaryrefslogtreecommitdiffstats
path: root/cps-service/src/main
diff options
context:
space:
mode:
authorClaudio David Gasparini <claudio.gasparini@pantheon.tech>2021-01-07 12:21:38 +0100
committerClaudio David Gasparini <claudio.gasparini@pantheon.tech>2021-01-11 10:01:27 +0100
commitfa56d71bb94d88f657a9d73fb91c3036220f32ab (patch)
tree163bd68ae4a77cdc4412a5354958090e7063f257 /cps-service/src/main
parent45b0d293c2d625c6d352d71a743f832c5e287c4e (diff)
Rework CpsModulePersistenceService
- remove getModuleReferences - provide service returning YangTextSchemaSourceSet Issue-ID: CPS-21 Signed-off-by: Claudio David Gasparini <claudio.gasparini@pantheon.tech> Change-Id: I61cf6450c8ed8a5154990ea19467e016dc1155b4
Diffstat (limited to 'cps-service/src/main')
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java2
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/CpsModuleService.java12
-rw-r--r--cps-service/src/main/java/org/onap/cps/api/impl/CpsModuleServiceImpl.java15
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java1
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/CpsModulePersistenceService.java13
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java1
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/model/SchemaSet.java39
-rw-r--r--cps-service/src/main/java/org/onap/cps/yang/YangTextSchemaSourceSetBuilder.java6
8 files changed, 72 insertions, 17 deletions
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 581550fb5c..853bd958f8 100644
--- a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java
@@ -50,7 +50,7 @@ public interface CpsAdminService {
void createAnchor(@NonNull String dataspaceName, @NonNull String schemaSetName, @NonNull String anchorName);
/**
- * Read all anchors in the given a dataspace.
+ * Read all anchors in the given dataspace.
*
* @param dataspaceName dataspace name
* @return a collection of anchors
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 e7b02fbad8..5f63f97f1e 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
@@ -21,8 +21,7 @@ package org.onap.cps.api;
import java.util.Map;
import org.checkerframework.checker.nullness.qual.NonNull;
-import org.onap.cps.spi.exceptions.CpsException;
-import org.opendaylight.yangtools.yang.model.api.SchemaContext;
+import org.onap.cps.spi.model.SchemaSet;
/**
* Responsible for managing module sets.
@@ -40,5 +39,12 @@ public interface CpsModuleService {
void createSchemaSet(@NonNull String dataspaceName, @NonNull String schemaSetName,
@NonNull Map<String, String> yangResourcesNameToContentMap);
-
+ /**
+ * Read schema set in the given dataspace.
+ *
+ * @param dataspaceName dataspace name
+ * @param schemaSetName schema set name
+ * @return a SchemaSet
+ */
+ SchemaSet getSchemaSet(@NonNull String dataspaceName, @NonNull String schemaSetName);
}
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 8a437dbdee..04a6fe1cee 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
@@ -19,10 +19,11 @@
package org.onap.cps.api.impl;
-
import java.util.Map;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.spi.CpsModulePersistenceService;
+import org.onap.cps.spi.model.SchemaSet;
+import org.onap.cps.yang.YangTextSchemaSourceSet;
import org.onap.cps.yang.YangTextSchemaSourceSetBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -42,4 +43,16 @@ public class CpsModuleServiceImpl implements CpsModuleService {
.storeSchemaSet(dataspaceName, schemaSetName, yangResourcesNameToContentMap);
}
+ @Override
+ public SchemaSet getSchemaSet(final String dataspaceName, final String schemaSetName) {
+ final Map<String, String> yangResourceNameToContent =
+ cpsModulePersistenceService.getYangSchemaResources(dataspaceName, schemaSetName);
+ final YangTextSchemaSourceSet yangTextSchemaSourceSet = YangTextSchemaSourceSetBuilder
+ .of(yangResourceNameToContent);
+ return SchemaSet.builder()
+ .name(schemaSetName)
+ .dataspaceName(dataspaceName)
+ .moduleReferences(yangTextSchemaSourceSet.getModuleReferences())
+ .build();
+ }
}
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 ba53003ace..5643aedb72 100644
--- 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,5 +57,4 @@ public interface CpsAdminPersistenceService {
*/
@NonNull
Collection<Anchor> getAnchors(@NonNull String dataspaceName);
-
}
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 63f1f36c73..a82d69acbd 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,9 +20,8 @@
package org.onap.cps.spi;
-import java.util.Collection;
import java.util.Map;
-import org.onap.cps.spi.model.ModuleReference;
+import org.checkerframework.checker.nullness.qual.NonNull;
/**
* Service to manage modules.
@@ -36,14 +35,16 @@ public interface CpsModulePersistenceService {
* @param schemaSetName schema set name
* @param yangResourcesNameToContentMap YANG resources (files) map where key is a name and value is content
*/
- void storeSchemaSet(String dataspaceName, String schemaSetName, Map<String, String> yangResourcesNameToContentMap);
+ void storeSchemaSet(@NonNull String dataspaceName, @NonNull String schemaSetName,
+ @NonNull Map<String, String> yangResourcesNameToContentMap);
/**
- * Returns Modules references per specific namespace / schemaSetName.
+ * Returns YANG resources per specific namespace / schemaSetName.
*
* @param namespace module namespace
* @param schemaSetName schema set name
- * @return collection of ModuleRef
+ * @return YANG resources (files) map where key is a name and value is content
*/
- Collection<ModuleReference> getModuleReferences(String namespace, String schemaSetName);
+ @NonNull
+ Map<String, String> getYangSchemaResources(@NonNull String namespace, @NonNull String schemaSetName);
}
diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java b/cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java
index 5af355dcdb..aa198a9c71 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/model/ModuleReference.java
@@ -31,6 +31,7 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
public class ModuleReference {
+ private String name;
private String namespace;
private String revision;
}
diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/SchemaSet.java b/cps-service/src/main/java/org/onap/cps/spi/model/SchemaSet.java
new file mode 100644
index 0000000000..caf7800d9b
--- /dev/null
+++ b/cps-service/src/main/java/org/onap/cps/spi/model/SchemaSet.java
@@ -0,0 +1,39 @@
+/*
+ * ============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.model;
+
+import java.io.Serializable;
+import java.util.List;
+import lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.Data;
+import lombok.NoArgsConstructor;
+
+@Data
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+public class SchemaSet implements Serializable {
+
+ private static final long serialVersionUID = 1464791260718603291L;
+ private String name;
+ private String dataspaceName;
+ private List<ModuleReference> moduleReferences;
+}
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 6d825445c3..ae0f2cd3e8 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
@@ -49,11 +49,6 @@ public final class YangTextSchemaSourceSetBuilder {
private final ImmutableMap.Builder<String, String> yangModelMap = new ImmutableMap.Builder<>();
- public YangTextSchemaSourceSetBuilder put(final String fileName, final String content) {
- this.yangModelMap.put(fileName, content);
- return this;
- }
-
public YangTextSchemaSourceSetBuilder putAll(final Map<String, String> yangResourceNameToContent) {
this.yangModelMap.putAll(yangResourceNameToContent);
return this;
@@ -95,6 +90,7 @@ public final class YangTextSchemaSourceSetBuilder {
private static ModuleReference toModuleReference(final Module module) {
return ModuleReference.builder()
+ .name(module.getName())
.namespace(module.getNamespace().toString())
.revision(module.getRevision().map(Revision::toString).orElse(null))
.build();