2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.policy.pap.main.rest;
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.PUT;
34 import javax.ws.rs.Path;
35 import javax.ws.rs.PathParam;
36 import javax.ws.rs.QueryParam;
37 import javax.ws.rs.core.Response;
38 import javax.ws.rs.core.Response.Status;
39 import org.apache.commons.lang3.tuple.Pair;
40 import org.onap.policy.models.pap.concepts.PdpGroupStateChangeResponse;
41 import org.onap.policy.models.pdp.enums.PdpState;
44 * Class to provide REST end points for PAP component to change state of a PDP group.
46 * @author Ram Krishna Verma (ram.krishna.verma@est.tech)
48 public class PdpGroupStateChangeControllerV1 extends PapRestControllerV1 {
50 private final PdpGroupStateChangeProvider provider = new PdpGroupStateChangeProvider();
53 * Changes state of a PDP group.
55 * @param requestId request ID used in ONAP logging
56 * @param groupName name of the PDP group to be deleted
57 * @param version version of the PDP group
58 * @param state state of the PDP group
63 @Path("pdps/groups/{name}/versions/{version}")
64 @ApiOperation(value = "Change state of a PDP Group",
65 notes = "Changes state of PDP Group, returning optional error details",
66 response = PdpGroupStateChangeResponse.class,
67 tags = {"Policy Administration (PAP) API"},
68 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
70 @ResponseHeader(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
71 response = String.class),
72 @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
73 response = String.class),
74 @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
75 response = String.class),
76 @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
77 response = UUID.class)},
78 extensions = {@Extension(name = EXTENSION_NAME,
79 properties = {@ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
80 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)})})
81 @ApiResponses(value = {@ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
82 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
83 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)})
86 public Response changeGroupState(
87 @HeaderParam(REQUEST_ID_NAME) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) final UUID requestId,
88 @ApiParam(value = "PDP Group Name", required = true) @PathParam("name") final String groupName,
89 @ApiParam(value = "PDP Group Version", required = true) @PathParam("version") final String version,
90 @ApiParam(value = "PDP Group State", required = true) @QueryParam("state") final PdpState state) {
92 final Pair<Status, PdpGroupStateChangeResponse> pair = provider.changeGroupState(groupName, version, state);
94 return addLoggingHeaders(addVersionControlHeaders(Response.status(pair.getLeft())), requestId)
95 .entity(pair.getRight()).build();