X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=cps-ncmp-rest%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fcps%2Fncmp%2Frest%2Fcontroller%2FNetworkCmProxyController.java;h=b5c8d14a9cfa446d7e4e764214c685cd9209fc45;hb=697caa85dd35d5996d604935987e43b61b5811c2;hp=f95d4a2f528e292852d85c437b1d26216fdf4f51;hpb=70f9a7d4f2d46f2630f8045d1729ecc3d3131f56;p=cps.git diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java index f95d4a2f5..b5c8d14a9 100755 --- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java +++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java @@ -1,7 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2021 Pantheon.tech - * Modifications (C) 2021 Nordix Foundation + * Modifications Copyright (C) 2021-2022 Nordix Foundation * Modification Copyright (C) 2021 highstreet technologies GmbH * Modifications (C) 2021 Bell Canada * ================================================================================ @@ -10,6 +10,7 @@ * 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. @@ -23,11 +24,10 @@ package org.onap.cps.ncmp.rest.controller; import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.CREATE; +import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.DELETE; import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.PATCH; import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum.UPDATE; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -35,20 +35,23 @@ import java.util.List; import java.util.stream.Collectors; import javax.validation.Valid; import javax.validation.constraints.NotNull; +import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.modelmapper.ModelMapper; import org.onap.cps.ncmp.api.NetworkCmProxyDataService; +import org.onap.cps.ncmp.api.models.NcmpServiceCmHandle; import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi; import org.onap.cps.ncmp.rest.model.CmHandleProperties; import org.onap.cps.ncmp.rest.model.CmHandleProperty; +import org.onap.cps.ncmp.rest.model.CmHandlePublicProperties; import org.onap.cps.ncmp.rest.model.CmHandles; import org.onap.cps.ncmp.rest.model.ConditionProperties; import org.onap.cps.ncmp.rest.model.Conditions; import org.onap.cps.ncmp.rest.model.ModuleNameAsJsonObject; import org.onap.cps.ncmp.rest.model.ModuleNamesAsJsonArray; -import org.onap.cps.spi.FetchDescendantsOption; -import org.onap.cps.spi.model.DataNode; -import org.onap.cps.spi.model.ModuleReference; -import org.onap.cps.utils.DataMapUtils; +import org.onap.cps.ncmp.rest.model.ModuleReference; +import org.onap.cps.ncmp.rest.model.RestOutputCmHandle; +import org.onap.cps.utils.JsonObjectMapper; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; @@ -57,96 +60,14 @@ import org.springframework.web.bind.annotation.RestController; @Slf4j @RestController @RequestMapping("${rest.api.ncmp-base-path}") +@RequiredArgsConstructor public class NetworkCmProxyController implements NetworkCmProxyApi { - private static final Gson GSON = new GsonBuilder().create(); + private static final String NO_BODY = null; + private final ModelMapper modelMapper; private final NetworkCmProxyDataService networkCmProxyDataService; - - /** - * Constructor Injection for Dependencies. - * @param networkCmProxyDataService Data Service Interface - */ - public NetworkCmProxyController(final NetworkCmProxyDataService networkCmProxyDataService) { - this.networkCmProxyDataService = networkCmProxyDataService; - } - - /** - * Create Node. - * @deprecated This Method is no longer used as part of NCMP. - */ - @Override - @Deprecated(forRemoval = false) - public ResponseEntity createNode(final String cmHandle, @Valid final String jsonData, - @Valid final String parentNodeXpath) { - networkCmProxyDataService.createDataNode(cmHandle, parentNodeXpath, jsonData); - return new ResponseEntity<>(HttpStatus.CREATED); - } - - /** - * Add List-node Child Element. - * @deprecated This Method is no longer used as part of NCMP. - */ - @Override - @Deprecated(forRemoval = false) - public ResponseEntity addListNodeElements(@NotNull @Valid final String parentNodeXpath, - final String cmHandle, @Valid final String jsonData) { - networkCmProxyDataService.addListNodeElements(cmHandle, parentNodeXpath, jsonData); - return new ResponseEntity<>(HttpStatus.CREATED); - } - - /** - * Get Node By CM Handle and X-Path. - * @deprecated This Method is no longer used as part of NCMP. - */ - @Override - @Deprecated(forRemoval = false) - public ResponseEntity getNodeByCmHandleAndXpath(final String cmHandle, @Valid final String xpath, - @Valid final Boolean includeDescendants) { - final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants) - ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS; - final var dataNode = networkCmProxyDataService.getDataNode(cmHandle, xpath, fetchDescendantsOption); - return new ResponseEntity<>(DataMapUtils.toDataMap(dataNode), HttpStatus.OK); - } - - /** - * Query Data Nodes. - * @deprecated This Method is no longer used as part of NCMP. - */ - @Override - @Deprecated(forRemoval = false) - public ResponseEntity queryNodesByCmHandleAndCpsPath(final String cmHandle, @Valid final String cpsPath, - @Valid final Boolean includeDescendants) { - final FetchDescendantsOption fetchDescendantsOption = Boolean.TRUE.equals(includeDescendants) - ? FetchDescendantsOption.INCLUDE_ALL_DESCENDANTS : FetchDescendantsOption.OMIT_DESCENDANTS; - final Collection dataNodes = - networkCmProxyDataService.queryDataNodes(cmHandle, cpsPath, fetchDescendantsOption); - return new ResponseEntity<>(GSON.toJson(dataNodes), HttpStatus.OK); - } - - /** - * Replace Node With Descendants. - * @deprecated This Method is no longer used as part of NCMP. - */ - @Override - @Deprecated(forRemoval = false) - public ResponseEntity replaceNode(final String cmHandle, @Valid final String jsonData, - @Valid final String parentNodeXpath) { - networkCmProxyDataService.replaceNodeTree(cmHandle, parentNodeXpath, jsonData); - return new ResponseEntity<>(HttpStatus.OK); - } - - /** - * Update Node Leaves. - * @deprecated This Method is no longer used as part of NCMP. - */ - @Override - @Deprecated(forRemoval = false) - public ResponseEntity updateNodeLeaves(final String cmHandle, @Valid final String jsonData, - @Valid final String parentNodeXpath) { - networkCmProxyDataService.updateNodeLeaves(cmHandle, parentNodeXpath, jsonData); - return new ResponseEntity<>(HttpStatus.OK); - } + private final JsonObjectMapper jsonObjectMapper; /** * Get resource data from operational datastore. @@ -155,17 +76,20 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { * @param resourceIdentifier resource identifier * @param acceptParamInHeader accept header parameter * @param optionsParamInQuery options query parameter + * @param topicParamInQuery topic query parameter * @return {@code ResponseEntity} response from dmi plugin */ @Override public ResponseEntity getResourceDataOperationalForCmHandle(final String cmHandle, final @NotNull @Valid String resourceIdentifier, final String acceptParamInHeader, - final @Valid String optionsParamInQuery) { + final @Valid String optionsParamInQuery, + final @Valid String topicParamInQuery) { final Object responseObject = networkCmProxyDataService.getResourceDataOperationalForCmHandle(cmHandle, resourceIdentifier, acceptParamInHeader, - optionsParamInQuery); + optionsParamInQuery, + topicParamInQuery); return ResponseEntity.ok(responseObject); } @@ -176,17 +100,20 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { * @param resourceIdentifier resource identifier * @param acceptParamInHeader accept header parameter * @param optionsParamInQuery options query parameter + * @param topicParamInQuery topic query parameter * @return {@code ResponseEntity} response from dmi plugin */ @Override public ResponseEntity getResourceDataRunningForCmHandle(final String cmHandle, final @NotNull @Valid String resourceIdentifier, final String acceptParamInHeader, - final @Valid String optionsParamInQuery) { + final @Valid String optionsParamInQuery, + final @Valid String topicParamInQuery) { final Object responseObject = networkCmProxyDataService.getResourceDataPassThroughRunningForCmHandle(cmHandle, resourceIdentifier, acceptParamInHeader, - optionsParamInQuery); + optionsParamInQuery, + topicParamInQuery); return ResponseEntity.ok(responseObject); } @@ -194,13 +121,13 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { public ResponseEntity patchResourceDataRunningForCmHandle(final String resourceIdentifier, final String cmHandle, final Object requestBody, final String contentType) { - networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, - resourceIdentifier, PATCH, requestBody.toString(), contentType); - return new ResponseEntity<>(HttpStatus.OK); + final Object responseObject = networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, + resourceIdentifier, PATCH, jsonObjectMapper.asJsonString(requestBody), contentType); + return ResponseEntity.ok(responseObject); } /** - * Create resource data in datastore pass through running for given cm-handle. + * Create resource data in datastore pass-through running for given cm-handle. * * @param resourceIdentifier resource identifier * @param cmHandle cm handle identifier @@ -210,16 +137,14 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { */ @Override public ResponseEntity createResourceDataRunningForCmHandle(final String resourceIdentifier, - final String cmHandle, - final String requestBody, - final String contentType) { + final String cmHandle, final Object requestBody, final String contentType) { networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, - resourceIdentifier, CREATE, requestBody, contentType); + resourceIdentifier, CREATE, jsonObjectMapper.asJsonString(requestBody), contentType); return new ResponseEntity<>(HttpStatus.CREATED); } /** - * Update resource data in datastore pass through running for given cm-handle. + * Update resource data in datastore pass-through running for given cm-handle. * * @param resourceIdentifier resource identifier * @param cmHandle cm handle identifier @@ -230,13 +155,31 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { @Override public ResponseEntity updateResourceDataRunningForCmHandle(final String resourceIdentifier, final String cmHandle, - final String requestBody, + final Object requestBody, final String contentType) { networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, - resourceIdentifier, UPDATE, requestBody, contentType); + resourceIdentifier, UPDATE, jsonObjectMapper.asJsonString(requestBody), contentType); return new ResponseEntity<>(HttpStatus.OK); } + + /** + * Delete resource data in datastore pass-through running for a given cm-handle. + * + * @param resourceIdentifier resource identifier + * @param cmHandle cm handle identifier + * @param contentType content type of the body + * @return response entity no content if request is successful + */ + @Override + public ResponseEntity deleteResourceDataRunningForCmHandle(final String cmHandle, + final String resourceIdentifier, + final String contentType) { + networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, + resourceIdentifier, DELETE, NO_BODY, contentType); + return new ResponseEntity<>(HttpStatus.NO_CONTENT); + } + /** * Execute cm handle search. * @@ -252,17 +195,30 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { return ResponseEntity.ok(cmHandles); } + /** + * Search for Cm Handle and Properties by Name. + * @param cmHandleId cm-handle identifier + * @return cm handle and its properties + */ + @Override + public ResponseEntity retrieveCmHandleDetailsById(final String cmHandleId) { + final NcmpServiceCmHandle ncmpServiceCmHandle = networkCmProxyDataService.getNcmpServiceCmHandle(cmHandleId); + final RestOutputCmHandle restOutputCmHandle = toRestOutputCmHandle(ncmpServiceCmHandle); + return ResponseEntity.ok(restOutputCmHandle); + } + /** * Return module references for a cm handle. * * @param cmHandle the cm handle - * @return module references for cm handle + * @return module references for cm handle. Namespace will be always blank because restConf does not include this. */ - @Override - public ResponseEntity getModuleReferencesByCmHandle(final String cmHandle) { - final Collection - moduleReferences = networkCmProxyDataService.getYangResourcesModuleReferences(cmHandle); - return new ResponseEntity<>(new Gson().toJson(moduleReferences), HttpStatus.OK); + public ResponseEntity> getModuleReferencesByCmHandle(final String cmHandle) { + final List moduleReferences = + networkCmProxyDataService.getYangResourcesModuleReferences(cmHandle).stream() + .map(moduleReference -> modelMapper.map(moduleReference, ModuleReference.class)) + .collect(Collectors.toList()); + return new ResponseEntity<>(moduleReferences, HttpStatus.OK); } private Collection processConditions(final List conditionProperties) { @@ -299,4 +255,13 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { } return cmHandleProperties; } + + private RestOutputCmHandle toRestOutputCmHandle(final NcmpServiceCmHandle ncmpServiceCmHandle) { + final RestOutputCmHandle restOutputCmHandle = new RestOutputCmHandle(); + final CmHandlePublicProperties cmHandlePublicProperties = new CmHandlePublicProperties(); + restOutputCmHandle.setCmHandle(ncmpServiceCmHandle.getCmHandleID()); + cmHandlePublicProperties.add(ncmpServiceCmHandle.getPublicProperties()); + restOutputCmHandle.setPublicCmHandleProperties(cmHandlePublicProperties); + return restOutputCmHandle; + } }