2 * ========================LICENSE_START=================================
5 * Copyright (C) 2019 Nordix Foundation
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
21 package org.oransc.policyagent.controllers;
23 import com.google.gson.Gson;
24 import com.google.gson.GsonBuilder;
26 import io.swagger.annotations.Api;
27 import io.swagger.annotations.ApiOperation;
28 import io.swagger.annotations.ApiResponse;
29 import io.swagger.annotations.ApiResponses;
31 import java.util.ArrayList;
32 import java.util.List;
33 import java.util.Optional;
35 import org.oransc.policyagent.configuration.ApplicationConfig;
36 import org.oransc.policyagent.repository.Ric;
37 import org.oransc.policyagent.repository.Rics;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.http.HttpStatus;
40 import org.springframework.http.ResponseEntity;
41 import org.springframework.web.bind.annotation.GetMapping;
42 import org.springframework.web.bind.annotation.RequestParam;
43 import org.springframework.web.bind.annotation.RestController;
46 @Api(value = "RIC Management API")
47 public class RicRepositoryController {
52 private static Gson gson = new GsonBuilder() //
57 RicRepositoryController(ApplicationConfig appConfig) {
61 * Example: http://localhost:8081/rics?managedElementId=kista_1
64 @ApiOperation(value = "Returns the name of a RIC managing one Mananged Element")
67 @ApiResponse(code = 200, message = "RIC is fond", response = String.class), //
68 @ApiResponse(code = 404, message = "RIC is not fond", response = String.class) //
70 public ResponseEntity<String> getRic(
71 @RequestParam(name = "managedElementId", required = false, defaultValue = "") String managedElementId) {
73 Optional<Ric> ric = this.rics.lookupRicForManagedElement(managedElementId);
75 if (ric.isPresent()) {
76 return new ResponseEntity<>(ric.get().name(), HttpStatus.OK);
78 return new ResponseEntity<>("", HttpStatus.NOT_FOUND);
83 * @return a Json array of all RIC data
84 * Example: http://localhost:8081/ric
87 @ApiOperation(value = "Query NearRT RIC information")
90 @ApiResponse(code = 200, message = "OK", response = RicInfo.class, responseContainer = "List") //
92 public ResponseEntity<String> getRics(
93 @RequestParam(name = "policyType", required = false) String supportingPolicyType) {
95 List<RicInfo> result = new ArrayList<>();
97 for (Ric ric : rics.getRics()) {
98 if (supportingPolicyType == null || ric.isSupportingType(supportingPolicyType)) {
99 result.add(new RicInfo(ric.name(), ric.getManagedElementIds(), ric.getSupportedPolicyTypeNames()));
104 return new ResponseEntity<>(gson.toJson(result), HttpStatus.OK);