0a679201abae0359310a6c2ba47512131217b20a
[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.annotations.Api;
27 import io.swagger.annotations.ApiOperation;
28 import io.swagger.annotations.ApiResponse;
29 import io.swagger.annotations.ApiResponses;
30
31 import java.lang.invoke.MethodHandles;
32 import java.util.Vector;
33
34 import lombok.Getter;
35
36 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.ServiceCallbackInfo;
37 import org.onap.ccsdk.oran.a1policymanagementservice.controllers.VoidResponse;
38 import org.slf4j.Logger;
39 import org.slf4j.LoggerFactory;
40 import org.springframework.http.HttpStatus;
41 import org.springframework.http.MediaType;
42 import org.springframework.http.ResponseEntity;
43 import org.springframework.web.bind.annotation.PostMapping;
44 import org.springframework.web.bind.annotation.RequestBody;
45 import org.springframework.web.bind.annotation.RestController;
46
47 @RestController("RappCallbacksController")
48 @Api(tags = {"R-App Callbacks"})
49 public class RappSimulatorController {
50
51     private final Logger logger = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
52     public static final String SERVICE_CALLBACK_URL = "/r-app/pms-callback";
53     private static Gson gson = new GsonBuilder().create();
54
55     public static class TestResults {
56         @Getter
57         private Vector<ServiceCallbackInfo> receivedInfo = new Vector<>();
58
59         public void clear() {
60             receivedInfo.clear();
61         }
62     }
63
64     @Getter
65     private TestResults testResults = new TestResults();
66
67     private static final String CALLBACK_DESCRIPTION = "The URL to this call is registerred at Service registration.";
68
69     @PostMapping(path = SERVICE_CALLBACK_URL, produces = MediaType.APPLICATION_JSON_VALUE)
70     @ApiOperation(value = "Callback for Near-RT RIC status", notes = CALLBACK_DESCRIPTION)
71     @ApiResponses(value = { //
72             @ApiResponse(code = 200, message = "OK", response = VoidResponse.class)} //
73     )
74     public ResponseEntity<Object> jobStatusCallback( //
75             @RequestBody ServiceCallbackInfo body) {
76         logger.info("R-App callback body: {}", gson.toJson(body));
77         this.testResults.receivedInfo.add(body);
78         return new ResponseEntity<>(HttpStatus.OK);
79     }
80
81 }