aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xINFO.yaml16
-rw-r--r--cps-rest/docs/openapi/components.yml44
-rw-r--r--cps-rest/docs/openapi/cpsAdmin.yml22
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java77
-rwxr-xr-xcps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy2
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java5
-rw-r--r--cps-service/src/main/java/org/onap/cps/utils/YangUtils.java8
-rw-r--r--cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy13
8 files changed, 170 insertions, 17 deletions
diff --git a/INFO.yaml b/INFO.yaml
index 5b1fc0ca8f..b5fdaad0a2 100755
--- a/INFO.yaml
+++ b/INFO.yaml
@@ -39,11 +39,21 @@ committers:
company: 'Bell Canada'
id: 'brusak'
timezone: 'America/Toronto'
- - name: 'Rishi Chail'
- email: 'rishi.chail@est.tech'
+ - name: 'Niamh Core'
+ email: 'niamh.core@est.tech'
company: 'Ericsson Software Technology'
- id: 'Rishi.Chail'
+ id: 'niamhcore'
timezone: 'Europe/Dublin'
+ - name: 'Aditya Puthuparambil'
+ email: 'aditya.puthuparambil@bell.ca'
+ company: 'Bell Canada'
+ id: 'puthuparambil.aditya'
+ timezone: 'Europe/Dublin'
+ - name: 'Renu Kumari'
+ email: 'renu.kumari@bell.ca'
+ company: 'Bell Canada'
+ id: 'renukumari'
+ timezone: 'America/Toronto'
repositories:
- cps
tsc:
diff --git a/cps-rest/docs/openapi/components.yml b/cps-rest/docs/openapi/components.yml
index 8398714c60..6543fcab6d 100644
--- a/cps-rest/docs/openapi/components.yml
+++ b/cps-rest/docs/openapi/components.yml
@@ -16,6 +16,21 @@
components:
schemas:
+
+ AnchorDetails:
+ type: object
+ title: Anchor details by anchor Name
+ properties:
+ name:
+ type: string
+ example: my_anchor
+ dataspaceName:
+ type: string
+ example: my_dataspace
+ schemaSetName:
+ type: string
+ example: my_schema_set
+
ErrorMessage:
type: object
title: Error
@@ -40,6 +55,35 @@ components:
format: binary
example: http://example.com/examples/example.yang
+ ModuleReferences:
+ type: object
+ title: Module reference object
+ properties:
+ name:
+ type: string
+ example: module_reference_name
+ namespace:
+ type: string
+ example: module_reference_namespace
+ revision:
+ type: string
+ example: module_reference_revision
+
+ SchemaSetDetails:
+ type: object
+ title: Schema set details by dataspace and schemasetName
+ properties:
+ dataspaceName:
+ type: string
+ example: my_dataspace
+ moduleReferences:
+ type: array
+ items:
+ $ref: '#/components/schemas/ModuleReferences'
+ name:
+ type: string
+ example: my_schema_set
+
parameters:
dataspaceNameInQuery:
name: dataspace-name
diff --git a/cps-rest/docs/openapi/cpsAdmin.yml b/cps-rest/docs/openapi/cpsAdmin.yml
index cb55948686..35b2e4ca6a 100644
--- a/cps-rest/docs/openapi/cpsAdmin.yml
+++ b/cps-rest/docs/openapi/cpsAdmin.yml
@@ -94,7 +94,11 @@ schemaSetBySchemaSetName:
- $ref: 'components.yml#/components/parameters/schemaSetNameInPath'
responses:
'200':
- $ref: 'components.yml#/components/responses/Ok'
+ description: OK
+ content:
+ application/json:
+ schema:
+ $ref: 'components.yml#/components/schemas/SchemaSetDetails'
'400':
$ref: 'components.yml#/components/responses/BadRequest'
'401':
@@ -136,7 +140,13 @@ anchorsByDataspace:
- $ref: 'components.yml#/components/parameters/dataspaceNameInPath'
responses:
'200':
- $ref: 'components.yml#/components/responses/Ok'
+ description: OK
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: 'components.yml#/components/schemas/AnchorDetails'
'400':
$ref: 'components.yml#/components/responses/BadRequest'
'401':
@@ -178,7 +188,11 @@ anchorByDataspaceAndAnchorName:
- $ref: 'components.yml#/components/parameters/anchorNameInPath'
responses:
'200':
- $ref: 'components.yml#/components/responses/Ok'
+ description: OK
+ content:
+ application/json:
+ schema:
+ $ref: 'components.yml#/components/schemas/AnchorDetails'
'400':
$ref: 'components.yml#/components/responses/BadRequest'
'401':
@@ -205,4 +219,4 @@ anchorByDataspaceAndAnchorName:
'401':
$ref: 'components.yml#/components/responses/Unauthorized'
'403':
- $ref: 'components.yml#/components/responses/Forbidden'
+ $ref: 'components.yml#/components/responses/Forbidden' \ No newline at end of file
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
index 74b1a418d1..57b6771940 100755
--- a/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java
@@ -25,11 +25,16 @@ import static org.onap.cps.rest.utils.MultipartFileUtil.extractYangResourcesMap;
import static org.onap.cps.spi.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED;
import java.util.Collection;
+import java.util.List;
+import java.util.stream.Collectors;
import org.modelmapper.ModelMapper;
import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsModuleService;
import org.onap.cps.rest.api.CpsAdminApi;
+import org.onap.cps.rest.model.AnchorDetails;
+import org.onap.cps.rest.model.SchemaSetDetails;
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;
@@ -50,17 +55,37 @@ public class AdminRestController implements CpsAdminApi {
@Autowired
private ModelMapper modelMapper;
+ /**
+ * Create a dataspace.
+ *
+ * @param dataspaceName dataspace name
+ * @return a {@Link ResponseEntity} of created dataspace name & {@link HttpStatus} CREATED
+ */
@Override
public ResponseEntity<String> createDataspace(final String dataspaceName) {
cpsAdminService.createDataspace(dataspaceName);
return new ResponseEntity<>(dataspaceName, HttpStatus.CREATED);
}
+ /**
+ * Delete a dataspace based on a given name.
+ *
+ * @param dataspaceName dataspace name
+ * @return a {@Link ResponseEntity} of {@link HttpStatus} NOT_IMPLEMENTED
+ */
@Override
public ResponseEntity<Object> deleteDataspace(final String dataspaceName) {
return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED);
}
+ /**
+ * Create a {@link SchemaSet}.
+ *
+ * @param multipartFile multipart file
+ * @param schemaSetName schemaset name
+ * @param dataspaceName dataspace name
+ * @return a {@Link ResponseEntity} of created schemaset name & {@link HttpStatus} CREATED
+ */
@Override
public ResponseEntity<String> createSchemaSet(final MultipartFile multipartFile,
final String schemaSetName, final String dataspaceName) {
@@ -68,12 +93,27 @@ public class AdminRestController implements CpsAdminApi {
return new ResponseEntity<>(schemaSetName, HttpStatus.CREATED);
}
+ /**
+ * Get {@link SchemaSetDetails} based on dataspace name & {@link SchemaSet} name.
+ *
+ * @param dataspaceName dataspace name
+ * @param schemaSetName schemaset name
+ * @return a {@Link ResponseEntity} of {@Link SchemaSetDetails} & {@link HttpStatus} OK
+ */
@Override
- public ResponseEntity<Object> getSchemaSet(final String dataspaceName, final String schemaSetName) {
+ public ResponseEntity<SchemaSetDetails> getSchemaSet(final String dataspaceName, final String schemaSetName) {
final var schemaSet = cpsModuleService.getSchemaSet(dataspaceName, schemaSetName);
- return new ResponseEntity<>(schemaSet, HttpStatus.OK);
+ final SchemaSetDetails schemaSetDetails = modelMapper.map(schemaSet, SchemaSetDetails.class);
+ return new ResponseEntity<>(schemaSetDetails, HttpStatus.OK);
}
+ /**
+ * Delete a {@link SchemaSet} based on given dataspace name & schemaset name.
+ *
+ * @param dataspaceName dataspace name
+ * @param schemaSetName schemaset name
+ * @return a {@Link ResponseEntity} of {@link HttpStatus} NO_CONTENT
+ */
@Override
public ResponseEntity<Void> deleteSchemaSet(final String dataspaceName, final String schemaSetName) {
cpsModuleService.deleteSchemaSet(dataspaceName, schemaSetName, CASCADE_DELETE_PROHIBITED);
@@ -86,7 +126,7 @@ public class AdminRestController implements CpsAdminApi {
* @param dataspaceName dataspace name
* @param schemaSetName schema set name
* @param anchorName anchorName
- * @return a ResponseEntity with the anchor name.
+ * @return a ResponseEntity with the anchor name & {@link HttpStatus} CREATED
*/
@Override
public ResponseEntity<String> createAnchor(final String dataspaceName, final String schemaSetName,
@@ -95,21 +135,44 @@ public class AdminRestController implements CpsAdminApi {
return new ResponseEntity<>(anchorName, HttpStatus.CREATED);
}
+ /**
+ * Delete an {@link Anchor} based on given dataspace name & anchor name.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @return a {@Link ResponseEntity} of {@link HttpStatus} NO_CONTENT
+ */
@Override
public ResponseEntity<Void> deleteAnchor(final String dataspaceName, final String anchorName) {
cpsAdminService.deleteAnchor(dataspaceName, anchorName);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
}
+ /**
+ * Get an {@link Anchor} based on given dataspace name & anchor name.
+ *
+ * @param dataspaceName dataspace name
+ * @param anchorName anchor name
+ * @return a {@Link ResponseEntity} of an {@Link AnchorDetails} & {@link HttpStatus} OK
+ */
@Override
- public ResponseEntity<Object> getAnchor(final String dataspaceName, final String anchorName) {
+ public ResponseEntity<AnchorDetails> getAnchor(final String dataspaceName, final String anchorName) {
final var anchor = cpsAdminService.getAnchor(dataspaceName, anchorName);
- return new ResponseEntity<>(anchor, HttpStatus.OK);
+ final AnchorDetails anchorDetails = modelMapper.map(anchor, AnchorDetails.class);
+ return new ResponseEntity<>(anchorDetails, HttpStatus.OK);
}
+ /**
+ * Get all {@link Anchor} based on given dataspace name.
+ *
+ * @param dataspaceName dataspace name
+ * @return a {@Link ResponseEntity} of all {@Link AnchorDetails} & {@link HttpStatus} OK
+ */
@Override
- public ResponseEntity<Object> getAnchors(final String dataspaceName) {
- final Collection<Anchor> anchorDetails = cpsAdminService.getAnchors(dataspaceName);
+ public ResponseEntity<List<AnchorDetails>> getAnchors(final String dataspaceName) {
+ final Collection<Anchor> anchors = cpsAdminService.getAnchors(dataspaceName);
+ final List<AnchorDetails> anchorDetails = anchors.stream().map(anchor ->
+ modelMapper.map(anchor, AnchorDetails.class)).collect(Collectors.toList());
return new ResponseEntity<>(anchorDetails, HttpStatus.OK);
}
}
diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy
index e158ebdedc..9ce7f73939 100755
--- a/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy
+++ b/cps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy
@@ -64,7 +64,7 @@ class AdminRestControllerSpec extends Specification {
CpsQueryService mockCpsQueryService = Mock()
@SpringBean
- ModelMapper modelMapper = Mock()
+ ModelMapper modelMapper = Spy()
@Autowired
MockMvc mvc
diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java b/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java
index 762e61ac59..4a9957deb4 100644
--- a/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/model/DataNodeBuilder.java
@@ -29,6 +29,7 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
+import org.onap.cps.spi.exceptions.DataValidationException;
import org.onap.cps.utils.YangUtils;
import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
@@ -142,6 +143,10 @@ public class DataNodeBuilder {
private DataNode buildFromNormalizedNodeTree() {
final Collection<DataNode> dataNodeCollection = buildCollectionFromNormalizedNodeTree();
+ if (!dataNodeCollection.iterator().hasNext()) {
+ throw new DataValidationException(
+ "Unsupported xpath: ", "Unsupported xpath as it is referring to one element");
+ }
return dataNodeCollection.iterator().next();
}
diff --git a/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java b/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java
index 0b66d37fba..b5c14a0721 100644
--- a/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java
+++ b/cps-service/src/main/java/org/onap/cps/utils/YangUtils.java
@@ -94,9 +94,13 @@ public class YangUtils {
final var jsonReader = new JsonReader(new StringReader(jsonData));
jsonParserStream.parse(jsonReader);
- } catch (final IOException | IllegalStateException | JsonSyntaxException exception) {
+ } catch (final IOException | JsonSyntaxException exception) {
throw new DataValidationException(
- "Failed to parse json data: " + jsonData, exception.getMessage(), exception);
+ "Failed to parse json data: " + jsonData, exception.getMessage(), exception);
+ } catch (final IllegalStateException illegalStateException) {
+ throw new DataValidationException(
+ "Failed to parse json data. Unsupported xpath or json data:" + jsonData, illegalStateException
+ .getMessage(), illegalStateException);
}
return normalizedNodeResult.getResult();
}
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
index 27a5a4e0ca..8001d6a9fe 100644
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsDataServiceImplSpec.groovy
@@ -125,6 +125,19 @@ class CpsDataServiceImplSpec extends Specification {
'level 2 node' | '/test-tree' | '{"branch": [{"name":"Name"}]}' || '/test-tree/branch[@name=\'Name\']' | ['name': 'Name']
}
+ def 'Update list-element data node with : #scenario.'() {
+ given: 'schema set for given anchor and dataspace references bookstore model'
+ setupSchemaSetMocks('bookstore.yang')
+ when: 'update data method is invoked with json data #jsonData and parent node xpath'
+ objectUnderTest.updateNodeLeaves(dataspaceName, anchorName, '/bookstore/categories[@code=2]', jsonData)
+ then: 'the persistence service method is invoked with correct parameters'
+ thrown(DataValidationException)
+ where: 'following parameters were used'
+ scenario | jsonData
+ 'multiple leaves' | '{"code": "01","name": "some-name"}'
+ 'one leaf' | '{"name": "some-name"}'
+ }
+
def 'Replace data node: #scenario.'() {
given: 'schema set for given anchor and dataspace references test-tree model'
setupSchemaSetMocks('test-tree.yang')