1fa51246260000cae5b5c4916a57b120f0af00d2
[ccsdk/oran.git] /
1 /*-
2  * ========================LICENSE_START=================================
3  * O-RAN-SC
4  * %%
5  * Copyright (C) 2020 Nordix Foundation
6  * %%
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ========================LICENSE_END===================================
19  */
20
21 package org.onap.ccsdk.oran.a1policymanagementservice.controllers.v2;
22
23 import com.google.gson.Gson;
24 import com.google.gson.GsonBuilder;
25
26 import io.swagger.v3.oas.annotations.Operation;
27 import io.swagger.v3.oas.annotations.media.Content;
28 import io.swagger.v3.oas.annotations.media.Schema;
29 import io.swagger.v3.oas.annotations.responses.ApiResponse;
30 import io.swagger.v3.oas.annotations.responses.ApiResponses;
31 import io.swagger.v3.oas.annotations.tags.Tag;
32
33 import java.lang.invoke.MethodHandles;
34 import java.util.Vector;
35
36 import lombok.Getter;
37
38 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.ServiceCallbackInfo;
39 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.VoidResponse;
40 import org.slf4j.Logger;
41 import org.slf4j.LoggerFactory;
42 import org.springframework.http.HttpStatus;
43 import org.springframework.http.MediaType;
44 import org.springframework.http.ResponseEntity;
45 import org.springframework.web.bind.annotation.PostMapping;
46 import org.springframework.web.bind.annotation.RequestBody;
47 import org.springframework.web.bind.annotation.RestController;
48
49 @RestController("RappCallbacksController")
50 @Tag( //
51         name = Consts.V2_API_SERVICE_CALLBACKS_NAME, //
52         description = Consts.V2_API_SERVICE_CALLBACKS_DESCRIPTION //
53 )
54 public class RappSimulatorController {
55
56     private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
57     public static final String SERVICE_CALLBACK_URL = "/r-app/near-rt-ric-status";
58     private static Gson gson = new GsonBuilder().create();
59
60     public static class TestResults {
61         @Getter
62         private Vector<ServiceCallbackInfo> receivedInfo = new Vector<>();
63
64         public void clear() {
65             receivedInfo.clear();
66         }
67     }
68
69     @Getter
70     private TestResults testResults = new TestResults();
71
72     private static final String CALLBACK_DESCRIPTION = "The URL to this call is registerred at Service registration.";
73
74     @PostMapping(path = SERVICE_CALLBACK_URL, produces = MediaType.APPLICATION_JSON_VALUE)
75     @Operation(summary = "Callback for Near-RT RIC status", description = CALLBACK_DESCRIPTION)
76     @ApiResponses(value = { //
77             @ApiResponse(responseCode = "200", description = "OK",
78                     content = @Content(schema = @Schema(implementation = VoidResponse.class)))} //
79     )
80
81     public ResponseEntity<Object> serviceCallback( //
82             @RequestBody ServiceCallbackInfo body) {
83         logger.info("R-App callback body: {}", gson.toJson(body));
84         this.testResults.receivedInfo.add(body);
85         return new ResponseEntity<>(HttpStatus.OK);
86     }
87
88 }