summaryrefslogtreecommitdiffstats
path: root/cps-rest
diff options
context:
space:
mode:
Diffstat (limited to 'cps-rest')
-rw-r--r--cps-rest/docs/openapi/components.yml9
-rw-r--r--cps-rest/docs/openapi/cpsAdmin.yml53
-rw-r--r--cps-rest/docs/openapi/openapi.yml7
-rwxr-xr-xcps-rest/src/main/java/org/onap/cps/rest/controller/AdminRestController.java18
-rw-r--r--cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestInputMapper.java4
-rwxr-xr-xcps-rest/src/test/groovy/org/onap/cps/rest/controller/AdminRestControllerSpec.groovy28
6 files changed, 118 insertions, 1 deletions
diff --git a/cps-rest/docs/openapi/components.yml b/cps-rest/docs/openapi/components.yml
index 269e724b18..fb0947e54a 100644
--- a/cps-rest/docs/openapi/components.yml
+++ b/cps-rest/docs/openapi/components.yml
@@ -1,6 +1,7 @@
# ============LICENSE_START=======================================================
# Copyright (c) 2021-2022 Bell Canada.
# Modifications Copyright (C) 2021-2022 Nordix Foundation
+# Modifications Copyright (C) 2022 TechMahindra Ltd.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -34,6 +35,14 @@ components:
type: string
example: my-schema-set
+ DataspaceDetails:
+ type: object
+ title: Dataspace details by dataspace Name
+ properties:
+ name:
+ type: string
+ example: my-dataspace
+
ErrorMessage:
type: object
title: Error
diff --git a/cps-rest/docs/openapi/cpsAdmin.yml b/cps-rest/docs/openapi/cpsAdmin.yml
index 5852c0cf16..e887ef2c07 100644
--- a/cps-rest/docs/openapi/cpsAdmin.yml
+++ b/cps-rest/docs/openapi/cpsAdmin.yml
@@ -1,6 +1,7 @@
# ============LICENSE_START=======================================================
# Copyright (c) 2021 Bell Canada.
# Modifications Copyright (C) 2021-2022 Nordix Foundation
+# Modifications Copyright (C) 2022 TechMahindra Ltd.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -233,4 +234,54 @@ anchorByDataspaceAndAnchorName:
'403':
$ref: 'components.yml#/components/responses/Forbidden'
'500':
- $ref: 'components.yml#/components/responses/InternalServerError' \ No newline at end of file
+ $ref: 'components.yml#/components/responses/InternalServerError'
+
+adminDataspaces:
+ get:
+ description: Read all dataspaces
+ tags:
+ - cps-admin
+ summary: Get all dataspaces
+ operationId: getAllDataspaces
+ responses:
+ '200':
+ description: OK
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: 'components.yml#/components/schemas/DataspaceDetails'
+ '400':
+ $ref: 'components.yml#/components/responses/BadRequest'
+ '401':
+ $ref: 'components.yml#/components/responses/Unauthorized'
+ '403':
+ $ref: 'components.yml#/components/responses/Forbidden'
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
+
+adminDataspace:
+ get:
+ description: Read a dataspace given a dataspace name
+ tags:
+ - cps-admin
+ summary: Get a dataspace
+ operationId: getDataspace
+ parameters:
+ - $ref: 'components.yml#/components/parameters/dataspaceNameInPath'
+ responses:
+ '200':
+ description: OK
+ content:
+ application/json:
+ schema:
+ $ref: 'components.yml#/components/schemas/DataspaceDetails'
+ '400':
+ $ref: 'components.yml#/components/responses/BadRequest'
+ '401':
+ $ref: 'components.yml#/components/responses/Unauthorized'
+ '403':
+ $ref: 'components.yml#/components/responses/Forbidden'
+ '500':
+ $ref: 'components.yml#/components/responses/InternalServerError'
diff --git a/cps-rest/docs/openapi/openapi.yml b/cps-rest/docs/openapi/openapi.yml
index 290bbf44b2..e170295504 100644
--- a/cps-rest/docs/openapi/openapi.yml
+++ b/cps-rest/docs/openapi/openapi.yml
@@ -2,6 +2,7 @@
# Copyright (C) 2021 Nordix Foundation
# Modifications Copyright (C) 2021 Pantheon.tech
# Modifications Copyright (C) 2021 Bell Canada.
+# Modifications Copyright (C) 2022 TechMahindra Ltd.
# ================================================================================
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
@@ -52,6 +53,12 @@ paths:
/v1/dataspaces:
$ref: 'cpsAdmin.yml#/dataspaces'
+ /v1/admin/dataspaces:
+ $ref: 'cpsAdmin.yml#/adminDataspaces'
+
+ /v1/admin/dataspaces/{dataspace-name}:
+ $ref: 'cpsAdmin.yml#/adminDataspace'
+
/v1/dataspaces/{dataspace-name}/anchors:
$ref: 'cpsAdmin.yml#/anchorsByDataspace'
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 2707d9f294..a29f8d2969 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
@@ -3,6 +3,7 @@
* Copyright (C) 2020-2022 Nordix Foundation
* Modifications Copyright (C) 2020-2021 Bell Canada.
* Modifications Copyright (C) 2021 Pantheon.tech
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -35,8 +36,10 @@ 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.DataspaceDetails;
import org.onap.cps.rest.model.SchemaSetDetails;
import org.onap.cps.spi.model.Anchor;
+import org.onap.cps.spi.model.Dataspace;
import org.onap.cps.spi.model.SchemaSet;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
@@ -174,4 +177,19 @@ public class AdminRestController implements CpsAdminApi {
.collect(Collectors.toList());
return new ResponseEntity<>(anchorDetails, HttpStatus.OK);
}
+
+ @Override
+ public ResponseEntity<List<DataspaceDetails>> getAllDataspaces() {
+ final Collection<Dataspace> dataspaces = cpsAdminService.getAllDataspaces();
+ final List<DataspaceDetails> dataspaceDetails = dataspaces.stream().map(cpsRestInputMapper::toDataspaceDetails)
+ .collect(Collectors.toList());
+ return new ResponseEntity<>(dataspaceDetails, HttpStatus.OK);
+ }
+
+ @Override
+ public ResponseEntity<DataspaceDetails> getDataspace(final String dataspaceName) {
+ final Dataspace dataspace = cpsAdminService.getDataspace(dataspaceName);
+ final DataspaceDetails dataspaceDetails = cpsRestInputMapper.toDataspaceDetails(dataspace);
+ return new ResponseEntity<>(dataspaceDetails, HttpStatus.OK);
+ }
}
diff --git a/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestInputMapper.java b/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestInputMapper.java
index d0a4a108c8..3d3ab1145b 100644
--- a/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestInputMapper.java
+++ b/cps-rest/src/main/java/org/onap/cps/rest/controller/CpsRestInputMapper.java
@@ -1,6 +1,7 @@
/*
* ============LICENSE_START=======================================================
* Copyright (C) 2022 Nordix Foundation
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -25,8 +26,10 @@ import org.mapstruct.Mapping;
import org.mapstruct.NullValueCheckStrategy;
import org.mapstruct.NullValuePropertyMappingStrategy;
import org.onap.cps.rest.model.AnchorDetails;
+import org.onap.cps.rest.model.DataspaceDetails;
import org.onap.cps.rest.model.SchemaSetDetails;
import org.onap.cps.spi.model.Anchor;
+import org.onap.cps.spi.model.Dataspace;
import org.onap.cps.spi.model.SchemaSet;
@Mapper(componentModel = "spring")
@@ -39,4 +42,5 @@ public interface CpsRestInputMapper {
AnchorDetails toAnchorDetails(final Anchor anchor);
+ DataspaceDetails toDataspaceDetails(final Dataspace dataspace);
}
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 41ad9ca5b2..e9612fc395 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
@@ -3,6 +3,7 @@
* Copyright (C) 2020-2021 Pantheon.tech
* Modifications Copyright (C) 2020-2021 Bell Canada.
* Modifications Copyright (C) 2021-2022 Nordix Foundation
+ * Modifications Copyright (C) 2022 TechMahindra Ltd.
* ================================================================================
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -34,6 +35,7 @@ import org.onap.cps.api.CpsModuleService
import org.onap.cps.spi.exceptions.AlreadyDefinedException
import org.onap.cps.spi.exceptions.SchemaSetInUseException
import org.onap.cps.spi.model.Anchor
+import org.onap.cps.spi.model.Dataspace
import org.onap.cps.spi.model.SchemaSet
import org.spockframework.spring.SpringBean
import org.springframework.beans.factory.annotation.Autowired
@@ -69,6 +71,7 @@ class AdminRestControllerSpec extends Specification {
def anchorName = 'my_anchor'
def schemaSetName = 'my_schema_set'
def anchor = new Anchor(name: anchorName, dataspaceName: dataspaceName, schemaSetName: schemaSetName)
+ def dataspace = new Dataspace(name: dataspaceName)
def 'Create new dataspace.'() {
given: 'an endpoint'
@@ -101,6 +104,31 @@ class AdminRestControllerSpec extends Specification {
response.status == HttpStatus.CONFLICT.value()
}
+ def 'Get a dataspace.'() {
+ given: 'service method returns a dataspace'
+ mockCpsAdminService.getDataspace(dataspaceName) >> dataspace
+ and: 'an endpoint'
+ def getDataspaceEndpoint = "$basePath/v1/admin/dataspaces/$dataspaceName"
+ when: 'get dataspace API is invoked'
+ def response = mvc.perform(get(getDataspaceEndpoint)).andReturn().response
+ then: 'the correct dataspace is returned'
+ response.status == HttpStatus.OK.value()
+ response.getContentAsString().contains(dataspaceName)
+ }
+
+ def 'Get all dataspaces.'() {
+ given: 'service method returns all dataspace'
+ mockCpsAdminService.getAllDataspaces() >> [dataspace, new Dataspace(name: "dataspace-test2")]
+ and: 'an endpoint'
+ def getAllDataspaceEndpoint = "$basePath/v1/admin/dataspaces"
+ when: 'get all dataspace API is invoked'
+ def response = mvc.perform(get(getAllDataspaceEndpoint)).andReturn().response
+ then: 'the correct dataspace is returned'
+ response.status == HttpStatus.OK.value()
+ response.getContentAsString().contains(dataspaceName)
+ response.getContentAsString().contains("dataspace-test2")
+ }
+
def 'Create schema set from yang file.'() {
def yangResourceMapCapture
given: 'single yang file'