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===================================
20 package org.oransc.policyagent.controllers;
22 import com.google.gson.Gson;
23 import com.google.gson.GsonBuilder;
25 import io.swagger.annotations.ApiOperation;
26 import io.swagger.annotations.ApiResponse;
27 import io.swagger.annotations.ApiResponses;
29 import java.util.Optional;
30 import java.util.Vector;
32 import org.oransc.policyagent.configuration.ApplicationConfig;
33 import org.oransc.policyagent.configuration.RicConfig;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.http.HttpStatus;
36 import org.springframework.http.ResponseEntity;
37 import org.springframework.web.bind.annotation.GetMapping;
38 import org.springframework.web.bind.annotation.RequestParam;
39 import org.springframework.web.bind.annotation.RestController;
42 public class RicRepositoryController {
44 private final ApplicationConfig appConfig;
45 private static Gson gson = new GsonBuilder() //
50 RicRepositoryController(ApplicationConfig config) {
51 this.appConfig = config;
55 * Example: http://localhost:8080/rics?managedElementId=kista_1
58 @ApiOperation(value = "Returns the name of a RIC managing one Mananged Element")
61 @ApiResponse(code = 200, message = "RIC is fond"), //
62 @ApiResponse(code = 404, message = "RIC is not fond") //
64 public ResponseEntity<String> getRic(
65 @RequestParam(name = "managedElementId", required = false, defaultValue = "") String managedElementId) {
67 Optional<RicConfig> config = appConfig.lookupRicConfigForManagedElement(managedElementId);
69 if (config.isPresent()) {
70 return new ResponseEntity<>(config.get().name(), HttpStatus.OK);
72 return new ResponseEntity<>("", HttpStatus.NOT_FOUND);
77 * @return a Json array of all RIC data
78 * Example: http://localhost:8080/ric
81 @ApiOperation(value = "Returns defined NearRT RIC:s as Json")
84 @ApiResponse(code = 200, message = "OK") //
86 public ResponseEntity<String> getRics() {
87 Vector<RicInfo> result = new Vector<RicInfo>();
88 for (RicConfig ricConfig : this.appConfig.getRicConfigs()) {
89 RicInfo ric = ImmutableRicInfo.builder() //
90 .managedElementIds(ricConfig.managedElementIds()) //
91 .name(ricConfig.name()) //
95 return new ResponseEntity<>(gson.toJson(result), HttpStatus.OK);