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.v3.oas.annotations.Operation;
24 import io.swagger.v3.oas.annotations.headers.Header;
25 import io.swagger.v3.oas.annotations.media.Content;
26 import io.swagger.v3.oas.annotations.media.Schema;
27 import io.swagger.v3.oas.annotations.responses.ApiResponse;
28 import io.swagger.v3.oas.annotations.responses.ApiResponses;
29 import lombok.RequiredArgsConstructor;
30 import org.onap.policy.clamp.acm.element.service.ConfigService;
31 import org.onap.policy.clamp.models.acm.messages.rest.element.ElementConfig;
32 import org.springframework.http.HttpStatus;
33 import org.springframework.http.MediaType;
34 import org.springframework.http.ResponseEntity;
35 import org.springframework.web.bind.annotation.DeleteMapping;
36 import org.springframework.web.bind.annotation.GetMapping;
37 import org.springframework.web.bind.annotation.PostMapping;
38 import org.springframework.web.bind.annotation.RequestBody;
39 import org.springframework.web.bind.annotation.RestController;
42 @RequiredArgsConstructor
43 public class AcElementController extends AbstractRestController {
45 private final ConfigService configService;
48 * REST endpoint to get the existing element config.
50 * @return the element config params
53 @GetMapping(path = "/config", produces = MediaType.APPLICATION_JSON_VALUE)
54 @Operation(summary = "Return the element config",
55 tags = { "Clamp Automation Composition AC Element Impl API" })
58 @ApiResponse(responseCode = OK_CODE, description = SERVER_OK_MESSAGE,
59 content = @Content(schema = @Schema(implementation = ElementConfig.class)),
61 @Header(name = API_VERSION_NAME),
62 @Header(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION),
63 @Header(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION),
64 @Header(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION),
65 @Header(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION),
66 @Header(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION)
68 @ApiResponse(responseCode = AUTHENTICATION_ERROR_CODE, description = AUTHENTICATION_ERROR_MESSAGE)
72 public ResponseEntity<ElementConfig> getElementConfig() {
73 return new ResponseEntity<>(configService.getElementConfig(), HttpStatus.OK);
77 * REST endpoint to activate the element.
79 * @param params element parameters for this ac element
82 @PostMapping(path = "/activate", consumes = MediaType.APPLICATION_JSON_VALUE,
83 produces = MediaType.APPLICATION_JSON_VALUE)
84 @Operation(summary = "Activates the element config",
85 tags = { "Clamp Automation Composition AC Element Impl API" }
89 @ApiResponse(responseCode = CREATED_CODE, description = SERVER_OK_MESSAGE,
91 @Header(name = API_VERSION_NAME),
92 @Header(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION),
93 @Header(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION),
94 @Header(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION),
95 @Header(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION),
96 @Header(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION)
98 @ApiResponse(responseCode = AUTHENTICATION_ERROR_CODE, description = AUTHENTICATION_ERROR_MESSAGE),
99 @ApiResponse(responseCode = BAD_REQUEST_ERROR_CODE, description = BAD_REQUEST_ERROR_MESSAGE)
103 public ResponseEntity<Object> activateElement(@RequestBody ElementConfig params) {
104 configService.activateElement(params);
105 return new ResponseEntity<>(HttpStatus.CREATED);
109 * REST endpoint to delete the element config.
111 * @return Status of operation
114 @DeleteMapping(path = "/deactivate")
115 @Operation(summary = "Delete the element config",
116 tags = { "Clamp Automation Composition AC Element Impl API" }
120 @ApiResponse(responseCode = NO_CONTENT_CODE, description = SERVER_OK_MESSAGE,
122 @Header(name = API_VERSION_NAME),
123 @Header(name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION),
124 @Header(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION),
125 @Header(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION),
126 @Header(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION),
127 @Header(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION)
129 @ApiResponse(responseCode = AUTHENTICATION_ERROR_CODE, description = AUTHENTICATION_ERROR_MESSAGE)
133 public ResponseEntity<Void> deleteConfig() {
134 configService.deleteConfig();
135 return new ResponseEntity<>(HttpStatus.NO_CONTENT);