277638220cb4d93328d0742bfac8782c5507a280
[policy/clamp.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  *  Copyright (C) 2021 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.simulator.simulation.rest;
22
23 import io.swagger.annotations.ApiOperation;
24 import io.swagger.annotations.ApiParam;
25 import io.swagger.annotations.ApiResponse;
26 import io.swagger.annotations.ApiResponses;
27 import io.swagger.annotations.Authorization;
28 import io.swagger.annotations.Extension;
29 import io.swagger.annotations.ExtensionProperty;
30 import io.swagger.annotations.ResponseHeader;
31 import java.util.Map;
32 import java.util.UUID;
33 import org.onap.policy.clamp.acm.participant.simulator.main.rest.AbstractRestController;
34 import org.onap.policy.clamp.acm.participant.simulator.simulation.SimulationProvider;
35 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositionElement;
36 import org.onap.policy.clamp.models.acm.concepts.AutomationCompositions;
37 import org.onap.policy.clamp.models.acm.messages.rest.TypedSimpleResponse;
38 import org.springframework.http.ResponseEntity;
39 import org.springframework.web.bind.annotation.GetMapping;
40 import org.springframework.web.bind.annotation.PathVariable;
41 import org.springframework.web.bind.annotation.PutMapping;
42 import org.springframework.web.bind.annotation.RequestBody;
43 import org.springframework.web.bind.annotation.RequestHeader;
44 import org.springframework.web.bind.annotation.RestController;
45
46 /**
47  * Class to provide REST end points for participant simulator to query/update details of automationCompositionElements.
48  */
49 @RestController
50 public class SimulationElementController extends AbstractRestController {
51
52     /**
53      * Constructor.
54      *
55      * @param simulationProvider the Simulation Provider
56      */
57     public SimulationElementController(SimulationProvider simulationProvider) {
58         super(simulationProvider);
59     }
60
61     /**
62      * Queries details of all automation composition element within the simulator.
63      *
64      * @param requestId request ID used in ONAP logging
65      * @param name the name of the Automation Composition element to get, null to get all
66      * @param version the version of the Automation Composition element to get, null to get all
67      * @return the automation composition elements
68      */
69     // @formatter:off
70     @GetMapping("/elements/{name}/{version}")
71     @ApiOperation(
72         value = "Query details of the requested simulated automation composition elements",
73         notes = "Queries details of the requested simulated automation composition elements, "
74                 + "returning all automation composition element details",
75         response = AutomationCompositions.class,
76         tags = {
77             "Clamp Automation Composition Participant Simulator API"
78         },
79         authorizations = @Authorization(value = AUTHORIZATION_TYPE),
80         responseHeaders = {
81             @ResponseHeader(
82                 name = VERSION_MINOR_NAME, description = VERSION_MINOR_DESCRIPTION,
83                 response = String.class),
84             @ResponseHeader(name = VERSION_PATCH_NAME, description = VERSION_PATCH_DESCRIPTION,
85                 response = String.class),
86             @ResponseHeader(name = VERSION_LATEST_NAME, description = VERSION_LATEST_DESCRIPTION,
87                 response = String.class),
88             @ResponseHeader(name = REQUEST_ID_NAME, description = REQUEST_ID_HDR_DESCRIPTION,
89                 response = UUID.class)},
90         extensions = {
91             @Extension
92                 (
93                     name = EXTENSION_NAME,
94                     properties = {
95                         @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
96                         @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
97                     }
98                 )
99         }
100     )
101     @ApiResponses(
102         value = {
103             @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
104             @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
105             @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
106         }
107     )
108     // @formatter:on
109     public ResponseEntity<Map<UUID, AutomationCompositionElement>> elements(
110         @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
111         @ApiParam(value = "Automation composition element name", required = true) @PathVariable("name") String name,
112         @ApiParam(
113             value = "Automation composition element version",
114             required = true) @PathVariable("version") String version) {
115
116         return ResponseEntity
117             .ok()
118             .headers(super.getCommonHeaders(requestId))
119             .body(getSimulationProvider().getAutomationCompositionElements(name, version));
120     }
121
122     /**
123      * Updates a automation composition element in the simulator.
124      *
125      * @param requestId request ID used in ONAP logging
126      * @param body the body of a automation composition element
127      * @return a response
128      */
129     // @formatter:off
130     @PutMapping("/elements")
131     @ApiOperation(
132             value = "Updates simulated automation composition elements",
133             notes = "Updates simulated automation composition elements, "
134                 + "returning the updated automation composition definition IDs",
135             response = TypedSimpleResponse.class,
136             tags = {
137                 "Clamp Automation Composition Participant Simulator API"
138                 },
139             authorizations = @Authorization(value = AUTHORIZATION_TYPE),
140             responseHeaders = {
141                 @ResponseHeader(
142                     name = VERSION_MINOR_NAME,
143                     description = VERSION_MINOR_DESCRIPTION,
144                     response = String.class),
145                 @ResponseHeader(
146                     name = VERSION_PATCH_NAME,
147                     description = VERSION_PATCH_DESCRIPTION,
148                     response = String.class),
149                 @ResponseHeader(
150                     name = VERSION_LATEST_NAME,
151                     description = VERSION_LATEST_DESCRIPTION,
152                     response = String.class),
153                 @ResponseHeader(
154                     name = REQUEST_ID_NAME,
155                     description = REQUEST_ID_HDR_DESCRIPTION,
156                     response = UUID.class)
157             },
158             extensions = {
159                 @Extension
160                     (
161                         name = EXTENSION_NAME,
162                         properties = {
163                             @ExtensionProperty(name = API_VERSION_NAME, value = API_VERSION),
164                             @ExtensionProperty(name = LAST_MOD_NAME, value = LAST_MOD_RELEASE)
165                         }
166                     )
167             }
168         )
169     @ApiResponses(
170             value = {
171                 @ApiResponse(code = AUTHENTICATION_ERROR_CODE, message = AUTHENTICATION_ERROR_MESSAGE),
172                 @ApiResponse(code = AUTHORIZATION_ERROR_CODE, message = AUTHORIZATION_ERROR_MESSAGE),
173                 @ApiResponse(code = SERVER_ERROR_CODE, message = SERVER_ERROR_MESSAGE)
174             }
175         )
176     // @formatter:on
177     public ResponseEntity<TypedSimpleResponse<AutomationCompositionElement>> update(
178         @RequestHeader(name = REQUEST_ID_NAME, required = false) @ApiParam(REQUEST_ID_PARAM_DESCRIPTION) UUID requestId,
179         @ApiParam(
180             value = "Body of a automation composition element",
181             required = true) @RequestBody AutomationCompositionElement body) {
182
183         return ResponseEntity
184             .ok()
185             .headers(super.getCommonHeaders(requestId))
186             .body(getSimulationProvider().updateAutomationCompositionElement(body));
187     }
188 }