From bbaf501627a69707bd797c535750996a9dd205aa Mon Sep 17 00:00:00 2001 From: bmiklos Date: Thu, 25 Aug 2022 18:28:16 +0200 Subject: Implement merging all ncmp datastore endpoints into one - Merging all endpoints under /v1/ch/{cm-handle}/data/ds/ncmp-datastore:* to /v1/ch/{cm-handle}/data/ds/{ncmp-datastore-name} - Implementing missing tests from parent - Introducing abstract class to keep the common code and just pass in the supplier to be executed in sync or async manner - Removed the existing get endpoints for passthrough-running, passthrough-operational and operational and merged them into a common get endpoint Issue-ID: CPS-1178 Issue-ID: CPS-1001 Change-Id: I6956c81d5acfa8fb11217bcc16cb795b62070fa3 Signed-off-by: bmiklos --- .../controller/NetworkCmProxyStubController.java | 99 +++++++++++----------- 1 file changed, 48 insertions(+), 51 deletions(-) (limited to 'cps-ncmp-rest-stub') diff --git a/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java b/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java index 67af6f10a9..ac5337dbd3 100644 --- a/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java +++ b/cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java @@ -30,10 +30,9 @@ import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.UUID; -import javax.validation.Valid; -import javax.validation.constraints.NotNull; import lombok.extern.slf4j.Slf4j; import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi; +import org.onap.cps.ncmp.rest.controller.handlers.DatastoreType; import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters; import org.onap.cps.ncmp.rest.model.RestModuleDefinition; import org.onap.cps.ncmp.rest.model.RestModuleReference; @@ -58,20 +57,53 @@ public class NetworkCmProxyStubController implements NetworkCmProxyApi { private String pathToResponseFiles; @Override - public ResponseEntity createResourceDataRunningForCmHandle(@NotNull @Valid final String resourceIdentifier, - final String cmHandleId, @Valid final Object body, final String contentType) { + public ResponseEntity getResourceDataForCmHandle(final String dataStoreType, + final String cmHandle, + final String resourceIdentifier, + final String optionsParamInQuery, + final String topicParamInQuery, + final Boolean includeDescendants) { + if (DatastoreType.PASSTHROUGH_OPERATIONAL == DatastoreType.fromDatastoreName(dataStoreType)) { + final ResponseEntity> asyncResponse = populateAsyncResponse(topicParamInQuery); + final Map asyncResponseData = asyncResponse.getBody(); + Object responseObject = null; + // read JSON file and map/convert to java POJO + final ClassPathResource resource = + new ClassPathResource(pathToResponseFiles + "passthrough-operational-example.json"); + try (InputStream inputStream = resource.getInputStream()) { + final String string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); + final ObjectMapper mapper = new ObjectMapper(); + responseObject = mapper.readValue(string, Object.class); + } catch (final IOException exception) { + log.error("Error reading the file.", exception); + return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); + } + if (asyncResponseData == null) { + return ResponseEntity.ok(responseObject); + } + return ResponseEntity.ok(asyncResponse); + } + return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); + } + + @Override + public ResponseEntity createResourceDataRunningForCmHandle(final String resourceIdentifier, + final String cmHandleId, + final Object body, + final String contentType) { return new ResponseEntity<>(HttpStatus.CREATED); } @Override public ResponseEntity deleteResourceDataRunningForCmHandle(final String cmHandleId, - @NotNull @Valid final String resourceIdentifier, final String contentType) { + final String resourceIdentifier, + final String contentType) { return new ResponseEntity<>(HttpStatus.NO_CONTENT); } @Override public ResponseEntity> searchCmHandles( - final CmHandleQueryParameters cmHandleQueryParameters) { + final CmHandleQueryParameters cmHandleQueryParameters) { List restOutputCmHandles = null; // read JSON file and map/convert to java POJO final ClassPathResource resource = new ClassPathResource(pathToResponseFiles + "cmHandlesSearch.json"); @@ -88,19 +120,19 @@ public class NetworkCmProxyStubController implements NetworkCmProxyApi { @Override public ResponseEntity setDataSyncEnabledFlagForCmHandle(final String cmHandleId, - final Boolean dataSyncEnabled) { + final Boolean dataSyncEnabled) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @Override public ResponseEntity> searchCmHandleIds( - final CmHandleQueryParameters cmHandleQueryParameters) { + final CmHandleQueryParameters cmHandleQueryParameters) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @Override public ResponseEntity getCmHandlePublicPropertiesByCmHandleId( - final String cmHandleId) { + final String cmHandleId) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -119,48 +151,11 @@ public class NetworkCmProxyStubController implements NetworkCmProxyApi { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } - /** - * Get resource data from operational datastore. - * - * @param cmHandleId cm handle identifier - * @param resourceIdentifier resource identifier - * @param optionsParamInQuery options query parameter - * @param topicParamInQuery topic query parameter - * @return {@code ResponseEntity} response from dmi plugin - */ - @Override - public ResponseEntity getResourceDataOperationalForCmHandle(final String cmHandleId, - final String resourceIdentifier, final String optionsParamInQuery, final String topicParamInQuery) { - final ResponseEntity> asyncResponse = populateAsyncResponse(topicParamInQuery); - final Map asyncResponseData = asyncResponse.getBody(); - Object responseObject = null; - // read JSON file and map/convert to java POJO - final ClassPathResource resource = new ClassPathResource(pathToResponseFiles - + "passthrough-operational-example.json"); - try (InputStream inputStream = resource.getInputStream()) { - final String string = new String(inputStream.readAllBytes(), StandardCharsets.UTF_8); - final ObjectMapper mapper = new ObjectMapper(); - responseObject = mapper.readValue(string, Object.class); - } catch (final IOException exception) { - log.error("Error reading the file.", exception); - return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build(); - } - if (asyncResponseData == null) { - return ResponseEntity.ok(responseObject); - } - return ResponseEntity.ok(asyncResponse); - - } - - @Override - public ResponseEntity getResourceDataRunningForCmHandle(final String cmHandleId, - final String resourceIdentifier, final String options, final String topic) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } - @Override public ResponseEntity patchResourceDataRunningForCmHandle(final String resourceIdentifier, - final String cmHandleId, final Object body, final String contentType) { + final String cmHandleId, + final Object body, + final String contentType) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @@ -170,8 +165,10 @@ public class NetworkCmProxyStubController implements NetworkCmProxyApi { } @Override - public ResponseEntity updateResourceDataRunningForCmHandle(@NotNull @Valid final String resourceIdentifier, - final String cmHandleId, @Valid final Object body, final String contentType) { + public ResponseEntity updateResourceDataRunningForCmHandle(final String resourceIdentifier, + final String cmHandleId, + final Object body, + final String contentType) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } -- cgit 1.2.3-korg