diff options
author | tragait <rahul.tyagi@est.tech> | 2021-08-16 15:12:36 +0100 |
---|---|---|
committer | tragait <rahul.tyagi@est.tech> | 2021-08-19 12:46:37 +0100 |
commit | c328551bdfd069343cc4c4e0249516d07938c78a (patch) | |
tree | 5beae0e58a123d67a4e89e904bc24d5239942437 /cps-ncmp-rest/src/main/java | |
parent | 24112c0a500e94dc6068be71105874f8d81678b7 (diff) |
get resource data for operational passthrough
Issue-ID: CPS-487
Signed-off-by: tragait <rahul.tyagi@est.tech>
Change-Id: Id1b761f3f6a388556d0cc334fd6f196c78badc39
Diffstat (limited to 'cps-ncmp-rest/src/main/java')
2 files changed, 38 insertions, 0 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 3d771b6c51..b35b245aab 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 @@ -27,6 +27,7 @@ import com.google.gson.Gson; import com.google.gson.GsonBuilder; import java.util.Collection; import javax.validation.Valid; +import javax.validation.constraints.Min; import javax.validation.constraints.NotNull; import org.onap.cps.ncmp.api.NetworkCmProxyDataService; import org.onap.cps.ncmp.api.models.DmiPluginRegistration; @@ -151,6 +152,29 @@ public class NetworkCmProxyController implements NetworkCmProxyApi { return new ResponseEntity<>(HttpStatus.OK); } + /** + * Get resource data for for operational datastore. + * + * @param cmHandle cm handle identifier + * @param resourceIdentifier resource identifier + * @param accept accept header parameter + * @param fields fields query parameter + * @param depth depth query parameter + * @return {@code ResponseEntity} response from dmi plugin + */ + @Override + public ResponseEntity<Object> getResourceDataOperationalForCmHandle(final String cmHandle, + final String resourceIdentifier, + final String accept, + final @Valid String fields, + final @Min(1) @Valid Integer depth) { + final var responseObject = networkCmProxyDataService.getResourceDataOperationalFoCmHandle(cmHandle, + resourceIdentifier, + accept, + fields, + depth); + return ResponseEntity.ok(responseObject); + } private DmiPluginRegistration convertRestObjectToJavaApiObject( final RestDmiPluginRegistration restDmiPluginRegistration) { 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 c91b821d66..6729329779 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 @@ -1,6 +1,7 @@ /* * ============LICENSE_START======================================================= * Copyright (C) 2021 Pantheon.tech + * Modifications Copyright (C) 2021 Nordix Foundation * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -22,6 +23,7 @@ package org.onap.cps.ncmp.rest.exceptions; import lombok.AccessLevel; import lombok.NoArgsConstructor; import lombok.extern.slf4j.Slf4j; +import org.onap.cps.ncmp.api.impl.exception.NcmpException; import org.onap.cps.ncmp.rest.controller.NetworkCmProxyController; import org.onap.cps.ncmp.rest.model.ErrorMessage; import org.onap.cps.spi.exceptions.CpsException; @@ -57,6 +59,11 @@ public class NetworkCmProxyRestExceptionHandler { return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception); } + @ExceptionHandler({NcmpException.class}) + public static ResponseEntity<Object> handleNcmpExceptions(final NcmpException exception) { + return buildErrorResponse(HttpStatus.INTERNAL_SERVER_ERROR, exception); + } + private static ResponseEntity<Object> buildErrorResponse(final HttpStatus status, final Exception exception) { if (exception.getCause() != null || !(exception instanceof CpsException)) { log.error("Exception occurred", exception); @@ -64,6 +71,13 @@ public class NetworkCmProxyRestExceptionHandler { final var errorMessage = new ErrorMessage(); errorMessage.setStatus(status.toString()); errorMessage.setMessage(exception.getMessage()); + if (exception instanceof CpsException) { + errorMessage.setDetails(((CpsException) exception).getDetails()); + } else if (exception instanceof NcmpException) { + errorMessage.setDetails(((NcmpException) exception).getDetails()); + } else { + errorMessage.setDetails(CHECK_LOGS_FOR_DETAILS); + } errorMessage.setDetails(exception instanceof CpsException ? ((CpsException) exception).getDetails() : CHECK_LOGS_FOR_DETAILS); return new ResponseEntity<>(errorMessage, status); |