diff options
Diffstat (limited to 'src/main/java/org/onap')
4 files changed, 73 insertions, 88 deletions
diff --git a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java index 2c2536ff..b17280ae 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/rest/controller/DmiRestController.java @@ -20,18 +20,16 @@ package org.onap.cps.ncmp.dmi.rest.controller; -import static org.onap.cps.ncmp.dmi.model.DmiModuleReadRequestBody.OperationEnum.READ; - import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import java.util.List; import javax.validation.Valid; -import javax.validation.constraints.Min; import lombok.extern.slf4j.Slf4j; import org.onap.cps.ncmp.dmi.model.CmHandles; import org.onap.cps.ncmp.dmi.model.DataAccessReadRequest; import org.onap.cps.ncmp.dmi.model.DataAccessWriteRequest; -import org.onap.cps.ncmp.dmi.model.DmiModuleReadRequestBody; +import org.onap.cps.ncmp.dmi.model.ModuleReferencesRequest; +import org.onap.cps.ncmp.dmi.model.ModuleResourcesReadRequest; import org.onap.cps.ncmp.dmi.model.ModuleSet; import org.onap.cps.ncmp.dmi.model.YangResources; import org.onap.cps.ncmp.dmi.rest.api.DmiPluginApi; @@ -59,8 +57,8 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi { } @Override - public ResponseEntity<ModuleSet> getModulesForCmHandle(final String cmHandle, - final @Valid DataAccessReadRequest body) { + public ResponseEntity<ModuleSet> getModuleReferences(final String cmHandle, + final @Valid ModuleReferencesRequest body) { // For onap-dmi-plugin we don't need cmHandleProperties, so DataAccessReadRequest is not used. final var moduleSet = dmiService.getModulesForCmHandle(cmHandle); return ResponseEntity.ok(moduleSet); @@ -68,14 +66,11 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi { @Override public ResponseEntity<YangResources> retrieveModuleResources( - final @Valid DmiModuleReadRequestBody dmiModuleReadRequestBody, - final String cmHandle) { - if (READ.equals(dmiModuleReadRequestBody.getOperation())) { - final var moduleReferenceList = convertRestObjectToJavaApiObject(dmiModuleReadRequestBody); - final var response = dmiService.getModuleResources(cmHandle, moduleReferenceList); - return new ResponseEntity<>(response, HttpStatus.OK); - } - return new ResponseEntity<>(HttpStatus.CONFLICT); + final @Valid ModuleResourcesReadRequest moduleResourcesReadRequest, + final String cmHandle) { + final List<ModuleReference> moduleReferences = convertRestObjectToJavaApiObject(moduleResourcesReadRequest); + final YangResources yangResources = dmiService.getModuleResources(cmHandle, moduleReferences); + return new ResponseEntity<>(yangResources, HttpStatus.OK); } /** @@ -114,64 +109,58 @@ public class DmiRestController implements DmiPluginApi, DmiPluginInternalApi { /** * This method fetches the resource for given cm handle using pass through operational. It filters the response on - * the basis of depth and field query parameters and returns response. + * the basis of options query parameters and returns response. * * @param resourceIdentifier resource identifier to fetch data * @param cmHandle cm handle identifier * @param dataAccessReadRequest data Access Read Request - * @param accept accept header parameter - * @param fields fields to filter the response data - * @param depth depth parameter for the response + * @param acceptParamInHeader accept header parameter + * @param optionsParamInQuery options query parameter * @return {@code ResponseEntity} response entity */ @Override public ResponseEntity<Object> getResourceDataOperationalForCmHandle(final String resourceIdentifier, final String cmHandle, final @Valid DataAccessReadRequest dataAccessReadRequest, - final String accept, - final @Valid String fields, - final @Min(1) @Valid Integer depth) { + final String acceptParamInHeader, + final @Valid String optionsParamInQuery) { final var modulesListAsJson = dmiService.getResourceDataOperationalForCmHandle(cmHandle, resourceIdentifier, - accept, - fields, - depth, + acceptParamInHeader, + optionsParamInQuery, dataAccessReadRequest.getCmHandleProperties()); return ResponseEntity.ok(modulesListAsJson); } /** * This method fetches the resource for given cm handle using pass through running. It filters the response on the - * basis of depth and field query parameters and returns response. + * basis of options query parameters and returns response. * * @param resourceIdentifier resource identifier to fetch data * @param cmHandle cm handle identifier * @param dataAccessReadRequest data Access Read Request - * @param accept accept header parameter - * @param fields fields to filter the response data - * @param depth depth parameter for the response + * @param acceptParamInHeader accept header parameter + * @param optionsParamInQuery options query parameter * @return {@code ResponseEntity} response entity */ @Override public ResponseEntity<Object> getResourceDataPassthroughRunningForCmHandle(final String resourceIdentifier, final String cmHandle, final @Valid DataAccessReadRequest dataAccessReadRequest, - final String accept, - final @Valid String fields, - final @Min(1) @Valid Integer depth) { + final String acceptParamInHeader, + final @Valid String optionsParamInQuery) { final var modulesListAsJson = dmiService.getResourceDataPassThroughRunningForCmHandle(cmHandle, resourceIdentifier, - accept, - fields, - depth, + acceptParamInHeader, + optionsParamInQuery, dataAccessReadRequest.getCmHandleProperties()); return ResponseEntity.ok(modulesListAsJson); } private List<ModuleReference> convertRestObjectToJavaApiObject( - final DmiModuleReadRequestBody dmiModuleSchemaReadRequestBody) { + final ModuleResourcesReadRequest moduleResourcesReadRequest) { return objectMapper - .convertValue(dmiModuleSchemaReadRequestBody.getData().getModules(), + .convertValue(moduleResourcesReadRequest.getData().getModules(), new TypeReference<List<ModuleReference>>() {}); } } diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java index 753810a2..c6910399 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiService.java @@ -61,40 +61,36 @@ public interface DmiService { /** * This method use to fetch the resource data from cm handle for datastore pass-through operational and resource - * Identifier. Fields and depths query parameter are used to filter the response from network resource. + * Identifier. Options query parameter are used to filter the response from network resource. * * @param cmHandle cm handle identifier * @param resourceIdentifier resource identifier - * @param acceptParam accept header parameter - * @param fieldsQuery fields query parameter - * @param depthQuery depth query parameter + * @param acceptParamInHeader accept header parameter + * @param optionsParamInQuery options query parameter * @param cmHandlePropertyMap cm handle properties * @return {@code Object} response from network function */ Object getResourceDataOperationalForCmHandle(@NotNull String cmHandle, @NotNull String resourceIdentifier, - String acceptParam, - String fieldsQuery, - Integer depthQuery, + String acceptParamInHeader, + String optionsParamInQuery, Map<String, String> cmHandlePropertyMap); /** * This method use to fetch the resource data from cm handle for datastore pass-through running and resource - * Identifier. Fields and depths query parameter are used to filter the response from network resource. + * Identifier. Options query parameter are used to filter the response from network resource. * * @param cmHandle cm handle identifier * @param resourceIdentifier resource identifier - * @param acceptParam accept header parameter - * @param fieldsQuery fields query parameter - * @param depthQuery depth query parameter + * @param acceptParamInHeader accept header parameter + * @param optionsParamInQuery options query parameter * @param cmHandlePropertyMap cm handle properties * @return {@code Object} response from network function */ Object getResourceDataPassThroughRunningForCmHandle(@NotNull String cmHandle, @NotNull String resourceIdentifier, - String acceptParam, - String fieldsQuery, - Integer depthQuery, + String acceptParamInHeader, + String optionsParamInQuery, Map<String, String> cmHandlePropertyMap); /** diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java index 844cc4de..b66e5c1b 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/service/DmiServiceImpl.java @@ -60,13 +60,12 @@ public class DmiServiceImpl implements DmiService { private NcmpRestClient ncmpRestClient; private ObjectMapper objectMapper; private DmiPluginProperties dmiPluginProperties; - private static final String CONTENT_QUERY_PASSTHROUGH_OPERATIONAL = "content=all"; - private static final String CONTENT_QUERY_PASSTHROUGH_RUNNING = "content=config"; + private static final String RESTCONF_CONTENT_PASSTHROUGH_OPERATIONAL_QUERY_PARAM = "content=all"; + private static final String REST_CONF_CONTENT_PASSTHROUGH_RUNNING_QUERY_PARAM = "content=config"; private static final String RESPONSE_CODE = "response code : "; private static final String MESSAGE = " message : "; private static final String IETF_NETCONF_MONITORING_OUTPUT = "ietf-netconf-monitoring:output"; - /** * Constructor. * @@ -178,34 +177,30 @@ public class DmiServiceImpl implements DmiService { @Override public Object getResourceDataOperationalForCmHandle(final @NotNull String cmHandle, final @NotNull String resourceIdentifier, - final String acceptParam, - final String fieldsQuery, - final Integer depthQuery, + final String acceptParamInHeader, + final String optionsParamInQuery, final Map<String, String> cmHandlePropertyMap) { // not using cmHandlePropertyMap of onap dmi impl , other dmi impl might use this. final ResponseEntity<String> responseEntity = sdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceIdentifier, - fieldsQuery, - depthQuery, - acceptParam, - CONTENT_QUERY_PASSTHROUGH_OPERATIONAL); + optionsParamInQuery, + acceptParamInHeader, + RESTCONF_CONTENT_PASSTHROUGH_OPERATIONAL_QUERY_PARAM); return prepareAndSendResponse(responseEntity, cmHandle); } @Override public Object getResourceDataPassThroughRunningForCmHandle(final @NotNull String cmHandle, final @NotNull String resourceIdentifier, - final String acceptParam, - final String fieldsQuery, - final Integer depthQuery, + final String acceptParamInHeader, + final String optionsParamInQuery, final Map<String, String> cmHandlePropertyMap) { // not using cmHandlePropertyMap of onap dmi impl , other dmi impl might use this. final ResponseEntity<String> responseEntity = sdncOperations.getResouceDataForOperationalAndRunning(cmHandle, resourceIdentifier, - fieldsQuery, - depthQuery, - acceptParam, - CONTENT_QUERY_PASSTHROUGH_RUNNING); + optionsParamInQuery, + acceptParamInHeader, + REST_CONF_CONTENT_PASSTHROUGH_RUNNING_QUERY_PARAM); return prepareAndSendResponse(responseEntity, cmHandle); } diff --git a/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java b/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java index 73503d23..98371bf9 100644 --- a/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java +++ b/src/main/java/org/onap/cps/ncmp/dmi/service/operation/SdncOperations.java @@ -20,6 +20,7 @@ package org.onap.cps.ncmp.dmi.service.operation; +import java.util.Arrays; import java.util.LinkedList; import java.util.List; import org.apache.groovy.parser.antlr4.util.StringUtils; @@ -92,23 +93,22 @@ public class SdncOperations { * * @param nodeId network resource identifier * @param resourceId resource identifier - * @param fieldsValue fields query - * @param depthValue depth query - * @param acceptParam accept parameter + * @param optionsParamInQuery fields query + * @param acceptParamInHeader accept parameter + * @param restconfContentQueryParam restconf content query param * @return {@code ResponseEntity} response entity */ public ResponseEntity<String> getResouceDataForOperationalAndRunning(final String nodeId, final String resourceId, - final String fieldsValue, - final Integer depthValue, - final String acceptParam, - final String contentQuery) { + final String optionsParamInQuery, + final String acceptParamInHeader, + final String restconfContentQueryParam) { final String getResourceDataUrl = prepareResourceDataUrl(nodeId, resourceId, - getQueryList(fieldsValue, depthValue, contentQuery)); + buildQueryParamList(optionsParamInQuery, restconfContentQueryParam)); final HttpHeaders httpHeaders = new HttpHeaders(); - if (!StringUtils.isEmpty(acceptParam)) { - httpHeaders.set(HttpHeaders.ACCEPT, acceptParam); + if (!StringUtils.isEmpty(acceptParamInHeader)) { + httpHeaders.set(HttpHeaders.ACCEPT, acceptParamInHeader); } return sdncRestconfClient.getOperation(getResourceDataUrl, httpHeaders); } @@ -131,20 +131,25 @@ public class SdncOperations { } @NotNull - private List<String> getQueryList(final String fieldsValue, final Integer depthValue, final String contentQuery) { - final List<String> queryList = new LinkedList<>(); - if (!StringUtils.isEmpty(fieldsValue)) { - queryList.add("fields=" + fieldsValue); - } - if (depthValue != null) { - queryList.add("depth=" + depthValue); - } - if (!StringUtils.isEmpty(contentQuery)) { - queryList.add(contentQuery); + private List<String> buildQueryParamList(final String optionsParamInQuery, final String restconfContentQueryParam) { + final List<String> queryParamAsList = getOptionsParamAsList(optionsParamInQuery); + queryParamAsList.add(restconfContentQueryParam); + return queryParamAsList; + } + + private List<String> getOptionsParamAsList(final String optionsParamInQuery) { + final List<String> queryParamAsList = new LinkedList<>(); + if (!StringUtils.isEmpty(optionsParamInQuery)) { + final String tempQuery = stripParenthesisFromOptionsQuery(optionsParamInQuery); + queryParamAsList.addAll(Arrays.asList(tempQuery.split(","))); } - return queryList; + return queryParamAsList; } + @NotNull + private String stripParenthesisFromOptionsQuery(final String optionsParamInQuery) { + return optionsParamInQuery.substring(1, optionsParamInQuery.length() - 1); + } @NotNull private String prepareGetSchemaUrl(final String nodeId) { |