<base.image>openjdk:11-jre-slim</base.image>
<java.version>11</java.version>
<jib-maven-plugin.version>2.6.0</jib-maven-plugin.version>
- <minimum-coverage>0.35</minimum-coverage>
+ <minimum-coverage>0.44</minimum-coverage>
<nexusproxy>https://nexus.onap.org</nexusproxy>
<oparent.version>3.1.0</oparent.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
403:
description: Forbidden
content: {}
+ /v1/dataspaces/{dataspace-name}/schema-sets/{schema-set-name}:
+ get:
+ tags:
+ - cps-admin
+ summary: Read a schema set given a schema set and a dataspace
+ operationId: getSchemaSet
+ parameters:
+ - name: dataspace-name
+ in: path
+ description: dataspace-name
+ required: true
+ schema:
+ type: string
+ - name: schema-set-name
+ in: path
+ description: schema-name
+ required: true
+ schema:
+ type: string
+ responses:
+ 200:
+ description: OK
+ content:
+ application/json:
+ schema:
+ type: object
+ 401:
+ description: Unauthorized
+ content: {}
+ 403:
+ description: Forbidden
+ content: {}
+ 404:
+ description: Not Found
+ content: {}
/v1/dataspaces/{dataspace-name}/schema-sets:
post:
tags:
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.rest.api.CpsAdminApi;
import org.onap.cps.spi.model.Anchor;
+import org.onap.cps.spi.model.SchemaSet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
return new ResponseEntity<>(schemaSetName, HttpStatus.CREATED);
}
+ @Override
+ public ResponseEntity<Object> getSchemaSet(final String dataspaceName, final String schemaSetName) {
+ final SchemaSet schemaSet = cpsModuleService.getSchemaSet(dataspaceName, schemaSetName);
+ return new ResponseEntity<>(schemaSet, HttpStatus.OK);
+ }
+
/**
* Create a new anchor.
*
import org.onap.cps.api.CpsModuleService
import org.onap.cps.spi.model.Anchor
import org.onap.cps.spi.exceptions.DataspaceAlreadyDefinedException
+import org.onap.cps.spi.model.SchemaSet
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
-import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest
import org.springframework.http.HttpStatus
import org.springframework.http.MediaType
MockMvc mvc
def anchorsEndpoint = '/v1/dataspaces/my_dataspace/anchors'
+ def schemaSetsEndpoint = '/v1/dataspaces/test-dataspace/schema-sets'
+ def schemaSetEndpoint = schemaSetsEndpoint + '/my_schema_set'
def anchor = new Anchor(name: 'my_anchor')
def anchorList = [anchor]
def response = performCreateDataspaceRequest("new-dataspace")
then: 'Service method is invoked with expected parameters'
1 * mockCpsAdminService.createDataspace("new-dataspace")
- and:
+ and: 'Dataspace is create successfully'
response.status == HttpStatus.CREATED.value()
}
mockCpsAdminService.createDataspace("existing-dataspace") >> { throw thrownException }
when:
def response = performCreateDataspaceRequest("existing-dataspace")
- then:
+ then: 'Dataspace creation fails'
response.status == HttpStatus.BAD_REQUEST.value()
}
def multipartFile = createMultipartFile("filename.doc", "content")
when:
def response = performCreateSchemaSetRequest(multipartFile)
- then:
+ then: 'Create schema fails'
response.status == HttpStatus.BAD_REQUEST.value()
}
def performCreateSchemaSetRequest(multipartFile) {
return mvc.perform(
MockMvcRequestBuilders
- .multipart('/v1/dataspaces/test-dataspace/schema-sets')
+ .multipart(schemaSetsEndpoint)
.file(multipartFile)
.param('schemaSetName', 'test-schema-set')
).andReturn().response
}
- def 'when createAnchor API is called, the response status is 201. '() {
+ def 'Get existing schema set'() {
+ given:
+ mockCpsModuleService.getSchemaSet('test-dataspace', 'my_schema_set') >>
+ new SchemaSet(name: 'my_schema_set', dataspaceName: 'test-dataspace')
+ when: 'get schema set API is invoked'
+ def response = mvc.perform(get(schemaSetEndpoint)).andReturn().response
+ then: 'the correct schema set is returned'
+ response.status == HttpStatus.OK.value()
+ response.getContentAsString().contains('my_schema_set')
+ }
+
+ def 'Create Anchor'() {
given:
def requestParams = new LinkedMultiValueMap<>()
requestParams.add('schema-set-name', 'my_schema-set')
when: 'post is invoked'
def response = mvc.perform(post(anchorsEndpoint).contentType(MediaType.APPLICATION_JSON)
.params(requestParams as MultiValueMap)).andReturn().response
- then: 'Status is 201 and the response is the name of the created anchor -> my_anchor'
+ then: 'Anchor is created successfully'
1 * mockCpsAdminService.createAnchor('my_dataspace', 'my_schema-set', 'my_anchor')
- assert response.status == HttpStatus.CREATED.value()
- assert response.getContentAsString().contains('my_anchor')
+ response.status == HttpStatus.CREATED.value()
+ response.getContentAsString().contains('my_anchor')
}
- def 'when get all anchors for a dataspace API is called, the response status is 200 '() {
+ def 'Get existing anchor'() {
given:
mockCpsAdminService.getAnchors('my_dataspace') >> anchorList
when: 'get all anchors API is invoked'
def response = mvc.perform(get(anchorsEndpoint)).andReturn().response
- then: 'Status is 200 and the response is Collection of Anchors containing anchor name -> my_anchor'
- assert response.status == HttpStatus.OK.value()
- assert response.getContentAsString().contains('my_anchor')
+ then: 'the correct anchor is returned'
+ response.status == HttpStatus.OK.value()
+ response.getContentAsString().contains('my_anchor')
}
}
import org.onap.cps.spi.entities.SchemaSet;
import org.onap.cps.spi.entities.YangResource;
import org.onap.cps.spi.exceptions.SchemaSetAlreadyDefinedException;
-import org.onap.cps.spi.model.ModuleReference;
import org.onap.cps.spi.repository.DataspaceRepository;
import org.onap.cps.spi.repository.SchemaSetRepository;
import org.onap.cps.spi.repository.YangResourceRepository;
-import org.onap.cps.yang.YangTextSchemaSourceSetBuilder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.stereotype.Component;
}
@Override
- public Collection<ModuleReference> getModuleReferences(final String dataspaceName, final String schemaSetName) {
+ public Map<String, String> getYangSchemaResources(final String dataspaceName, final String schemaSetName) {
final Dataspace dataspace = dataspaceRepository.getByName(dataspaceName);
final SchemaSet schemaSet = schemaSetRepository.getByDataspaceAndName(dataspace, schemaSetName);
- final Map<String, String> yangResourceNameToContent = schemaSet.getYangResources().stream().collect(
+ return schemaSet.getYangResources().stream().collect(
Collectors.toMap(YangResource::getName, YangResource::getContent));
- return YangTextSchemaSourceSetBuilder.of(yangResourceNameToContent).getModuleReferences();
}
}
@Test
@SqlGroup({@Sql(CLEAR_DATA), @Sql(SET_DATA)})
public void testStoreSchemaSetWithNewYangResource() {
+ final Map<String, String> yangResourcesNameToContentMap = toMap(NEW_RESOURCE_NAME, NEW_RESOURCE_CONTENT);
cpsModulePersistenceService.storeSchemaSet(DATASPACE_NAME, SCHEMA_SET_NAME_NEW,
- toMap(NEW_RESOURCE_NAME, NEW_RESOURCE_CONTENT));
+ yangResourcesNameToContentMap);
assertSchemaSetPersisted(DATASPACE_NAME, SCHEMA_SET_NAME_NEW,
NEW_RESOURCE_ABSTRACT_ID, NEW_RESOURCE_NAME, NEW_RESOURCE_CONTENT, NEW_RESOURCE_CHECKSUM);
+ assertEquals(yangResourcesNameToContentMap,
+ cpsModulePersistenceService.getYangSchemaResources(DATASPACE_NAME, SCHEMA_SET_NAME_NEW));
}
@Test
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
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.
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);
}
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;
.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();
+ }
}
*/
@NonNull
Collection<Anchor> getAnchors(@NonNull String dataspaceName);
-
}
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.
* @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);
}
@AllArgsConstructor
public class ModuleReference {
+ private String name;
private String namespace;
private String revision;
}
--- /dev/null
+/*
+ * ============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;
+}
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;
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();
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 {
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'))
+ }
}