diff options
author | a.sreekumar <ajith.sreekumar@bell.ca> | 2021-12-03 11:27:32 +0000 |
---|---|---|
committer | a.sreekumar <ajith.sreekumar@bell.ca> | 2021-12-14 17:58:20 +0000 |
commit | 4694c152f69380f4d3d64bde0a13d15fb59a71f3 (patch) | |
tree | 38c9e0b1117323c58536706a66830109225d6200 /main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java | |
parent | c51fa0d4e953518571a115af4afdea80a17ed605 (diff) |
Migrate pap startup & controllers to spring boot
This commit migrates pap config, startup and controllers to spring boot.
Change-Id: Icf91d728160a23db614dfba6b40ddccd2f6163a5
Issue-ID: POLICY-3754
Signed-off-by: a.sreekumar <ajith.sreekumar@bell.ca>
Diffstat (limited to 'main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java')
-rw-r--r-- | main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java | 46 |
1 files changed, 20 insertions, 26 deletions
diff --git a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java index 576eb8d8..03a853ba 100644 --- a/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java +++ b/main/src/main/java/org/onap/policy/pap/main/rest/PdpGroupQueryControllerV1.java @@ -2,6 +2,7 @@ * ============LICENSE_START======================================================= * Copyright (C) 2019,2021 Nordix Foundation. * Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property. + * Modifications Copyright (C) 2021 Bell Canada. All rights reserved. * ================================================================================ * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,38 +31,38 @@ import io.swagger.annotations.Extension; import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.ResponseHeader; import java.util.UUID; -import javax.ws.rs.GET; -import javax.ws.rs.HeaderParam; -import javax.ws.rs.Path; -import javax.ws.rs.core.Response; -import javax.ws.rs.core.Response.Status; +import lombok.RequiredArgsConstructor; import org.apache.commons.lang3.tuple.Pair; import org.onap.policy.models.base.PfModelException; -import org.onap.policy.models.base.PfModelRuntimeException; import org.onap.policy.models.pdp.concepts.PdpGroups; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.springframework.http.HttpStatus; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestHeader; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; /** * Class to provide REST end points for PAP component to query details of all PDP groups. * * @author Ram Krishna Verma (ram.krishna.verma@est.tech) */ +@RestController +@RequestMapping(path = "/policy/pap/v1") +@RequiredArgsConstructor public class PdpGroupQueryControllerV1 extends PapRestControllerV1 { - private static final Logger LOGGER = LoggerFactory.getLogger(PdpGroupQueryControllerV1.class); - - private final PdpGroupQueryProvider provider = new PdpGroupQueryProvider(); + private final PdpGroupQueryProvider provider; /** * Queries details of all PDP groups. * * @param requestId request ID used in ONAP logging * @return a response + * @throws PfModelException the exception */ // @formatter:off - @GET - @Path("pdps") + @GetMapping("pdps") @ApiOperation(value = "Query details of all PDP groups", notes = "Queries details of all PDP groups, returning all group details", response = PdpGroups.class, @@ -89,19 +90,12 @@ public class PdpGroupQueryControllerV1 extends PapRestControllerV1 { @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE) }) // @formatter:on + public ResponseEntity<PdpGroups> queryGroupDetails(@ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader( + required = false, + value = REQUEST_ID_NAME) final UUID requestId) throws PfModelException { - public Response queryGroupDetails( - @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId) { - - try { - final Pair<Status, PdpGroups> pair = provider.fetchPdpGroupDetails(); - return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId) - .entity(pair.getRight()).build(); - } catch (final PfModelException | PfModelRuntimeException exp) { - LOGGER.info("group query failed", exp); - return addLoggingHeaders( - addVersionControlHeaders(Response.status(exp.getErrorResponse().getResponseCode())), requestId) - .entity(exp.getErrorResponse()).build(); - } + final Pair<HttpStatus, PdpGroups> pair = provider.fetchPdpGroupDetails(); + return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(pair.getLeft())), requestId) + .body(pair.getRight()); } } |