summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrajesh.kumar <rk00747546@techmahindra.com>2022-09-06 11:47:18 +0000
committerrajesh.kumar <rk00747546@techmahindra.com>2022-11-18 06:37:38 +0000
commitcec0cb7254ede8a790ec6f70ad5e31d10e2d32d7 (patch)
tree07e240bf7e384290b7bff198395e50af51eea994
parentd2a1f36a78fdc69d43b39f0a7852d47d78924ed5 (diff)
Added get APIs for dataspace.
Issue-ID: CPS-1186 Change-ID: I73f97f986a817d423f93a8d922dcd9647b0829aa Signed-off-by: rajesh.kumar <rk00747546@techmahindra.com>
-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
-rwxr-xr-xcps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java19
-rw-r--r--cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy28
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/CpsAdminService.java18
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java13
-rwxr-xr-xcps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java17
-rw-r--r--cps-service/src/main/java/org/onap/cps/spi/model/Dataspace.java42
-rwxr-xr-xcps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy18
-rw-r--r--docs/api/swagger/cps/openapi.yaml127
14 files changed, 399 insertions, 2 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'
diff --git a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
index 20a39f98e3..2cebfc72c0 100755
--- a/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
+++ b/cps-ri/src/main/java/org/onap/cps/spi/impl/CpsAdminPersistenceServiceImpl.java
@@ -3,6 +3,7 @@
* Copyright (C) 2020-2022 Nordix Foundation.
* Modifications Copyright (C) 2020-2022 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.
@@ -39,6 +40,7 @@ import org.onap.cps.spi.exceptions.DataspaceInUseException;
import org.onap.cps.spi.exceptions.DataspaceNotFoundException;
import org.onap.cps.spi.exceptions.ModuleNamesNotFoundException;
import org.onap.cps.spi.model.Anchor;
+import org.onap.cps.spi.model.Dataspace;
import org.onap.cps.spi.repository.AnchorRepository;
import org.onap.cps.spi.repository.DataspaceRepository;
import org.onap.cps.spi.repository.SchemaSetRepository;
@@ -82,6 +84,19 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
}
@Override
+ public Dataspace getDataspace(final String dataspaceName) {
+ final DataspaceEntity dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
+ return toDataspace(dataspaceEntity);
+ }
+
+ @Override
+ public Collection<Dataspace> getAllDataspaces() {
+ final Collection<DataspaceEntity> dataspaceEntities = dataspaceRepository.findAll();
+ return dataspaceEntities.stream().map(CpsAdminPersistenceServiceImpl::toDataspace)
+ .collect(Collectors.toSet());
+ }
+
+ @Override
public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) {
final var dataspaceEntity = dataspaceRepository.getByName(dataspaceName);
final var schemaSetEntity =
@@ -155,6 +170,10 @@ public class CpsAdminPersistenceServiceImpl implements CpsAdminPersistenceServic
.build();
}
+ private static Dataspace toDataspace(final DataspaceEntity dataspaceEntity) {
+ return Dataspace.builder().name(dataspaceEntity.getName()).build();
+ }
+
private void validateDataspaceAndModuleNames(final String dataspaceName,
final Collection<String> inputModuleNames) {
final Collection<String> retrievedModuleReferences =
diff --git a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy
index cdb3e6c735..99d44aac89 100644
--- a/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy
+++ b/cps-ri/src/test/groovy/org/onap/cps/spi/impl/CpsAdminPersistenceServiceSpec.groovy
@@ -3,6 +3,7 @@
* Copyright (C) 2021-2022 Nordix Foundation
* Modifications Copyright (C) 2021 Pantheon.tech
* Modifications Copyright (C) 2022 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.
@@ -30,6 +31,7 @@ import org.onap.cps.spi.exceptions.DataspaceInUseException
import org.onap.cps.spi.exceptions.DataspaceNotFoundException
import org.onap.cps.spi.exceptions.SchemaSetNotFoundException
import org.onap.cps.spi.model.Anchor
+import org.onap.cps.spi.model.Dataspace
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.test.context.jdbc.Sql
import org.testcontainers.shaded.com.fasterxml.jackson.databind.ObjectMapper
@@ -68,6 +70,32 @@ class CpsAdminPersistenceServiceSpec extends CpsPersistenceSpecBase {
}
@Sql([CLEAR_DATA, SET_DATA])
+ def 'Get a dataspace.'() {
+ when: 'dataspace is retrieved'
+ def dataspace = objectUnderTest.getDataspace(DATASPACE_NAME)
+ then: ' the response contains expected dataspace'
+ assert dataspace.getName().equals(DATASPACE_NAME);
+ }
+
+ @Sql([CLEAR_DATA, SET_DATA])
+ def 'Get all dataspaces.'() {
+ when: 'all dataspaces are retrieved'
+ def dataspaces = objectUnderTest.getAllDataspaces()
+ then: 'the response contains expected dataspaces'
+ def expectedDataspaces = Set.of(new Dataspace(name: 'DATASPACE-001'), new Dataspace(name: 'DATASPACE-002-NO-DATA'),
+ new Dataspace(name: 'DATASPACE-003'))
+ assert dataspaces == expectedDataspaces
+ }
+
+ @Sql([CLEAR_DATA, SET_DATA])
+ def 'Get non existing dataspace.'() {
+ when: 'attempting to retrieve a non-existing dataspace'
+ def dataspace = objectUnderTest.getDataspace('non_existing_dataspace')
+ then: 'an DataspaceNotFoundException is thrown'
+ thrown(DataspaceNotFoundException)
+ }
+
+ @Sql([CLEAR_DATA, SET_DATA])
def 'Create and retrieve a new anchor.'() {
when: 'a new anchor is created'
def newAnchorName = 'my-new-anchor'
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 ab3373248a..b0e68cf8fb 100755
--- a/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java
+++ b/cps-service/src/main/java/org/onap/cps/api/CpsAdminService.java
@@ -3,6 +3,7 @@
* Copyright (C) 2020-2022 Nordix Foundation
* Modifications Copyright (C) 2020-2022 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.
@@ -26,6 +27,7 @@ import java.util.Collection;
import org.onap.cps.spi.exceptions.AlreadyDefinedException;
import org.onap.cps.spi.exceptions.CpsException;
import org.onap.cps.spi.model.Anchor;
+import org.onap.cps.spi.model.Dataspace;
/**
* CPS Admin Service.
@@ -48,6 +50,22 @@ public interface CpsAdminService {
void deleteDataspace(String dataspaceName);
/**
+ * Get dataspace by given dataspace name.
+ *
+ * @param dataspaceName dataspace name
+ * @return a dataspace
+ */
+ Dataspace getDataspace(String dataspaceName);
+
+ /**
+ * Get All Dataspaces.
+ *
+ *
+ * @return a collection of dataspaces
+ */
+ Collection<Dataspace> getAllDataspaces();
+
+ /**
* Create an Anchor.
*
* @param dataspaceName dataspace name
diff --git a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java
index 56f424164f..ece3eb95c9 100755
--- a/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java
+++ b/cps-service/src/main/java/org/onap/cps/api/impl/CpsAdminServiceImpl.java
@@ -3,6 +3,7 @@
* Copyright (C) 2020-2022 Nordix Foundation
* Modifications Copyright (C) 2020-2022 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.
@@ -30,6 +31,7 @@ import org.onap.cps.api.CpsAdminService;
import org.onap.cps.api.CpsDataService;
import org.onap.cps.spi.CpsAdminPersistenceService;
import org.onap.cps.spi.model.Anchor;
+import org.onap.cps.spi.model.Dataspace;
import org.onap.cps.spi.utils.CpsValidator;
import org.springframework.context.annotation.Lazy;
import org.springframework.stereotype.Component;
@@ -56,6 +58,17 @@ public class CpsAdminServiceImpl implements CpsAdminService {
}
@Override
+ public Dataspace getDataspace(final String dataspaceName) {
+ cpsValidator.validateNameCharacters(dataspaceName);
+ return cpsAdminPersistenceService.getDataspace(dataspaceName);
+ }
+
+ @Override
+ public Collection<Dataspace> getAllDataspaces() {
+ return cpsAdminPersistenceService.getAllDataspaces();
+ }
+
+ @Override
public void createAnchor(final String dataspaceName, final String schemaSetName, final String anchorName) {
cpsValidator.validateNameCharacters(dataspaceName, schemaSetName, anchorName);
cpsAdminPersistenceService.createAnchor(dataspaceName, schemaSetName, anchorName);
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 db2d2b2d49..6bcb69844d 100755
--- a/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java
+++ b/cps-service/src/main/java/org/onap/cps/spi/CpsAdminPersistenceService.java
@@ -3,6 +3,7 @@
* Copyright (C) 2020-2022 Nordix Foundation.
* Modifications Copyright (C) 2020-2022 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.
@@ -25,6 +26,7 @@ package org.onap.cps.spi;
import java.util.Collection;
import org.onap.cps.spi.exceptions.AlreadyDefinedException;
import org.onap.cps.spi.model.Anchor;
+import org.onap.cps.spi.model.Dataspace;
/*
Service for handling CPS admin data.
@@ -47,6 +49,21 @@ public interface CpsAdminPersistenceService {
void deleteDataspace(String dataspaceName);
/**
+ * Get dataspace.
+ *
+ * @param dataspaceName dataspace name
+ * @return a dataspace
+ */
+ Dataspace getDataspace(String dataspaceName);
+
+ /**
+ * Get all dataspaces.
+ *
+ * @return a collection of dataspaces.
+ */
+ Collection<Dataspace> getAllDataspaces();
+
+ /**
* Create an Anchor.
*
* @param dataspaceName dataspace name
diff --git a/cps-service/src/main/java/org/onap/cps/spi/model/Dataspace.java b/cps-service/src/main/java/org/onap/cps/spi/model/Dataspace.java
new file mode 100644
index 0000000000..23c6d69063
--- /dev/null
+++ b/cps-service/src/main/java/org/onap/cps/spi/model/Dataspace.java
@@ -0,0 +1,42 @@
+/*
+ * ============LICENSE_START=======================================================
+ * 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.
+ * 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 lombok.AllArgsConstructor;
+import lombok.Builder;
+import lombok.EqualsAndHashCode;
+import lombok.Getter;
+import lombok.NoArgsConstructor;
+import lombok.Setter;
+
+@Setter
+@Getter
+@Builder
+@NoArgsConstructor
+@AllArgsConstructor
+@EqualsAndHashCode
+public class Dataspace implements Serializable {
+
+ private static final long serialVersionUID = 1464791062718603291L;
+
+ private String name;
+}
diff --git a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy
index 2979c09866..e7d4e4ddb1 100755
--- a/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy
+++ b/cps-service/src/test/groovy/org/onap/cps/api/impl/CpsAdminServiceImplSpec.groovy
@@ -3,6 +3,7 @@
* Copyright (C) 2020-2022 Nordix Foundation
* Modifications Copyright (C) 2020-2022 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.
@@ -25,6 +26,7 @@ package org.onap.cps.api.impl
import org.onap.cps.api.CpsDataService
import org.onap.cps.spi.CpsAdminPersistenceService
import org.onap.cps.spi.model.Anchor
+import org.onap.cps.spi.model.Dataspace
import org.onap.cps.spi.utils.CpsValidator
import spock.lang.Specification
import java.time.OffsetDateTime
@@ -89,6 +91,22 @@ class CpsAdminServiceImplSpec extends Specification {
1 * mockCpsValidator.validateNameCharacters('someDataspace', 'someAnchor')
}
+ def 'Retrieve dataspace.'() {
+ given: 'a dataspace is already created'
+ def dataspace = new Dataspace(name: "someDataspace")
+ mockCpsAdminPersistenceService.getDataspace('someDataspace') >> dataspace
+ expect: 'the dataspace provided by persistence service is returned as result'
+ assert objectUnderTest.getDataspace('someDataspace') == dataspace
+ }
+
+ def 'Retrieve all dataspaces.'() {
+ given: 'that all given dataspaces are already created'
+ def dataspaces = [new Dataspace(name: "test-dataspace1"), new Dataspace(name: "test-dataspace2")]
+ mockCpsAdminPersistenceService.getAllDataspaces() >> dataspaces
+ expect: 'the dataspace provided by persistence service is returned as result'
+ assert objectUnderTest.getAllDataspaces() == dataspaces
+ }
+
def 'Delete anchor.'() {
when: 'delete anchor is invoked'
objectUnderTest.deleteAnchor('someDataspace','someAnchor')
diff --git a/docs/api/swagger/cps/openapi.yaml b/docs/api/swagger/cps/openapi.yaml
index e8f13d4df9..8ea0d7b03e 100644
--- a/docs/api/swagger/cps/openapi.yaml
+++ b/docs/api/swagger/cps/openapi.yaml
@@ -163,6 +163,124 @@ paths:
status: 500
message: Internal Server Error
details: Internal Server Error occurred
+ /v1/admin/dataspaces:
+ get:
+ tags:
+ - cps-admin
+ summary: Get dataspaces
+ description: "Read all dataspaces"
+ operationId: getAllDataspaces
+ responses:
+ "200":
+ description: OK
+ content:
+ application/json:
+ schema:
+ type: array
+ items:
+ $ref: '#/components/schemas/DataspaceDetails'
+ "400":
+ description: Bad Request
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ErrorMessage'
+ example:
+ status: 400
+ message: Bad Request
+ details: The provided request is not valid
+ "401":
+ description: Unauthorized
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ErrorMessage'
+ example:
+ status: 401
+ message: Unauthorized request
+ details: This request is unauthorized
+ "403":
+ description: Forbidden
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ErrorMessage'
+ example:
+ status: 403
+ message: Request Forbidden
+ details: This request is forbidden
+ "500":
+ description: Internal Server Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ErrorMessage'
+ example:
+ status: 500
+ message: Internal Server Error
+ details: Internal Server Error occurred
+ /v1/admin/dataspaces/{dataspace-name}:
+ get:
+ tags:
+ - cps-admin
+ summary: Get a dataspace
+ description: Read an dataspace given a dataspace name
+ operationId: getDataspace
+ parameters:
+ - name: dataspace-name
+ in: path
+ description: dataspace-name
+ required: true
+ schema:
+ type: string
+ example: my-dataspace
+ responses:
+ "200":
+ description: OK
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/DataspaceDetails'
+ "400":
+ description: Bad Request
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ErrorMessage'
+ example:
+ status: 400
+ message: Bad Request
+ details: The provided request is not valid
+ "401":
+ description: Unauthorized
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ErrorMessage'
+ example:
+ status: 401
+ message: Unauthorized request
+ details: This request is unauthorized
+ "403":
+ description: Forbidden
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ErrorMessage'
+ example:
+ status: 403
+ message: Request Forbidden
+ details: This request is forbidden
+ "500":
+ description: Internal Server Error
+ content:
+ application/json:
+ schema:
+ $ref: '#/components/schemas/ErrorMessage'
+ example:
+ status: 500
+ message: Internal Server Error
+ details: Internal Server Error occurred
/v1/dataspaces/{dataspace-name}/anchors:
get:
tags:
@@ -1565,6 +1683,13 @@ components:
schemaSetName:
type: string
example: my-schema-set
+ DataspaceDetails:
+ title: Dataspace details by dataspace Name
+ type: object
+ properties:
+ name:
+ type: string
+ example: my-dataspace
MultipartFile:
required:
- file
@@ -1615,4 +1740,4 @@ components:
name: kids
security:
- - basicAuth: [] \ No newline at end of file
+ - basicAuth: []