diff options
Diffstat (limited to 'cps-ncmp-service/src')
5 files changed, 62 insertions, 98 deletions
diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java index 2f91ed30e1..cb2f78206c 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/NetworkCmProxyDataService.java @@ -114,16 +114,14 @@ public interface NetworkCmProxyDataService { * * @param cmHandle cm handle * @param resourceIdentifier resource identifier - * @param accept accept param - * @param fields fields query - * @param depth depth query + * @param acceptParamInHeader accept param + * @param optionsParamInQuery options query * @return {@code Object} resource data */ Object getResourceDataOperationalForCmHandle(@NotNull String cmHandle, @NotNull String resourceIdentifier, - String accept, - String fields, - Integer depth); + String acceptParamInHeader, + String optionsParamInQuery); /** * Get resource data for data store pass-through running @@ -131,16 +129,14 @@ public interface NetworkCmProxyDataService { * * @param cmHandle cm handle * @param resourceIdentifier resource identifier - * @param acceptParam accept param - * @param fields fields query - * @param depth depth query + * @param acceptParamInHeader accept param + * @param optionsParamInQuery options query * @return {@code Object} resource data */ Object getResourceDataPassThroughRunningForCmHandle(@NotNull String cmHandle, @NotNull String resourceIdentifier, - String acceptParam, - String fields, - Integer depth); + String acceptParamInHeader, + String optionsParamInQuery); /** * Create resource data for data store pass-through running diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java index 2395fb5db4..5594a2a7a5 100755 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImpl.java @@ -168,9 +168,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService @Override public Object getResourceDataOperationalForCmHandle(final @NotNull String cmHandle, final @NotNull String resourceIdentifier, - final String acceptParam, - final String fieldsQueryParam, - final Integer depthQueryParam) { + final String acceptParamInHeader, + final String optionsParamInQuery) { final DataNode cmHandleDataNode = fetchDataNodeFromDmiRegistryForCmHandle(cmHandle); final String dmiServiceName = String.valueOf(cmHandleDataNode.getLeaves().get(NCMP_DMI_SERVICE_NAME)); @@ -178,9 +177,8 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService final ResponseEntity<Object> response = dmiOperations.getResourceDataOperationalFromDmi(dmiServiceName, cmHandle, resourceIdentifier, - fieldsQueryParam, - depthQueryParam, - acceptParam, + optionsParamInQuery, + acceptParamInHeader, dmiRequestBody); return handleResponse(response); } @@ -188,18 +186,16 @@ public class NetworkCmProxyDataServiceImpl implements NetworkCmProxyDataService @Override public Object getResourceDataPassThroughRunningForCmHandle(final @NotNull String cmHandle, final @NotNull String resourceIdentifier, - final String acceptParam, - final String fields, - final Integer depth) { + final String acceptParamInHeader, + final String optionsParamInQuery) { final DataNode cmHandleDataNode = fetchDataNodeFromDmiRegistryForCmHandle(cmHandle); final String dmiServiceName = String.valueOf(cmHandleDataNode.getLeaves().get(NCMP_DMI_SERVICE_NAME)); final String dmiRequestBody = getGenericRequestBody(cmHandleDataNode); final ResponseEntity<Object> response = dmiOperations.getResourceDataPassThroughRunningFromDmi(dmiServiceName, cmHandle, resourceIdentifier, - fields, - depth, - acceptParam, + optionsParamInQuery, + acceptParamInHeader, dmiRequestBody); return handleResponse(response); } diff --git a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java index 71af3d4cfe..363b0ef9b2 100644 --- a/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java +++ b/cps-ncmp-service/src/main/java/org/onap/cps/ncmp/api/impl/operation/DmiOperations.java @@ -52,6 +52,9 @@ public class DmiOperations { private static final String DMI_CM_HANDLE_PATH = "/v1/ch/{cmHandle}"; private static final String DMI_CM_HANDLE_DATASTORE_PATH = DMI_CM_HANDLE_PATH + "/data/ds"; private static final String URL_SEPARATOR = "/"; + private static final String RESOURCE_IDENTIFIER = "resourceIdentifier"; + private static final String OPTIONS_QUERY_KEY = "options"; + /** * Constructor for {@code DmiOperations}. This method also manipulates url properties. @@ -102,22 +105,20 @@ public class DmiOperations { * @param dmiServiceName dmi service name * @param cmHandle network resource identifier * @param resourceId resource identifier - * @param fieldsQuery fields query - * @param depthQuery depth query - * @param acceptParam accept parameter + * @param optionsParamInQuery options query + * @param acceptParamInHeader accept parameter * @param jsonBody json body for put operation * @return {@code ResponseEntity} response entity */ public ResponseEntity<Object> getResourceDataOperationalFromDmi(final String dmiServiceName, final String cmHandle, final String resourceId, - final String fieldsQuery, - final Integer depthQuery, - final String acceptParam, + final String optionsParamInQuery, + final String acceptParamInHeader, final String jsonBody) { final var dmiResourceDataUrl = getDmiDatastoreUrl(dmiServiceName, cmHandle, resourceId, - fieldsQuery, depthQuery, DataStoreEnum.PASSTHROUGH_OPERATIONAL); - final var httpHeaders = prepareHeader(acceptParam); + optionsParamInQuery, DataStoreEnum.PASSTHROUGH_OPERATIONAL); + final var httpHeaders = prepareHeader(acceptParamInHeader); return dmiRestClient.putOperationWithJsonData(dmiResourceDataUrl, jsonBody, httpHeaders); } @@ -128,22 +129,20 @@ public class DmiOperations { * @param dmiServiceName dmi service name * @param cmHandle network resource identifier * @param resourceId resource identifier - * @param fieldsQuery fields query - * @param depthQuery depth query - * @param acceptParam accept parameter + * @param optionsParamInQuery fields query + * @param acceptParamInHeader accept parameter * @param jsonBody json body for put operation * @return {@code ResponseEntity} response entity */ public ResponseEntity<Object> getResourceDataPassThroughRunningFromDmi(final String dmiServiceName, final String cmHandle, final String resourceId, - final String fieldsQuery, - final Integer depthQuery, - final String acceptParam, + final String optionsParamInQuery, + final String acceptParamInHeader, final String jsonBody) { final var dmiResourceDataUrl = getDmiDatastoreUrl(dmiServiceName, cmHandle, resourceId, - fieldsQuery, depthQuery, DataStoreEnum.PASSTHROUGH_RUNNING); - final var httpHeaders = prepareHeader(acceptParam); + optionsParamInQuery, DataStoreEnum.PASSTHROUGH_RUNNING); + final var httpHeaders = prepareHeader(acceptParamInHeader); return dmiRestClient.putOperationWithJsonData(dmiResourceDataUrl, jsonBody, httpHeaders); } @@ -161,7 +160,7 @@ public class DmiOperations { final String cmHandle, final String resourceId, final String jsonBody) { - final var stringBuilder = getStringBuilderForPassThroughRunningUrl(dmiServiceName, + final var stringBuilder = getStringBuilderForPassThroughUrl(dmiServiceName, cmHandle, resourceId, DataStoreEnum.PASSTHROUGH_RUNNING); return dmiRestClient.postOperationWithJsonData(stringBuilder.toString(), jsonBody, new HttpHeaders()); } @@ -181,50 +180,35 @@ public class DmiOperations { private String getDmiDatastoreUrl(final String dmiServiceName, final String cmHandle, final String resourceId, - final String fieldsQuery, - final Integer depthQuery, + final String optionsParamInQuery, final DataStoreEnum dataStoreEnum) { - final var stringBuilder = getStringBuilderForPassThroughRunningUrl(dmiServiceName, + final var stringBuilder = getStringBuilderForPassThroughUrl(dmiServiceName, cmHandle, resourceId, dataStoreEnum); - appendFieldsAndDepth(stringBuilder, fieldsQuery, depthQuery); + appendOptionsQuery(stringBuilder, optionsParamInQuery); return stringBuilder.toString(); } @NotNull - private StringBuilder getStringBuilderForPassThroughRunningUrl(final String dmiServiceName, - final String cmHandle, - final String resourceId, - final DataStoreEnum dataStoreEnum) { + private StringBuilder getStringBuilderForPassThroughUrl(final String dmiServiceName, + final String cmHandle, + final String resourceId, + final DataStoreEnum dataStoreEnum) { final var stringBuilder = new StringBuilder(dmiServiceName); stringBuilder.append(DMI_API_PATH); stringBuilder.append(DMI_CM_HANDLE_DATASTORE_PATH.replace("{cmHandle}", cmHandle)); stringBuilder.append(URL_SEPARATOR + dataStoreEnum.getValue()); - stringBuilder.append(URL_SEPARATOR + resourceId); + stringBuilder.append("?" + RESOURCE_IDENTIFIER + "=" + resourceId); return stringBuilder; } - private void appendFieldsAndDepth(final StringBuilder stringBuilder, - final String fieldsQuery, - final Integer depthQuery) { - final var doesFieldExists = (fieldsQuery != null && !fieldsQuery.isEmpty()); - if (doesFieldExists) { - stringBuilder.append("?").append("fields=").append(fieldsQuery); - } - if (depthQuery != null) { - if (doesFieldExists) { - stringBuilder.append("&"); - } else { - stringBuilder.append("?"); - } - stringBuilder.append("depth=").append(depthQuery); - } + private void appendOptionsQuery(final StringBuilder stringBuilder, + final String optionsParamInQuery) { + stringBuilder.append("&").append(OPTIONS_QUERY_KEY).append("=").append(optionsParamInQuery); } private HttpHeaders prepareHeader(final String acceptParam) { final var httpHeaders = new HttpHeaders(); - if (acceptParam != null && !acceptParam.isEmpty()) { - httpHeaders.set(HttpHeaders.ACCEPT, acceptParam); - } + httpHeaders.set(HttpHeaders.ACCEPT, acceptParam); return httpHeaders; } } diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy index e38386fdd2..b5d4713959 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/NetworkCmProxyDataServiceImplSpec.groovy @@ -231,16 +231,14 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { mockDmiOperations.getResourceDataOperationalFromDmi('testDmiService', 'testCmHandle', 'testResourceId', - 'testFieldQuery', - 5, + '(a=1,b=2)', 'testAcceptParam', '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}') >> new ResponseEntity<>('result-json', HttpStatus.OK) when: 'get resource data is called' def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle', 'testResourceId', 'testAcceptParam', - 'testFieldQuery', - 5) + '(a=1,b=2)') then: 'dmi returns ok response' response == 'result-json' } @@ -259,8 +257,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle', 'testResourceId', 'testAcceptParam', - 'testFieldQuery', - 5) + '(a=1,b=2)') then: 'exception is thrown with the expected details' def exceptionThrown = thrown(NcmpException.class) exceptionThrown.details == 'testException' @@ -276,8 +273,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { mockDmiOperations.getResourceDataOperationalFromDmi('testDmiService', 'testCmHandle', 'testResourceId', - 'testFieldQuery', - 5, + '(a=1,b=2)', 'testAcceptParam', '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}') >> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND) @@ -285,8 +281,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def response = objectUnderTest.getResourceDataOperationalForCmHandle('testCmHandle', 'testResourceId', 'testAcceptParam', - 'testFieldQuery', - 5) + '(a=1,b=2)') then: 'exception is thrown' def exceptionThrown = thrown(NcmpException.class) and: 'details contains the original response' @@ -303,16 +298,14 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { mockDmiOperations.getResourceDataPassThroughRunningFromDmi('testDmiService', 'testCmHandle', 'testResourceId', - 'testFieldQuery', - 5, + '(a=1,b=2)', 'testAcceptParam', '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}') >> new ResponseEntity<>('{result-json}', HttpStatus.OK) when: 'get resource data is called' def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle', 'testResourceId', 'testAcceptParam', - 'testFieldQuery', - 5) + '(a=1,b=2)') then: 'get resource data returns expected response' response == '{result-json}' } @@ -331,8 +324,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle', 'testResourceId', 'testAcceptParam', - 'testFieldQuery', - 5) + '(a=1,b=2)') then: 'exception is thrown with the expected details' def exceptionThrown = thrown(NcmpException.class) exceptionThrown.details == 'testException' @@ -348,8 +340,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { mockDmiOperations.getResourceDataPassThroughRunningFromDmi('testDmiService', 'testCmHandle', 'testResourceId', - 'testFieldQuery', - 5, + '(a=1,b=2)', 'testAcceptParam', '{"operation":"read","cmHandleProperties":{"testName":"testValue"}}') >> new ResponseEntity<>('NOK-json', HttpStatus.NOT_FOUND) @@ -357,8 +348,7 @@ class NetworkCmProxyDataServiceImplSpec extends Specification { def response = objectUnderTest.getResourceDataPassThroughRunningForCmHandle('testCmHandle', 'testResourceId', 'testAcceptParam', - 'testFieldQuery', - 5) + '(a=1,b=2)') then: 'exception is thrown' def exceptionThrown = thrown(NcmpException.class) and: 'details contains the original response' diff --git a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy index 6a1ce1a18b..8e0fb76a56 100644 --- a/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy +++ b/cps-ncmp-service/src/test/groovy/org/onap/cps/ncmp/api/impl/operation/DmiOperationsSpec.groovy @@ -42,13 +42,12 @@ class DmiOperationsSpec extends Specification { def 'call get resource data for pass-through:operational datastore from DMI.'() { given: 'expected url' def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' + - '/ncmp-datastore:passthrough-operational/testResourceId?fields=testFieldsQuery&depth=10' + '/ncmp-datastore:passthrough-operational?resourceIdentifier=parent/child&options=(a=1,b=2)' when: 'get resource data is called to DMI' objectUnderTest.getResourceDataOperationalFromDmi('testDmiBasePath', 'testCmhandle', - 'testResourceId', - 'testFieldsQuery', - 10, + 'parent/child', + '(a=1,b=2)', 'testAcceptJson', 'testJsonbody') then: 'the put operation is executed with the correct URL' @@ -57,13 +56,12 @@ class DmiOperationsSpec extends Specification { def 'call get resource data for pass-through:running datastore from DMI.'() { given: 'expected url' def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' + - '/ncmp-datastore:passthrough-running/testResourceId?fields=testFieldsQuery&depth=10' + '/ncmp-datastore:passthrough-running?resourceIdentifier=parent/child&options=(a=1,b=2)' when: 'get resource data is called to DMI' objectUnderTest.getResourceDataPassThroughRunningFromDmi('testDmiBasePath', 'testCmhandle', - 'testResourceId', - 'testFieldsQuery', - 10, + 'parent/child', + '(a=1,b=2)', 'testAcceptJson', 'testJsonbody') then: 'the put operation is executed with the correct URL' @@ -72,11 +70,11 @@ class DmiOperationsSpec extends Specification { def 'call create resource data for pass-through:running datastore from DMI.'() { given: 'expected url' def expectedUrl = 'testDmiBasePath/dmi/v1/ch/testCmhandle/data/ds' + - '/ncmp-datastore:passthrough-running/testResourceId' + '/ncmp-datastore:passthrough-running?resourceIdentifier=parent/child' when: 'get resource data is called to DMI' objectUnderTest.createResourceDataPassThroughRunningFromDmi('testDmiBasePath', 'testCmhandle', - 'testResourceId', + 'parent/child', 'testJsonbody') then: 'the put operation is executed with the correct URL' 1 * mockDmiRestClient.postOperationWithJsonData(expectedUrl, 'testJsonbody', _ as HttpHeaders) |