2 * ========================LICENSE_START=================================
4 * ======================================================================
5 * Copyright (C) 2019-2020 Nordix Foundation. All rights reserved.
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
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.onap.ccsdk.oran.a1policymanagementservice.controllers.v1;
23 import com.google.gson.Gson;
24 import com.google.gson.GsonBuilder;
26 import io.swagger.v3.oas.annotations.Operation;
27 import io.swagger.v3.oas.annotations.Parameter;
28 import io.swagger.v3.oas.annotations.media.ArraySchema;
29 import io.swagger.v3.oas.annotations.media.Content;
30 import io.swagger.v3.oas.annotations.media.Schema;
31 import io.swagger.v3.oas.annotations.responses.ApiResponse;
32 import io.swagger.v3.oas.annotations.responses.ApiResponses;
33 import io.swagger.v3.oas.annotations.tags.Tag;
35 import java.util.ArrayList;
36 import java.util.List;
38 import org.onap.ccsdk.oran.a1policymanagementservice.exceptions.EntityNotFoundException;
39 import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyTypes;
40 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
41 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Rics;
42 import org.springframework.beans.factory.annotation.Autowired;
43 import org.springframework.http.HttpStatus;
44 import org.springframework.http.ResponseEntity;
45 import org.springframework.web.bind.annotation.GetMapping;
46 import org.springframework.web.bind.annotation.RequestParam;
47 import org.springframework.web.bind.annotation.RestController;
50 @Tag(name = Consts.V1_API_NAME)
51 public class RicRepositoryController {
59 private static Gson gson = new GsonBuilder() //
63 * Example: http://localhost:8081/rics?managedElementId=kista_1
65 * @throws EntityNotFoundException
68 @Operation(summary = "Returns the name of a RIC managing one Mananged Element")
69 @ApiResponses(value = { //
70 @ApiResponse(responseCode = "200", //
71 description = "Near-RT RIC is found", //
72 content = @Content(schema = @Schema(implementation = String.class))), //
73 @ApiResponse(responseCode = "404", //
74 description = "Near-RT RIC is not found", //
75 content = @Content(schema = @Schema(implementation = String.class))) //
78 public ResponseEntity<String> getRic( //
79 @Parameter(name = "managedElementId", required = true, description = "The identity of the Managed Element") //
80 @RequestParam(name = "managedElementId", required = true) String managedElementId)
81 throws EntityNotFoundException {
82 Ric ric = this.rics.lookupRicForManagedElement(managedElementId);
83 return new ResponseEntity<>(ric.id(), HttpStatus.OK);
87 * @return a Json array of all RIC data Example: http://localhost:8081/ric
90 @Operation(summary = "Query Near-RT RIC information")
91 @ApiResponses(value = { //
92 @ApiResponse(responseCode = "200", //
93 description = "OK", //
94 content = @Content(array = @ArraySchema(schema = @Schema(implementation = RicInfo.class)))), //
95 @ApiResponse(responseCode = "404", //
96 description = "Policy type is not found", //
97 content = @Content(schema = @Schema(implementation = String.class))) //
99 public ResponseEntity<String> getRics( //
100 @Parameter(name = "policyType", required = false, description = "The name of the policy type") //
101 @RequestParam(name = "policyType", required = false) String supportingPolicyType) {
102 if ((supportingPolicyType != null) && (this.types.get(supportingPolicyType) == null)) {
103 return new ResponseEntity<>("Policy type not found", HttpStatus.NOT_FOUND);
106 List<RicInfo> result = new ArrayList<>();
107 for (Ric ric : rics.getRics()) {
108 if (supportingPolicyType == null || ric.isSupportingType(supportingPolicyType)) {
109 result.add(new RicInfo(ric.id(), ric.getManagedElementIds(), ric.getSupportedPolicyTypeNames(),
110 ric.getState().toString()));
114 return new ResponseEntity<>(gson.toJson(result), HttpStatus.OK);