a12e5f70d6ab8f37f183ec7e14fdea9e71805d43
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2023 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.participant.sim.rest;
22
23 import java.util.UUID;
24 import javax.validation.Valid;
25 import javax.ws.rs.core.MediaType;
26 import lombok.RequiredArgsConstructor;
27 import org.onap.policy.clamp.acm.participant.sim.controller.genapi.SimulatorParticipantControllerApi;
28 import org.onap.policy.clamp.acm.participant.sim.main.handler.AutomationCompositionElementHandler;
29 import org.onap.policy.clamp.acm.participant.sim.model.InternalData;
30 import org.onap.policy.clamp.acm.participant.sim.model.InternalDatas;
31 import org.onap.policy.clamp.acm.participant.sim.model.SimConfig;
32 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
33 import org.springframework.http.HttpStatus;
34 import org.springframework.http.ResponseEntity;
35 import org.springframework.web.bind.annotation.RequestBody;
36 import org.springframework.web.bind.annotation.RequestMapping;
37 import org.springframework.web.bind.annotation.RestController;
38
39 @RequiredArgsConstructor
40 @RestController
41 @RequestMapping(value = "/v2", produces = {MediaType.APPLICATION_JSON})
42 public class SimulatorController implements SimulatorParticipantControllerApi {
43
44     private final AutomationCompositionElementHandler automationCompositionElementHandler;
45
46     @Override
47     public ResponseEntity<SimConfig> getConfig(UUID xonapRequestId) {
48         return new ResponseEntity<>(automationCompositionElementHandler.getConfig(), HttpStatus.OK);
49     }
50
51     @Override
52     public ResponseEntity<Void> setConfig(UUID xonapRequestId, @Valid @RequestBody SimConfig body) {
53         automationCompositionElementHandler.setConfig(body);
54         return new ResponseEntity<>(HttpStatus.OK);
55     }
56
57     @Override
58     public ResponseEntity<AutomationCompositions> getAutomationCompositions(UUID xonapRequestId) {
59         return new ResponseEntity<>(automationCompositionElementHandler.getAutomationCompositions(), HttpStatus.OK);
60     }
61
62     @Override
63     public ResponseEntity<InternalDatas> getDatas(UUID xonapRequestId) {
64         return new ResponseEntity<>(automationCompositionElementHandler.getDataList(), HttpStatus.OK);
65     }
66
67     /**
68      * Set Data.
69      *
70      * @param body the Data
71      * @return Void
72      */
73     @Override
74     public ResponseEntity<Void> setData(UUID xonapRequestId, @Valid @RequestBody InternalData body) {
75         automationCompositionElementHandler.setOutProperties(body.getAutomationCompositionId(),
76                 body.getAutomationCompositionElementId(), body.getUseState(), body.getOperationalState(),
77                 body.getOutProperties());
78         return new ResponseEntity<>(HttpStatus.OK);
79     }
80 }