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=419f6e926866e1cce4fd3ef0ffa9c535457eeb24;hb=05e7b8a207b1c641468e77d754fe1a5ae9e1a51e;hp=e3c457eaf48647b97936390c9c9aad55520a221b;hpb=18a79ebafa6c2b8737eb0702e1c17acbf57159ba;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 e3c457eaf..419f6e926 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 (C) 2021-2022 Nordix Foundation * Modification Copyright (C) 2021 highstreet technologies GmbH * Modifications (C) 2021 Bell Canada * ================================================================================ @@ -27,8 +27,6 @@ import static org.onap.cps.ncmp.api.impl.operations.DmiRequestBody.OperationEnum 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; @@ -36,6 +34,7 @@ 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; @@ -48,9 +47,7 @@ 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.ncmp.rest.model.ModuleReference; -import org.onap.cps.spi.FetchDescendantsOption; -import org.onap.cps.spi.model.DataNode; -import org.onap.cps.utils.DataMapUtils; +import org.onap.cps.utils.JsonObjectMapper; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; @@ -59,104 +56,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 = new ModelMapper(); + 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. - */ - // All deprecated APIs methods will be address into https://jira.onap.org/browse/CPS-642 - @Override - @Deprecated(forRemoval = false) - public ResponseEntity createNode(final String cmHandle, @Valid final Object jsonData, - @Valid final String parentNodeXpath) { - networkCmProxyDataService.createDataNode(cmHandle, parentNodeXpath, GSON.toJson(jsonData)); - return new ResponseEntity<>(HttpStatus.CREATED); - } - - /** - * Add List-node Child Element. - * @deprecated This Method is no longer used as part of NCMP. - */ - // All deprecated APIs methods will be address into https://jira.onap.org/browse/CPS-642 - @Override - @Deprecated(forRemoval = false) - public ResponseEntity addListNodeElements(@NotNull @Valid final String parentNodeXpath, - final String cmHandle, @Valid final Object jsonData) { - networkCmProxyDataService.addListNodeElements(cmHandle, parentNodeXpath, GSON.toJson(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. - */ - // All deprecated APIs methods will be address into https://jira.onap.org/browse/CPS-642 - @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. - */ - // All deprecated APIs methods will be address into https://jira.onap.org/browse/CPS-642 - @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. - */ - // All deprecated APIs methods will be address into https://jira.onap.org/browse/CPS-642 - @Override - @Deprecated(forRemoval = false) - public ResponseEntity replaceNode(final String cmHandle, @Valid final Object jsonData, - @Valid final String parentNodeXpath) { - networkCmProxyDataService.replaceNodeTree(cmHandle, parentNodeXpath, GSON.toJson(jsonData)); - return new ResponseEntity<>(HttpStatus.OK); - } - - /** - * Update Node Leaves. - * @deprecated This Method is no longer used as part of NCMP. - */ - // All deprecated APIs methods will be address into https://jira.onap.org/browse/CPS-642 - @Override - @Deprecated(forRemoval = false) - public ResponseEntity updateNodeLeaves(final String cmHandle, @Valid final Object jsonData, - @Valid final String parentNodeXpath) { - networkCmProxyDataService.updateNodeLeaves(cmHandle, parentNodeXpath, GSON.toJson(jsonData)); - return new ResponseEntity<>(HttpStatus.OK); - } + private final JsonObjectMapper jsonObjectMapper; /** * Get resource data from operational datastore. @@ -204,9 +111,9 @@ 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, GSON.toJson(requestBody), contentType); - return new ResponseEntity<>(HttpStatus.OK); + final Object responseObject = networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, + resourceIdentifier, PATCH, jsonObjectMapper.asJsonString(requestBody), contentType); + return ResponseEntity.ok(responseObject); } /** @@ -222,7 +129,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { public ResponseEntity createResourceDataRunningForCmHandle(final String resourceIdentifier, final String cmHandle, final Object requestBody, final String contentType) { networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, - resourceIdentifier, CREATE, GSON.toJson(requestBody), contentType); + resourceIdentifier, CREATE, jsonObjectMapper.asJsonString(requestBody), contentType); return new ResponseEntity<>(HttpStatus.CREATED); } @@ -241,7 +148,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { final Object requestBody, final String contentType) { networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, - resourceIdentifier, UPDATE, GSON.toJson(requestBody), contentType); + resourceIdentifier, UPDATE, jsonObjectMapper.asJsonString(requestBody), contentType); return new ResponseEntity<>(HttpStatus.OK); }