diff options
author | Niamh Core <niamh.core@est.tech> | 2021-08-20 10:38:54 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2021-08-20 10:38:54 +0000 |
commit | dc5ed75c841da857611713bceed8bf9988204d3d (patch) | |
tree | 1200bc43049a530dd7dff9fdc647319282729361 /cps-ncmp-rest/src/main | |
parent | ffc05ea4b84ee3ca36c2278a4d4ded9f8e0371d1 (diff) | |
parent | c328551bdfd069343cc4c4e0249516d07938c78a (diff) |
Merge "get resource data for operational passthrough"
Diffstat (limited to 'cps-ncmp-rest/src/main')
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); |