diff options
Diffstat (limited to 'cps-service')
10 files changed, 85 insertions, 86 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 581550fb5..853bd958f 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 e7b02fbad..5f63f97f1 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 8a437dbde..04a6fe1ce 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 ba53003ac..5643aedb7 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 df0f9f5a2..a82d69acb 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. @@ -30,36 +29,22 @@ import org.onap.cps.spi.model.ModuleReference; public interface CpsModulePersistenceService { /** - * TODO - * clean up method to conform with spi proposal - https://jira.onap.org/browse/CPS-103 - * Store the module from a yang model in the database. - * @deprecated - * - * @param namespace module namespace - * @param moduleContent module content - * @param revision module revision - * @param dataspaceName the name of the dataspace the module is associated with - */ - @Deprecated(forRemoval = true) - void storeModule(final String namespace, final String moduleContent, final String revision, - final String dataspaceName); - - - /** * Stores Schema Set. * * @param dataspaceName dataspace name * @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/DataPersistenceService.java b/cps-service/src/main/java/org/onap/cps/spi/DataPersistenceService.java deleted file mode 100644 index a3cbc28c5..000000000 --- a/cps-service/src/main/java/org/onap/cps/spi/DataPersistenceService.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * ============LICENSE_START======================================================= - * Copyright (C) 2020 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; - -/** - * Defines methods to access and manipulate data using the chosen database solution. - */ -public interface DataPersistenceService { - - /** - * Store the JSON structure in the database. - * - * @param jsonStructure the JSON structure. - * @return jsonEntityID the ID of the JSON entity. - */ - Integer storeJsonStructure(final String jsonStructure); - - /** - * Get the JSON structure from the database using the entity identifier. - * - * @param jsonStructureId the json entity identifier. - * @return a JSON Structure. - */ - String getJsonById(int jsonStructureId); - - /** - * Delete the JSON structure from the database using the entity identifier. - * - * @param jsonStructureId the json entity identifier. - */ - void deleteJsonById(int jsonStructureId); -}
\ No newline at end of file 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 5af355dcd..aa198a9c7 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 000000000..caf7800d9 --- /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 6d825445c..ae0f2cd3e 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(); 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 a93411bfe..ebe4fe7bc 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 @@ -21,11 +21,9 @@ package org.onap.cps.api.impl import org.onap.cps.TestUtils -import org.onap.cps.spi.CpsModulePersistenceService +import org.onap.cps.spi.CpsModulePersistenceService; import org.onap.cps.spi.exceptions.ModelValidationException -import org.onap.cps.utils.YangUtils -import org.opendaylight.yangtools.yang.common.Revision -import org.opendaylight.yangtools.yang.model.api.SchemaContext +import org.onap.cps.spi.model.ModuleReference import spock.lang.Specification class CpsModuleServiceImplSpec extends Specification { @@ -54,4 +52,15 @@ class CpsModuleServiceImplSpec extends Specification { thrown(ModelValidationException.class) } + def 'Get schema set by name and namespace.'() { + given: 'an already present schema set' + def yangResourcesNameToContentMap = TestUtils.getYangResourcesAsMap('bookstore.yang') + mockModuleStoreService.getYangSchemaResources('someDataspace', 'someSchemaSet') >> yangResourcesNameToContentMap + when: 'get schema set method is invoked' + def result = objectUnderTest.getSchemaSet('someDataspace', 'someSchemaSet') + then: 'the correct schema set is returned' + result.getName().contains('someSchemaSet') + result.getDataspaceName().contains('someDataspace') + result.getModuleReferences().contains(new ModuleReference('stores', 'org:onap:ccsdk:sample', '2020-09-15')) + } } |