diff options
author | bmiklos <miklos.baranyak@est.tech> | 2022-08-25 18:28:16 +0200 |
---|---|---|
committer | bmiklos <miklos.baranyak@est.tech> | 2022-09-01 16:56:05 +0200 |
commit | bbaf501627a69707bd797c535750996a9dd205aa (patch) | |
tree | 94e46ff4e6657bcda6b312947567e5fee7494b03 /cps-ncmp-rest-stub/src/main/java/org | |
parent | 33236ba508ca3536dbacce944b19f880aa6ff944 (diff) |
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 <miklos.baranyak@est.tech>
Diffstat (limited to 'cps-ncmp-rest-stub/src/main/java/org')
-rw-r--r-- | cps-ncmp-rest-stub/src/main/java/org/onap/cps/ncmp/rest/stub/controller/NetworkCmProxyStubController.java | 99 |
1 files changed, 48 insertions, 51 deletions
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<Void> createResourceDataRunningForCmHandle(@NotNull @Valid final String resourceIdentifier, - final String cmHandleId, @Valid final Object body, final String contentType) { + public ResponseEntity<Object> 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<Map<String, Object>> asyncResponse = populateAsyncResponse(topicParamInQuery); + final Map<String, Object> 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<Void> createResourceDataRunningForCmHandle(final String resourceIdentifier, + final String cmHandleId, + final Object body, + final String contentType) { return new ResponseEntity<>(HttpStatus.CREATED); } @Override public ResponseEntity<Void> 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<List<RestOutputCmHandle>> searchCmHandles( - final CmHandleQueryParameters cmHandleQueryParameters) { + final CmHandleQueryParameters cmHandleQueryParameters) { List<RestOutputCmHandle> 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<Object> setDataSyncEnabledFlagForCmHandle(final String cmHandleId, - final Boolean dataSyncEnabled) { + final Boolean dataSyncEnabled) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @Override public ResponseEntity<List<String>> searchCmHandleIds( - final CmHandleQueryParameters cmHandleQueryParameters) { + final CmHandleQueryParameters cmHandleQueryParameters) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } @Override public ResponseEntity<RestOutputCmHandlePublicProperties> 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<Object> getResourceDataOperationalForCmHandle(final String cmHandleId, - final String resourceIdentifier, final String optionsParamInQuery, final String topicParamInQuery) { - final ResponseEntity<Map<String, Object>> asyncResponse = populateAsyncResponse(topicParamInQuery); - final Map<String, Object> 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<Object> getResourceDataRunningForCmHandle(final String cmHandleId, - final String resourceIdentifier, final String options, final String topic) { - return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); - } - @Override public ResponseEntity<Object> 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<Object> updateResourceDataRunningForCmHandle(@NotNull @Valid final String resourceIdentifier, - final String cmHandleId, @Valid final Object body, final String contentType) { + public ResponseEntity<Object> updateResourceDataRunningForCmHandle(final String resourceIdentifier, + final String cmHandleId, + final Object body, + final String contentType) { return new ResponseEntity<>(HttpStatus.NOT_IMPLEMENTED); } |