2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2022 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.clamp.acm.element.main.rest;
23 import io.swagger.annotations.ApiOperation;
24 import io.swagger.annotations.ApiResponse;
25 import io.swagger.annotations.ApiResponses;
26 import io.swagger.annotations.Authorization;
27 import io.swagger.annotations.Extension;
28 import io.swagger.annotations.ExtensionProperty;
29 import io.swagger.annotations.ResponseHeader;
30 import java.util.UUID;
31 import lombok.RequiredArgsConstructor;
32 import org.onap.policy.clamp.acm.element.service.ConfigService;
33 import org.onap.policy.clamp.models.acm.messages.rest.element.ElementConfig;
34 import org.springframework.http.HttpStatus;
35 import org.springframework.http.MediaType;
36 import org.springframework.http.ResponseEntity;
37 import org.springframework.web.bind.annotation.DeleteMapping;
38 import org.springframework.web.bind.annotation.GetMapping;
39 import org.springframework.web.bind.annotation.PostMapping;
40 import org.springframework.web.bind.annotation.RequestBody;
41 import org.springframework.web.bind.annotation.RestController;
44 @RequiredArgsConstructor
45 public class AcElementController extends AbstractRestController {
47 private final ConfigService configService;
51 * REST endpoint to get the existing element config.
53 * @return the element config params
56 @GetMapping(path = "/config", produces = MediaType.APPLICATION_JSON_VALUE)
58 value = "Return the element config",
59 response = ElementConfig.class,
61 "Clamp Automation Composition AC Element Impl API"
63 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
66 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
67 response = String.class),
69 name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
70 response = String.class),
72 name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
73 response = String.class),
75 name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
76 response = UUID.class)},
79 name = EXTENSION_NAME,
81 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
82 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
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)
94 public ResponseEntity<ElementConfig> getElementConfig() {
95 return new ResponseEntity<>(configService.getElementConfig(), HttpStatus.OK);
99 * REST endpoint to activate the element.
101 * @param params element parameters for this ac element
104 @PostMapping(path = "/activate", consumes = MediaType.APPLICATION_JSON_VALUE,
105 produces = MediaType.APPLICATION_JSON_VALUE)
107 value = "Activates the element config",
108 response = ElementConfig.class,
110 "Clamp Automation Composition AC Element Impl API"
112 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
115 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
116 response = String.class),
118 name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
119 response = String.class),
121 name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
122 response = String.class),
124 name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
125 response = UUID.class)
129 name = EXTENSION_NAME,
131 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
132 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
139 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
140 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
141 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
145 public ResponseEntity<Object> activateElement(@RequestBody ElementConfig params) {
146 configService.activateElement(params);
147 return new ResponseEntity<>(HttpStatus.CREATED);
151 * REST endpoint to delete the element config.
153 * @return Status of operation
156 @DeleteMapping(path = "/deactivate")
158 value = "Delete the element config",
159 response = ElementConfig.class,
161 "Clamp Automation Composition AC Element Impl API"
163 authorizations = @Authorization(value = AUTHORIZATION_TYPE),
166 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
167 response = String.class),
169 name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
170 response = String.class),
172 name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
173 response = String.class),
175 name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
176 response = UUID.class)},
179 name = EXTENSION_NAME,
181 @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
182 @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
189 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
190 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
191 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
195 public ResponseEntity<Object> deleteConfig() {
196 configService.deleteConfig();
197 return new ResponseEntity<>(HttpStatus.NO_CONTENT);