021567a7b0b77ce294d52993eae686abd1d35a54
[policy/clamp.git] /
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.policy.clamp.acm.element.main.rest;
22
23 import java.util.UUID;
24 import lombok.RequiredArgsConstructor;
25 import org.onap.policy.clamp.acm.element.main.rest.genapi.AcElementControllerApi;
26 import org.onap.policy.clamp.acm.element.service.ConfigService;
27 import org.onap.policy.clamp.models.acm.messages.rest.element.ElementConfig;
28 import org.springframework.http.HttpStatus;
29 import org.springframework.http.ResponseEntity;
30 import org.springframework.web.bind.annotation.RestController;
31
32 @RestController
33 @RequiredArgsConstructor
34 public class AcElementController implements AcElementControllerApi {
35
36     private final ConfigService configService;
37
38     /**
39      * REST end point to get the existing element configuration.
40      *
41      * @return the element configuration parameters
42      */
43     @Override
44     public ResponseEntity<ElementConfig> getElementConfig(UUID onapRequestId) {
45         return new ResponseEntity<>(configService.getElementConfig(), HttpStatus.OK);
46     }
47
48     /**
49      * REST end point to activate the element.
50      *
51      * @param params element parameters for this AC element
52      */
53     @Override
54     public ResponseEntity<String> activateElement(UUID onapRequestId, ElementConfig params) {
55         configService.activateElement(params);
56         return new ResponseEntity<>(HttpStatus.CREATED);
57     }
58
59     /**
60      * REST end point to delete the element configuration.
61      *
62      * @return Status of operation
63      */
64     @Override
65     public ResponseEntity<Void> deleteConfig(UUID onapRequestId) {
66         configService.deleteConfig();
67         return new ResponseEntity<>(HttpStatus.NO_CONTENT);
68     }
69 }