summaryrefslogtreecommitdiffstats
path: root/cps-ncmp-rest/src/main/java
diff options
context:
space:
mode:
authorbmiklos <miklos.baranyak@est.tech>2022-09-05 18:25:46 +0200
committerbmiklos <miklos.baranyak@est.tech>2022-09-07 12:07:40 +0200
commit440dc8aab179f6c8451683f53b019ccd8bd60bdf (patch)
tree0b4568eb55924cb69c4d599e75cc658a6a126eb5 /cps-ncmp-rest/src/main/java
parentbd22f203779e6c396f10d9064565d72f0488dad0 (diff)
Handle invalid operations on merged datastore endpoint
- Move the other endpoints under the same thats handling the get - Add exceptions to handle invalid cases - Add new tests for testing the invalid cases Issue-ID: CPS-1001 Issue-ID: CPS-1219 Change-Id: I26fd57b5921f976cde7089b4cf1e8c0e5d8dc43b Signed-off-by: bmiklos <miklos.baranyak@est.tech>
Diffstat (limited to 'cps-ncmp-rest/src/main/java')
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/NetworkCmProxyController.java43
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/DatastoreType.java16
-rw-r--r--cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/InvalidDatastoreException.java32
-rwxr-xr-xcps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java9
4 files changed, 92 insertions, 8 deletions
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 9aa8263fc5..2f6668a351 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
@@ -41,6 +41,7 @@ import org.onap.cps.ncmp.rest.api.NetworkCmProxyApi;
import org.onap.cps.ncmp.rest.controller.handlers.DatastoreType;
import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreResourceRequestHandler;
import org.onap.cps.ncmp.rest.controller.handlers.NcmpDatastoreResourceRequestHandlerFactory;
+import org.onap.cps.ncmp.rest.exceptions.InvalidDatastoreException;
import org.onap.cps.ncmp.rest.mapper.CmHandleStateMapper;
import org.onap.cps.ncmp.rest.model.CmHandlePublicProperties;
import org.onap.cps.ncmp.rest.model.CmHandleQueryParameters;
@@ -98,11 +99,26 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
optionsParamInQuery, topicParamInQuery, includeDescendants);
}
+ /**
+ * Patch resource data from passthrough-running.
+ *
+ * @param resourceIdentifier resource identifier
+ * @param datastoreName name of the datastore
+ * @param cmHandle cm handle identifier
+ * @param requestBody the request body
+ * @param contentType content type of body
+ * @return {@code ResponseEntity} response from dmi plugin
+ */
+
@Override
public ResponseEntity<Object> patchResourceDataRunningForCmHandle(final String resourceIdentifier,
+ final String datastoreName,
final String cmHandle,
final Object requestBody,
final String contentType) {
+
+ acceptPassthroughRunningOnly(datastoreName);
+
final Object responseObject = networkCmProxyDataService
.writeResourceDataPassThroughRunningForCmHandle(
cmHandle, resourceIdentifier, PATCH,
@@ -114,6 +130,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
* Create resource data in datastore pass-through running for given cm-handle.
*
* @param resourceIdentifier resource identifier
+ * @param datastoreName name of the datastore
* @param cmHandle cm handle identifier
* @param requestBody the request body
* @param contentType content type of body
@@ -121,9 +138,13 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
*/
@Override
public ResponseEntity<Void> createResourceDataRunningForCmHandle(final String resourceIdentifier,
+ final String datastoreName,
final String cmHandle,
final Object requestBody,
final String contentType) {
+
+ acceptPassthroughRunningOnly(datastoreName);
+
networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
resourceIdentifier, CREATE, jsonObjectMapper.asJsonString(requestBody), contentType);
return new ResponseEntity<>(HttpStatus.CREATED);
@@ -133,34 +154,43 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
* Update resource data in datastore pass-through running for given cm-handle.
*
* @param resourceIdentifier resource identifier
+ * @param datastoreName name of the datastore
* @param cmHandle cm handle identifier
* @param requestBody the request body
* @param contentType content type of the body
* @return response entity
*/
+
@Override
public ResponseEntity<Object> updateResourceDataRunningForCmHandle(final String resourceIdentifier,
+ final String datastoreName,
final String cmHandle,
final Object requestBody,
final String contentType) {
+ acceptPassthroughRunningOnly(datastoreName);
+
networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
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 datastoreName name of the datastore
* @param cmHandle cm handle identifier
+ * @param resourceIdentifier resource identifier
* @param contentType content type of the body
* @return response entity no content if request is successful
*/
@Override
- public ResponseEntity<Void> deleteResourceDataRunningForCmHandle(final String cmHandle,
+ public ResponseEntity<Void> deleteResourceDataRunningForCmHandle(final String datastoreName,
+ final String cmHandle,
final String resourceIdentifier,
final String contentType) {
+
+ acceptPassthroughRunningOnly(datastoreName);
+
networkCmProxyDataService.writeResourceDataPassThroughRunningForCmHandle(cmHandle,
resourceIdentifier, DELETE, NO_BODY, contentType);
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
@@ -290,6 +320,7 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
return new ResponseEntity<>(HttpStatus.OK);
}
+
private RestOutputCmHandle toRestOutputCmHandle(final NcmpServiceCmHandle ncmpServiceCmHandle) {
final RestOutputCmHandle restOutputCmHandle = new RestOutputCmHandle();
final CmHandlePublicProperties cmHandlePublicProperties = new CmHandlePublicProperties();
@@ -301,6 +332,12 @@ public class NetworkCmProxyController implements NetworkCmProxyApi {
return restOutputCmHandle;
}
+ private void acceptPassthroughRunningOnly(final String datastoreName) {
+ final DatastoreType datastoreType = DatastoreType.fromDatastoreName(datastoreName);
+ if (DatastoreType.PASSTHROUGH_RUNNING != datastoreType) {
+ throw new InvalidDatastoreException(datastoreName + " is not supported");
+ }
+ }
}
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/DatastoreType.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/DatastoreType.java
index 959c85d141..e8ab997d6f 100644
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/DatastoreType.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/controller/handlers/DatastoreType.java
@@ -25,6 +25,7 @@ import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import lombok.Getter;
+import org.onap.cps.ncmp.rest.exceptions.InvalidDatastoreException;
@Getter
public enum DatastoreType {
@@ -45,8 +46,21 @@ public enum DatastoreType {
type -> datastoreNameToDatastoreType.put(type.getDatastoreName(), type));
}
+ /**
+ * From datastore name get datastore type.
+ *
+ * @param datastoreName the datastore name
+ * @return the datastore type
+ */
public static DatastoreType fromDatastoreName(final String datastoreName) {
- return datastoreNameToDatastoreType.get(datastoreName);
+
+ final DatastoreType datastoreType = datastoreNameToDatastoreType.get(datastoreName);
+
+ if (null == datastoreType) {
+ throw new InvalidDatastoreException(datastoreName + " is an invalid datastore name");
+ }
+
+ return datastoreType;
}
}
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/InvalidDatastoreException.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/InvalidDatastoreException.java
new file mode 100644
index 0000000000..ff13a93e58
--- /dev/null
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/InvalidDatastoreException.java
@@ -0,0 +1,32 @@
+/*
+ * ============LICENSE_START=======================================================
+ * Copyright (C) 2022 Nordix Foundation
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ * SPDX-License-Identifier: Apache-2.0
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.cps.ncmp.rest.exceptions;
+
+public class InvalidDatastoreException extends RuntimeException {
+ /**
+ * Instantiates a new Invalid datastore exception.
+ *
+ * @param message the message
+ */
+ public InvalidDatastoreException(final String message) {
+ super(message);
+ }
+}
diff --git a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java
index 98d7f6fd1d..f12a1c5f24 100755
--- a/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java
+++ b/cps-ncmp-rest/src/main/java/org/onap/cps/ncmp/rest/exceptions/NetworkCmProxyRestExceptionHandler.java
@@ -59,7 +59,7 @@ public class NetworkCmProxyRestExceptionHandler {
*/
@ExceptionHandler
public static ResponseEntity<Object> handleInternalServerErrorExceptions(
- final Exception exception) {
+ final Exception exception) {
return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception);
}
@@ -74,8 +74,8 @@ public class NetworkCmProxyRestExceptionHandler {
return wrapDmiErrorResponse(HttpStatus.BAD_GATEWAY, httpClientRequestException);
}
- @ExceptionHandler({DmiRequestException.class, DataValidationException.class, HttpMessageNotReadableException.class,
- InvalidTopicException.class})
+ @ExceptionHandler({DmiRequestException.class, DataValidationException.class,
+ HttpMessageNotReadableException.class, InvalidTopicException.class, InvalidDatastoreException.class})
public static ResponseEntity<Object> handleDmiRequestExceptions(final Exception exception) {
return buildErrorResponse(HttpStatus.BAD_REQUEST, exception);
}
@@ -104,7 +104,8 @@ public class NetworkCmProxyRestExceptionHandler {
return new ResponseEntity<>(errorMessage, status);
}
- private static ResponseEntity<Object> wrapDmiErrorResponse(final HttpStatus httpStatus,
+ private static ResponseEntity<Object> wrapDmiErrorResponse(
+ final HttpStatus httpStatus,
final HttpClientRequestException httpClientRequestException) {
final var dmiErrorMessage = new DmiErrorMessage();
final var dmiErrorResponse = new DmiErrorMessageDmiresponse();