cf4ac8eb79fce8dc55d2d8392b9c29ab31d3a7a7
[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 jakarta.validation.Valid;
24 import jakarta.ws.rs.core.MediaType;
25 import java.util.UUID;
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.AutomationComposition;
33 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
34 import org.springframework.http.HttpStatus;
35 import org.springframework.http.ResponseEntity;
36 import org.springframework.web.bind.annotation.RequestBody;
37 import org.springframework.web.bind.annotation.RequestMapping;
38 import org.springframework.web.bind.annotation.RestController;
39
40 @RequiredArgsConstructor
41 @RestController
42 @RequestMapping(value = "/v2", produces = {MediaType.APPLICATION_JSON})
43 public class SimulatorController implements SimulatorParticipantControllerApi {
44
45     private final AutomationCompositionElementHandler automationCompositionElementHandler;
46
47     @Override
48     public ResponseEntity<SimConfig> getConfig(UUID xonapRequestId) {
49         return new ResponseEntity<>(automationCompositionElementHandler.getConfig(), HttpStatus.OK);
50     }
51
52     @Override
53     public ResponseEntity<Void> setConfig(UUID xonapRequestId, @Valid @RequestBody SimConfig body) {
54         automationCompositionElementHandler.setConfig(body);
55         return new ResponseEntity<>(HttpStatus.OK);
56     }
57
58     @Override
59     public ResponseEntity<AutomationCompositions> getAutomationCompositions(UUID xonapRequestId) {
60         return new ResponseEntity<>(automationCompositionElementHandler.getAutomationCompositions(), HttpStatus.OK);
61     }
62
63     @Override
64     public ResponseEntity<AutomationComposition> getAutomationComposition(UUID instanceId, UUID xonapRequestId) {
65         return new ResponseEntity<>(automationCompositionElementHandler.getAutomationComposition(instanceId),
66                 HttpStatus.OK);
67     }
68
69     @Override
70     public ResponseEntity<InternalDatas> getDatas(UUID xonapRequestId) {
71         return new ResponseEntity<>(automationCompositionElementHandler.getDataList(), HttpStatus.OK);
72     }
73
74     /**
75      * Set instance Data.
76      *
77      * @param body the Data
78      * @return Void
79      */
80     @Override
81     public ResponseEntity<Void> setData(UUID xonapRequestId, @Valid @RequestBody InternalData body) {
82         automationCompositionElementHandler.setOutProperties(body.getAutomationCompositionId(),
83                 body.getAutomationCompositionElementId(), body.getUseState(), body.getOperationalState(),
84                 body.getOutProperties());
85         return new ResponseEntity<>(HttpStatus.OK);
86     }
87
88     @Override
89     public ResponseEntity<InternalDatas> getCompositionDatas(UUID xonapRequestId) {
90         return new ResponseEntity<>(automationCompositionElementHandler.getCompositionDataList(), HttpStatus.OK);
91     }
92
93     @Override
94     public ResponseEntity<Void> setCompositionData(UUID xonapRequestId, @Valid InternalData body) {
95         automationCompositionElementHandler.setCompositionOutProperties(body.getCompositionId(),
96                 body.getCompositionDefinitionElementId(), body.getOutProperties());
97         return new ResponseEntity<>(HttpStatus.OK);
98     }
99 }