Merge "Update INFO.yaml file"
[policy/pap.git] / main / src / main / java / org / onap / policy / pap / main / rest / PdpGroupDeleteControllerV1.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.DELETE;
33 import javax.ws.rs.HeaderParam;
34 import javax.ws.rs.Path;
35 import javax.ws.rs.PathParam;
36 import javax.ws.rs.core.Response;
37 import javax.ws.rs.core.Response.Status;
38 import org.apache.commons.lang3.tuple.Pair;
39 import org.onap.policy.models.pap.concepts.PdpGroupDeleteResponse;
40
41 /**
42  * Class to provide REST end points for PAP component to delete a PDP group.
43  */
44 public class PdpGroupDeleteControllerV1 extends PapRestControllerV1 {
45
46     private final PdpGroupDeleteProvider provider = new PdpGroupDeleteProvider();
47
48     /**
49      * Deletes a PDP group.
50      *
51      * @param requestId request ID used in ONAP logging
52      * @param groupName name of the PDP group to be deleted
53      * @return a response
54      */
55     // @formatter:off
56     @DELETE
57     @Path("pdps/groups/{name}")
58     @ApiOperation(value = "Delete PDP Group",
59         notes = "Deletes a PDP Group, returning optional error details",
60         response = PdpGroupDeleteResponse.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 deleteGroup(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
81                     @ApiParam(value = "PDP Group Name", required = true) @PathParam("name") String groupName) {
82
83         Pair<Status, PdpGroupDeleteResponse> pair = provider.deleteGroup(groupName, null);
84
85         return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
86                         .entity(pair.getRight()).build();
87     }
88
89     /**
90      * Deletes a particular version of a PDP group.
91      *
92      * @param requestId request ID used in ONAP logging
93      * @param groupName name of the PDP group to be deleted
94      * @param version version to be deleted
95      * @return a response
96      */
97     // @formatter:off
98     @DELETE
99     @Path("pdps/groups/{name}/versions/{version}")
100     @ApiOperation(value = "Delete version of a PDP Group",
101         notes = "Deletes a version of PDP Group, returning optional error details",
102         response = PdpGroupDeleteResponse.class,
103         tags = {"Policy Administration (PAP) API"},
104         authorizations = @Authorization(value = AUTHORIZATION_TYPE),
105         responseHeaders = {
106             @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
107                             response = String.class),
108             @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
109                             response = String.class),
110             @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
111                             response = String.class),
112             @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
113                             response = UUID.class)},
114         extensions = {@Extension(name = EXTENSION_NAME,
115             properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
116                 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
117     @ApiResponses(value = {@ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
118                     @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
119                     @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
120     // @formatter:on
121
122     public Response deleteGroupVersion(
123                     @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
124                     @ApiParam(value = "PDP Group Name", required = true) @PathParam("name") String groupName,
125                     @ApiParam(value = "PDP Group Version", required = true) @PathParam("version") String version) {
126
127         Pair<Status, PdpGroupDeleteResponse> pair = provider.deleteGroup(groupName, version);
128
129         return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
130                         .entity(pair.getRight()).build();
131     }
132
133     /**
134      * Deletes a PDP policy.
135      *
136      * @param requestId request ID used in ONAP logging
137      * @param policyName name of the PDP Policy to be deleted
138      * @return a response
139      */
140     // @formatter:off
141     @DELETE
142     @Path("pdps/policies/{name}")
143     @ApiOperation(value = "Delete PDP Policy",
144         notes = "Deletes a PDP Policy, returning optional error details",
145         response = PdpGroupDeleteResponse.class,
146         tags = {"Policy Administration (PAP) API"},
147         authorizations = @Authorization(value = AUTHORIZATION_TYPE),
148         responseHeaders = {
149             @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
150                             response = String.class),
151             @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
152                             response = String.class),
153             @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
154                             response = String.class),
155             @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
156                             response = UUID.class)},
157         extensions = {@Extension(name = EXTENSION_NAME,
158             properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
159                 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
160     @ApiResponses(value = {@ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
161                     @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
162                     @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
163     // @formatter:on
164
165     public Response deletePolicy(@HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
166                     @ApiParam(value = "PDP Policy Name", required = true) @PathParam("name") String policyName) {
167
168         Pair<Status, PdpGroupDeleteResponse> pair = provider.deletePolicy(policyName, null);
169
170         return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
171                         .entity(pair.getRight()).build();
172     }
173
174     /**
175      * Deletes a specific version of a PDP policy.
176      *
177      * @param requestId request ID used in ONAP logging
178      * @param policyName name of the PDP Policy to be deleted
179      * @param version version to be deleted
180      * @return a response
181      */
182     // @formatter:off
183     @DELETE
184     @Path("pdps/policies/{name}/versions/{version}")
185     @ApiOperation(value = "Delete version of a PDP Policy",
186         notes = "Deletes a version of a PDP Policy, returning optional error details",
187         response = PdpGroupDeleteResponse.class,
188         tags = {"Policy Administration (PAP) API"},
189         authorizations = @Authorization(value = AUTHORIZATION_TYPE),
190         responseHeaders = {
191             @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
192                             response = String.class),
193             @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
194                             response = String.class),
195             @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
196                             response = String.class),
197             @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
198                             response = UUID.class)},
199         extensions = {@Extension(name = EXTENSION_NAME,
200             properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
201                 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
202     @ApiResponses(value = {@ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
203                     @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
204                     @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
205     // @formatter:on
206
207     public Response deletePolicyVersion(
208                     @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
209                     @ApiParam(value = "PDP Policy Name", required = true) @PathParam("name") String policyName,
210                     @ApiParam(value = "PDP Policy Version", required = true) @PathParam("version") String version) {
211
212         Pair<Status, PdpGroupDeleteResponse> pair = provider.deletePolicy(policyName, version);
213
214         return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
215                         .entity(pair.getRight()).build();
216     }
217 }