Migrate pap startup & controllers to spring boot
[policy/pap.git] / main / src / main / java / org / onap / policy / pap / main / rest / PdpGroupQueryControllerV1.java
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2019,2021 Nordix Foundation.
4  *  Modifications Copyright (C) 2019, 2021 AT&T Intellectual Property.
5  *  Modifications Copyright (C) 2021 Bell Canada. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  * SPDX-License-Identifier: Apache-2.0
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.policy.pap.main.rest;
24
25 import io.swagger.annotations.ApiOperation;
26 import io.swagger.annotations.ApiParam;
27 import io.swagger.annotations.ApiResponse;
28 import io.swagger.annotations.ApiResponses;
29 import io.swagger.annotations.Authorization;
30 import io.swagger.annotations.Extension;
31 import io.swagger.annotations.ExtensionProperty;
32 import io.swagger.annotations.ResponseHeader;
33 import java.util.UUID;
34 import lombok.RequiredArgsConstructor;
35 import org.apache.commons.lang3.tuple.Pair;
36 import org.onap.policy.models.base.PfModelException;
37 import org.onap.policy.models.pdp.concepts.PdpGroups;
38 import org.springframework.http.HttpStatus;
39 import org.springframework.http.ResponseEntity;
40 import org.springframework.web.bind.annotation.GetMapping;
41 import org.springframework.web.bind.annotation.RequestHeader;
42 import org.springframework.web.bind.annotation.RequestMapping;
43 import org.springframework.web.bind.annotation.RestController;
44
45 /**
46  * Class to provide REST end points for PAP component to query details of all PDP groups.
47  *
48  * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
49  */
50 @RestController
51 @RequestMapping(path = "/policy/pap/v1")
52 @RequiredArgsConstructor
53 public class PdpGroupQueryControllerV1 extends PapRestControllerV1 {
54
55     private final PdpGroupQueryProvider provider;
56
57     /**
58      * Queries details of all PDP groups.
59      *
60      * @param requestId request ID used in ONAP logging
61      * @return a response
62      * @throws PfModelException the exception
63      */
64     // @formatter:off
65     @GetMapping("pdps")
66     @ApiOperation(value = "Query details of all PDP groups",
67         notes = "Queries details of all PDP groups, returning all group details",
68         response = PdpGroups.class,
69         tags = {"PdpGroup Query"},
70         authorizations = @Authorization(value = AUTHORIZATION_TYPE),
71         responseHeaders = {
72             @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
73                             response = String.class),
74             @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
75                             response = String.class),
76             @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
77                             response = String.class),
78             @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
79                             response = UUID.class)},
80         extensions = {
81             @Extension(name = EXTENSION_NAME,
82                 properties = {
83                     @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
84                     @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
85                 })
86             })
87     @ApiResponses(value = {
88         @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
89         @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
90         @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
91     })
92     // @formatter:on
93     public ResponseEntity<PdpGroups> queryGroupDetails(@ApiParam(REQUEST_ID_PARAM_DESCRIPTION) @RequestHeader(
94         required = false,
95         value = REQUEST_ID_NAME) final UUID requestId) throws PfModelException {
96
97         final Pair<HttpStatus, PdpGroups> pair = provider.fetchPdpGroupDetails();
98         return addLoggingHeaders(addVersionControlHeaders(ResponseEntity.status(pair.getLeft())), requestId)
99             .body(pair.getRight());
100     }
101 }