diff options
Diffstat (limited to 'cps-rest')
6 files changed, 190 insertions, 7 deletions
diff --git a/cps-rest/docs/openapi/components.yml b/cps-rest/docs/openapi/components.yml index 1a7e4308d9..43a311872a 100644 --- a/cps-rest/docs/openapi/components.yml +++ b/cps-rest/docs/openapi/components.yml @@ -1,7 +1,7 @@ # ============LICENSE_START======================================================= # Copyright (c) 2021-2022 Bell Canada. # Modifications Copyright (C) 2021-2023 Nordix Foundation -# Modifications Copyright (C) 2022-2024 TechMahindra Ltd. +# Modifications Copyright (C) 2022-2025 TechMahindra Ltd. # Modifications Copyright (C) 2022 Deutsche Telekom AG # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); @@ -157,7 +157,12 @@ components: name: "Funny" target-data: name: "Comic" - + NotificationSubscriptionsDataSample: + value: + cps-notification-subscriptions:dataspaces: + dataspace: + - name: dataspace01 + - name: dataspace02 parameters: dataspaceNameInQuery: name: dataspace-name @@ -236,6 +241,19 @@ components: value: /shops/bookstore list attributes xpath: value: /shops/bookstore/categories[@code=1] + notificationSubscriptionXpathInQuery: + name: xpath + in: query + description: For more details on xpath, please refer https://docs.onap.org/projects/onap-cps/en/latest/xpath.html + required: true + schema: + type: string + default: /dataspaces + examples: + subscription by dataspace xpath: + value: /dataspaces/dataspace[@name='dataspace01'] + subscription by anchor xpath: + value: /dataspaces/dataspace[@name='dataspace01']/anchors/anchor[@name='anchor01'] requiredXpathInQuery: name: xpath in: query diff --git a/cps-rest/docs/openapi/cpsAdminV2.yml b/cps-rest/docs/openapi/cpsAdminV2.yml index e501ad8b15..af2572a1f0 100644 --- a/cps-rest/docs/openapi/cpsAdminV2.yml +++ b/cps-rest/docs/openapi/cpsAdminV2.yml @@ -1,5 +1,5 @@ # ============LICENSE_START======================================================= -# Copyright (C) 2022 TechMahindra Ltd. +# Copyright (C) 2022-2025 TechMahindra Ltd. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -87,3 +87,75 @@ schemaSet: $ref: 'components.yml#/components/responses/Conflict' '500': $ref: 'components.yml#/components/responses/InternalServerError' + +notificationSubscription: + get: + description: Get cps notification subscription + tags: + - cps-admin + summary: Get cps notification subscription + operationId: getNotificationSubscription + parameters: + - $ref: 'components.yml#/components/parameters/notificationSubscriptionXpathInQuery' + responses: + '200': + description: OK + content: + application/json: + schema: + $ref: 'components.yml#/components/examples/NotificationSubscriptionsDataSample' + '400': + $ref: 'components.yml#/components/responses/BadRequest' + '403': + $ref: 'components.yml#/components/responses/Forbidden' + '409': + $ref: 'components.yml#/components/responses/Conflict' + '500': + $ref: 'components.yml#/components/responses/InternalServerError' + post: + description: Create cps notification subscription + tags: + - cps-admin + summary: Create cps notification subscription + operationId: createNotificationSubscription + parameters: + - $ref: 'components.yml#/components/parameters/notificationSubscriptionXpathInQuery' + requestBody: + required: true + content: + application/json: + schema: + type: object + examples: + dataSample: + $ref: 'components.yml#/components/examples/NotificationSubscriptionsDataSample' + responses: + '201': + $ref: 'components.yml#/components/responses/CreatedV2' + '400': + $ref: 'components.yml#/components/responses/BadRequest' + '403': + $ref: 'components.yml#/components/responses/Forbidden' + '409': + $ref: 'components.yml#/components/responses/Conflict' + '500': + $ref: 'components.yml#/components/responses/InternalServerError' + delete: + description: Delete cps notification subscription + tags: + - cps-admin + summary: Delete cps notification subscription + operationId: deleteNotificationSubscription + parameters: + - $ref: 'components.yml#/components/parameters/notificationSubscriptionXpathInQuery' + responses: + '204': + $ref: 'components.yml#/components/responses/NoContent' + '400': + $ref: 'components.yml#/components/responses/BadRequest' + '403': + $ref: 'components.yml#/components/responses/Forbidden' + '409': + $ref: 'components.yml#/components/responses/Conflict' + '500': + $ref: 'components.yml#/components/responses/InternalServerError'
\ No newline at end of file diff --git a/cps-rest/docs/openapi/openapi.yml b/cps-rest/docs/openapi/openapi.yml index c85bf7cac7..09c454b1da 100644 --- a/cps-rest/docs/openapi/openapi.yml +++ b/cps-rest/docs/openapi/openapi.yml @@ -2,7 +2,7 @@ # Copyright (C) 2021-2025 Nordix Foundation # Modifications Copyright (C) 2021 Pantheon.tech # Modifications Copyright (C) 2021 Bell Canada. -# Modifications Copyright (C) 2022-2024 TechMahindra Ltd. +# Modifications Copyright (C) 2022-2025 TechMahindra Ltd. # ================================================================================ # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -115,5 +115,8 @@ paths: /v2/dataspaces/{dataspace-name}/nodes/query: $ref: 'cpsQueryV2.yml#/nodesByDataspaceAndCpsPath' + /v2/notification-subscription: + $ref: 'cpsAdminV2.yml#/notificationSubscription' + security: - basicAuth: [] 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 4c6bd6cdc5..01a9746af0 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,7 +3,7 @@ * Copyright (C) 2020-2025 Nordix Foundation * Modifications Copyright (C) 2020-2021 Bell Canada. * Modifications Copyright (C) 2021 Pantheon.tech - * Modifications Copyright (C) 2022 TechMahindra Ltd. + * Modifications Copyright (C) 2022-2025 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,11 +31,13 @@ import jakarta.validation.Valid; import jakarta.validation.constraints.NotNull; import java.util.Collection; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import lombok.RequiredArgsConstructor; import org.onap.cps.api.CpsAnchorService; import org.onap.cps.api.CpsDataspaceService; import org.onap.cps.api.CpsModuleService; +import org.onap.cps.api.CpsNotificationService; import org.onap.cps.api.model.Anchor; import org.onap.cps.api.model.Dataspace; import org.onap.cps.api.model.SchemaSet; @@ -43,6 +45,7 @@ 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.utils.JsonObjectMapper; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; @@ -58,6 +61,8 @@ public class AdminRestController implements CpsAdminApi { private final CpsModuleService cpsModuleService; private final CpsRestInputMapper cpsRestInputMapper; private final CpsAnchorService cpsAnchorService; + private final CpsNotificationService cpsNotificationService; + private final JsonObjectMapper jsonObjectMapper; /** * Create a dataspace. @@ -280,4 +285,25 @@ public class AdminRestController implements CpsAdminApi { final DataspaceDetails dataspaceDetails = cpsRestInputMapper.toDataspaceDetails(dataspace); return new ResponseEntity<>(dataspaceDetails, HttpStatus.OK); } + + @Override + public ResponseEntity<Void> createNotificationSubscription(final String xpath, + final Object notificationSubscriptionAsJson) { + cpsNotificationService.createNotificationSubscription( + jsonObjectMapper.asJsonString(notificationSubscriptionAsJson), xpath); + return new ResponseEntity<>(HttpStatus.CREATED); + } + + @Override + public ResponseEntity<Void> deleteNotificationSubscription(final String xpath) { + cpsNotificationService.deleteNotificationSubscription(xpath); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + + @Override + public ResponseEntity<Object> getNotificationSubscription(final String xpath) { + final List<Map<String, Object>> dataMaps = cpsNotificationService.getNotificationSubscription(xpath); + return new ResponseEntity<>(jsonObjectMapper.asJsonString(dataMaps), 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 0d189783fd..6d1ca40cd9 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,7 +3,7 @@ * Copyright (C) 2020-2021 Pantheon.tech * Modifications Copyright (C) 2020-2021 Bell Canada. * Modifications Copyright (C) 2021-2025 Nordix Foundation - * Modifications Copyright (C) 2022 TechMahindra Ltd. + * Modifications Copyright (C) 2022-2025 TechMahindra Ltd. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -23,15 +23,26 @@ package org.onap.cps.rest.controller +import com.fasterxml.jackson.databind.ObjectMapper + +import static org.onap.cps.api.parameters.CascadeDeleteAllowed.CASCADE_DELETE_PROHIBITED +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.multipart +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put + import org.mapstruct.factory.Mappers import org.onap.cps.api.CpsAnchorService import org.onap.cps.api.CpsDataspaceService import org.onap.cps.api.CpsModuleService +import org.onap.cps.api.CpsNotificationService import org.onap.cps.api.exceptions.AlreadyDefinedException import org.onap.cps.api.exceptions.SchemaSetInUseException import org.onap.cps.api.model.Anchor import org.onap.cps.api.model.Dataspace import org.onap.cps.api.model.SchemaSet +import org.onap.cps.utils.JsonObjectMapper import org.spockframework.spring.SpringBean import org.springframework.beans.factory.annotation.Autowired import org.springframework.beans.factory.annotation.Value @@ -63,8 +74,15 @@ class AdminRestControllerSpec extends Specification { CpsAnchorService mockCpsAnchorService = Mock() @SpringBean + CpsNotificationService mockCpsNotificationService = Mock() + + @SpringBean CpsRestInputMapper cpsRestInputMapper = Mappers.getMapper(CpsRestInputMapper) + @SpringBean + JsonObjectMapper jsonObjectMapper = new JsonObjectMapper(new ObjectMapper()) + + @Autowired MockMvc mvc @@ -393,6 +411,48 @@ class AdminRestControllerSpec extends Specification { response.status == HttpStatus.NO_CONTENT.value() } + def 'Add notification subscription'() { + given: 'an endpoint and its payload' + def notificationSubscriptionEndpoint = "$basePath/v2/notification-subscription" + def xpath = '/dataspaces' + def jsonPayload = '{"dataspace":[{"name":"ds01"}]}' + when: 'post request is performed' + def response = + mvc.perform( + post(notificationSubscriptionEndpoint) + .contentType(MediaType.APPLICATION_JSON) + .content(jsonPayload)) + .andReturn().response + then: 'notification service method is invoked with expected parameter' + 1 * mockCpsNotificationService.createNotificationSubscription(jsonPayload, xpath) + and: 'HTTP response code indicates success' + response.status == HttpStatus.CREATED.value() + } + + def 'delete notification subscription'() { + given: 'an endpoint and xpath' + def notificationSubscriptionEndpoint = "$basePath/v2/notification-subscription" + def xpath = '/dataspaces' + when: 'delete request is performed' + def response = mvc.perform(delete(notificationSubscriptionEndpoint).param('xpath', xpath)).andReturn().response + then: 'notification service method is invoked with expected parameter' + 1 * mockCpsNotificationService.deleteNotificationSubscription(xpath) + and: 'HTTP response code indicates success' + response.status == HttpStatus.NO_CONTENT.value() + } + + def 'Get notification subscription.'() { + given: 'an endpoint and xpath' + def notificationSubscriptionEndpoint = "$basePath/v2/notification-subscription" + def xpath = '/dataspaces' + when: 'get notification subscription is invoked' + def response = mvc.perform(get(notificationSubscriptionEndpoint).param('xpath', xpath)).andReturn().response + then: 'HTTP response code indicates success' + response.status == HttpStatus.OK.value() + and: 'notification service is called with proper parameters' + 1 * mockCpsNotificationService.getNotificationSubscription(xpath) + } + def createMultipartFile(filename, content) { return new MockMultipartFile("file", filename, "text/plain", content.getBytes()) } diff --git a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy index f0fc4cca62..4e1d27cda2 100644 --- a/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy +++ b/cps-rest/src/test/groovy/org/onap/cps/rest/exceptions/CpsRestExceptionHandlerSpec.groovy @@ -3,7 +3,7 @@ * Copyright (C) 2020 Pantheon.tech * Modifications Copyright (C) 2021-2023 Nordix Foundation * Modifications Copyright (C) 2021 Bell Canada. - * Modifications Copyright (C) 2022 TechMahindra Ltd. + * Modifications Copyright (C) 2022-2025 TechMahindra Ltd. * Modifications Copyright (C) 2022 Deutsche Telekom AG * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); @@ -30,6 +30,7 @@ import org.onap.cps.api.CpsDataspaceService import org.onap.cps.api.CpsAnchorService import org.onap.cps.api.CpsDataService import org.onap.cps.api.CpsModuleService +import org.onap.cps.api.CpsNotificationService import org.onap.cps.api.CpsQueryService import org.onap.cps.rest.controller.CpsRestInputMapper import org.onap.cps.api.exceptions.AlreadyDefinedException @@ -87,6 +88,9 @@ class CpsRestExceptionHandlerSpec extends Specification { @SpringBean PrefixResolver prefixResolver = Mock() + @SpringBean + CpsNotificationService mockCpsNotificationService = Mock() + @Autowired MockMvc mvc |