Add PDP Group Deploy and Delete REST API stubs
[policy/pap.git] / main / src / main / java / org / onap / policy / pap / main / rest / PdpGroupDeployControllerV1.java
1 /*
2  * ============LICENSE_START=======================================================
3  * ONAP PAP
4  * ================================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. 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  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.pap.main.rest;
22
23 import io.swagger.annotations.ApiOperation;
24 import io.swagger.annotations.ApiParam;
25 import io.swagger.annotations.ApiResponse;
26 import io.swagger.annotations.ApiResponses;
27 import io.swagger.annotations.Authorization;
28 import io.swagger.annotations.Extension;
29 import io.swagger.annotations.ExtensionProperty;
30 import io.swagger.annotations.ResponseHeader;
31 import java.util.UUID;
32 import javax.ws.rs.HeaderParam;
33 import javax.ws.rs.POST;
34 import javax.ws.rs.Path;
35 import javax.ws.rs.core.Response;
36 import javax.ws.rs.core.Response.Status;
37 import org.apache.commons.lang3.tuple.Pair;
38 import org.onap.policy.models.pap.concepts.PdpGroup;
39 import org.onap.policy.models.pap.concepts.PdpGroupDeployResponse;
40
41 /**
42  * Class to provide REST end points for PAP component to deploy a PDP group.
43  */
44 public class PdpGroupDeployControllerV1 extends PapRestControllerV1 {
45
46     private final PdpGroupDeployProvider provider = new PdpGroupDeployProvider();
47
48     /**
49      * Deploys or updates a PDP group.
50      *
51      * @param requestId request ID used in ONAP logging
52      * @param group PDP group configuration
53      * @return a response
54      */
55     // @formatter:off
56     @POST
57     @Path("pdps")
58     @ApiOperation(value = "Deploy or update PDP Group",
59         notes = "Deploys or updates a PDP Group, returning optional error details",
60         response = PdpGroupDeployResponse.class,
61         tags = {"Policy Administration (PAP) API"},
62         authorizations = @Authorization(value = AUTHORIZATION_TYPE),
63         responseHeaders = {
64             @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
65                             response = String.class),
66             @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
67                             response = String.class),
68             @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
69                             response = String.class),
70             @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
71                             response = UUID.class)},
72         extensions = {@Extension(name = EXTENSION_NAME,
73             properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
74                 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
75     @ApiResponses(value = {@ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
76                     @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
77                     @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
78     // @formatter:on
79
80     public Response deploy(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
81                     @ApiParam(value = "PDP Group Configuration", required = true) PdpGroup group) {
82
83         Pair<Status, PdpGroupDeployResponse> pair = provider.deploy(group);
84
85         return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
86                         .entity(pair.getRight()).build();
87     }
88 }