From: leventecsanyi Date: Tue, 24 Jun 2025 07:33:11 +0000 (+0100) Subject: Remove private properties from the response whem the value is null X-Git-Url: https://gerrit.onap.org/r/gitweb?a=commitdiff_plain;h=refs%2Fchanges%2F70%2F141370%2F5;p=cps.git Remove private properties from the response whem the value is null - Fixed openapi and unit test Issue-ID:CPS-1872 Change-Id: I6c4465fd79249861814a56c6fb02e4d5cf854928 Signed-off-by: ToineSiebelink Signed-off-by: leventecsanyi --- diff --git a/cps-ncmp-rest/docs/openapi/components.yaml b/cps-ncmp-rest/docs/openapi/components.yaml index 835cfc29e2..25b65750be 100644 --- a/cps-ncmp-rest/docs/openapi/components.yaml +++ b/cps-ncmp-rest/docs/openapi/components.yaml @@ -255,12 +255,13 @@ components: example: my-cm-handle1 publicCmHandleProperties: type: object + nullable: true items: type: object additionalProperties: type: string example: '3gpp Type' - privateCmHandleProperties: + cmHandleProperties: type: object additionalProperties: type: string diff --git a/cps-ncmp-rest/docs/openapi/ncmp-inventory.yml b/cps-ncmp-rest/docs/openapi/ncmp-inventory.yml index 4aa977e0cc..f8013b6f47 100755 --- a/cps-ncmp-rest/docs/openapi/ncmp-inventory.yml +++ b/cps-ncmp-rest/docs/openapi/ncmp-inventory.yml @@ -157,9 +157,9 @@ searchCmHandles: summary: Query Cm Handles for a requested DMI Service operationId: searchCmHandles parameters: - - name: includePrivatePropertiesInQuery + - name: includeCmHandlePropertiesInQuery in: query - description: Whether to include private properties in the response. + description: Whether to include additional properties in the response. required: false schema: type: boolean diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java index a3b40864f5..e8cc0b9234 100644 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryController.java @@ -83,20 +83,20 @@ public class NetworkCmProxyInventoryController implements NetworkCmProxyInventor * Execute cm handle query search and return a list of cm handle details. Any number of conditions can be applied. * * @param cmHandleQueryParameters the cm handle query parameters - * @param includeAdditionalProperties boolean value to determine the inclusion of additional properties + * @param includeCmHandlePropertiesInQuery boolean value to determine the inclusion of additional properties * @return collection of cm handles */ @Override public ResponseEntity> searchCmHandles( final CmHandleQueryParameters cmHandleQueryParameters, - final Boolean includeAdditionalProperties) { + final Boolean includeCmHandlePropertiesInQuery) { final CmHandleQueryApiParameters cmHandleQueryApiParameters = deprecationHelper.mapOldConditionProperties(cmHandleQueryParameters); - final boolean includeAdditionalPropertiesParameter = Boolean.TRUE.equals(includeAdditionalProperties); + final boolean includeCmHandlePropertiesParameter = Boolean.TRUE.equals(includeCmHandlePropertiesInQuery); final List restOutputCmHandles = networkCmProxyInventoryFacade.executeCmHandleInventorySearch(cmHandleQueryApiParameters) .map(handle -> restOutputCmHandleMapper - .toRestOutputCmHandle(handle, includeAdditionalPropertiesParameter)) + .toRestOutputCmHandle(handle, includeCmHandlePropertiesParameter)) .collectList().block(); return ResponseEntity.ok(restOutputCmHandles); } diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/RestOutputCmHandleMapper.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/RestOutputCmHandleMapper.java index 685b0d5cc4..32d87167e4 100644 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/RestOutputCmHandleMapper.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/util/RestOutputCmHandleMapper.java @@ -47,7 +47,9 @@ public class RestOutputCmHandleMapper { restOutputCmHandle.setPublicCmHandleProperties( Collections.singletonList(ncmpServiceCmHandle.getPublicProperties())); if (includeAdditionalProperties) { - restOutputCmHandle.setPrivateCmHandleProperties(ncmpServiceCmHandle.getAdditionalProperties()); + restOutputCmHandle.setCmHandleProperties(ncmpServiceCmHandle.getAdditionalProperties()); + } else { + restOutputCmHandle.setCmHandleProperties(null); } restOutputCmHandle.setState( cmHandleStateMapper.toCmHandleCompositeStateExternalLockReason( @@ -60,4 +62,4 @@ public class RestOutputCmHandleMapper { restOutputCmHandle.setDataProducerIdentifier(ncmpServiceCmHandle.getDataProducerIdentifier()); return restOutputCmHandle; } -} \ No newline at end of file +} diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy index 8e55bbbc3d..366d1af920 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/controller/NetworkCmProxyInventoryControllerSpec.groovy @@ -270,7 +270,7 @@ class NetworkCmProxyInventoryControllerSpec extends Specification { def 'Get a cm handle by DMI service name.'() { given: 'an endpoint for returning cm handles by dmi service name' - def postUrl = "$ncmpBasePathV1/ch/searchCmHandles?includePrivatePropertiesInQuery=true" + def postUrl = "$ncmpBasePathV1/ch/searchCmHandles?includeCmHandlePropertiesInQuery=true" String jsonString = TestUtils.getResourceFileContent('cm-handle-search-by-dmi-service.json') and: 'a cm handle is returned' def ncmpServiceCmHandle = new NcmpServiceCmHandle(additionalProperties: ['someName': 'my dmi']) diff --git a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/RestOutputCmHandleMapperSpec.groovy b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/RestOutputCmHandleMapperSpec.groovy index 019053778c..50e2fd4f49 100644 --- a/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/RestOutputCmHandleMapperSpec.groovy +++ b/cps-ncmp-rest/src/test/groovy/org/onap/cps/ncmp/rest/util/RestOutputCmHandleMapperSpec.groovy @@ -39,7 +39,9 @@ class RestOutputCmHandleMapperSpec extends Specification { when: 'the mapper function is called' def result = objectUnderTest.toRestOutputCmHandle(ncmpServiceCmHandle, includeAdditionalProperties) then: 'result has the expected properties' - assert result.privateCmHandleProperties.containsKey('additional property key') == includeAdditionalProperties + if (includeAdditionalProperties) { + assert result.cmHandleProperties.containsKey('additional property key') + } if (trustLevel != null) { assert result.trustLevel == trustLevel.toString() } diff --git a/docs/api/swagger/ncmp/openapi-inventory.yaml b/docs/api/swagger/ncmp/openapi-inventory.yaml index c00bc8b096..7e5b2b13a4 100644 --- a/docs/api/swagger/ncmp/openapi-inventory.yaml +++ b/docs/api/swagger/ncmp/openapi-inventory.yaml @@ -202,9 +202,9 @@ paths: this query. operationId: searchCmHandles parameters: - - description: Whether to include private properties in the response. + - description: Whether to include additional properties in the response. in: query - name: includePrivatePropertiesInQuery + name: includeCmHandlePropertiesInQuery required: false schema: type: boolean @@ -616,6 +616,8 @@ components: publicCmHandleProperties: - key: 3gpp Type - key: 3gpp Type + cmHandleProperties: + key: 3gpp Type state: dataSyncEnabled: false dataSyncState: @@ -632,8 +634,6 @@ components: lastUpdateTime: 2022-12-31T20:30:40.000+0000 trustLevel: COMPLETE moduleSetTag: my-module-set-tag - privateCmHandleProperties: - key: 3gpp Type properties: cmHandle: example: my-cm-handle1 @@ -644,8 +644,9 @@ components: example: 3gpp Type type: string type: object + nullable: true type: array - privateCmHandleProperties: + cmHandleProperties: additionalProperties: example: 3gpp Type type: string diff --git a/docs/api/swagger/ncmp/openapi.yaml b/docs/api/swagger/ncmp/openapi.yaml index 61d4e19d3e..0e5cd576c2 100644 --- a/docs/api/swagger/ncmp/openapi.yaml +++ b/docs/api/swagger/ncmp/openapi.yaml @@ -1937,6 +1937,8 @@ components: publicCmHandleProperties: - key: 3gpp Type - key: 3gpp Type + cmHandleProperties: + key: 3gpp Type state: dataSyncEnabled: false dataSyncState: @@ -1953,8 +1955,6 @@ components: lastUpdateTime: 2022-12-31T20:30:40.000+0000 trustLevel: COMPLETE moduleSetTag: my-module-set-tag - privateCmHandleProperties: - key: 3gpp Type properties: cmHandle: example: my-cm-handle1 @@ -1965,8 +1965,9 @@ components: example: 3gpp Type type: string type: object + nullable: true type: array - privateCmHandleProperties: + cmHandleProperties: additionalProperties: example: 3gpp Type type: string