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=a97852fe2bb822c675eb7525b03d91ece1a5135b;hb=fd50018df540ab3689e2bc5db9d2bcfb2d11c922;hp=3b44b80f6d33a670d5745c89852712bd63387d00;hpb=043a0ed45530842a8606a675cb71078ab055d2d5;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 3b44b80f6..a97852fe2 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 * ================================================================================ @@ -37,6 +37,7 @@ import java.util.stream.Collectors; import javax.validation.Valid; import javax.validation.constraints.NotNull; import lombok.extern.slf4j.Slf4j; +import org.modelmapper.ModelMapper; import org.onap.cps.ncmp.api.NetworkCmProxyDataService; import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi; import org.onap.cps.ncmp.rest.model.CmHandleProperties; @@ -46,10 +47,7 @@ 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.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.RequestMapping; @@ -61,7 +59,9 @@ import org.springframework.web.bind.annotation.RestController; 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 NetworkCmProxyDataService networkCmProxyDataService; /** @@ -72,83 +72,6 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { 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); - } - /** * Get resource data from operational datastore. * @@ -196,7 +119,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { final String cmHandle, final Object requestBody, final String contentType) { networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, - resourceIdentifier, PATCH, requestBody.toString(), contentType); + resourceIdentifier, PATCH, GSON.toJson(requestBody), contentType); return new ResponseEntity<>(HttpStatus.OK); } @@ -211,11 +134,9 @@ 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, GSON.toJson(requestBody), contentType); return new ResponseEntity<>(HttpStatus.CREATED); } @@ -231,10 +152,10 @@ 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, GSON.toJson(requestBody), contentType); return new ResponseEntity<>(HttpStatus.OK); } @@ -244,18 +165,15 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { * * @param resourceIdentifier resource identifier * @param cmHandle cm handle identifier - * @param requestBody the request body * @param contentType content type of the body * @return response entity no content if request is successful */ @Override - public ResponseEntity deleteResourceDataRunningForCmHandle(final String resourceIdentifier, - final String cmHandle, - final String requestBody, + public ResponseEntity deleteResourceDataRunningForCmHandle(final String cmHandle, + final String resourceIdentifier, final String contentType) { - networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle, - resourceIdentifier, DELETE, requestBody, contentType); + resourceIdentifier, DELETE, NO_BODY, contentType); return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @@ -280,11 +198,12 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { * @param cmHandle the cm handle * @return module references for cm handle */ - @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) {