2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2019 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.sdnc.northbound.restadpter;
23 import org.springframework.web.util.UriComponentsBuilder;
26 * This class provides Near-RIC api to invoke the A1 interface
28 * @author lathishbabu.ganesan@est.tech
32 public class NearRicUrlProvider {
34 private String baseUrl;
36 public NearRicUrlProvider() {
37 // Near ric ip:port is passed in payload currently
41 * Retrieve the base url of the Near-RIC
43 * @return the base url
45 public String getBaseUrl(final String nearRtRicId) {
46 baseUrl = "http://" + nearRtRicId + "/a1-p/";
47 return UriComponentsBuilder.fromUriString(baseUrl).build().toString();
51 * Retrieve the url of A1 healthcheck
53 * @return the health check url
55 public String getHealthCheck(final String nearRtRicId) {
56 return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicId)).pathSegment("healthcheck").build()
61 * Retrieve the policy type url
63 * @return the base url with the policytypes
65 public String getPolicyTypes(final String nearRtRicId) {
66 return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicId)).pathSegment("policytypes/").build()
71 * Retrieve the url of policy type id
73 * @param policyTypeId Policy Type Id
74 * @return the policy type id url
76 public String getPolicyTypeId(final String nearRtRicId, final String policyTypeId) {
77 return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicId)).pathSegment("policytypes")
78 .pathSegment(policyTypeId).build().toString();
82 * Retrieve the url of the policy instances
84 * @param policyTypeId Policy Type Id
85 * @return the policy instances for the given policy type
87 public String getPolicyInstances(final String nearRtRicId, final String policyTypeId) {
88 return UriComponentsBuilder.fromUriString(getPolicyTypeId(nearRtRicId, policyTypeId)).pathSegment("policies")
93 * Retrieve the url of the policy instance id
95 * @param policyTypeId Policy Type Id
96 * @param policyInstanceId Policy Instance Id
97 * @return the policy instance id for the given policy type
99 public String getPolicyInstanceId(final String nearRtRicId, final String policyTypeId, final String policyInstanceId) {
100 return UriComponentsBuilder.fromUriString(getPolicyTypeId(nearRtRicId, policyTypeId)).pathSegment("policies")
101 .pathSegment(policyInstanceId).build().toString();
105 * Retrieve the url of the policy instance id status
107 * @param policyTypeId Policy Type Id
108 * @param policyInstanceId Policy Instance Id
109 * @return the policy instance id status for the given policy type
111 public String getPolicyInstanceIdStatus(final String nearRtRicId, final String policyTypeId,
112 final String policyInstanceId) {
113 return UriComponentsBuilder.fromUriString(getPolicyInstanceId(nearRtRicId, policyTypeId, policyInstanceId))
114 .pathSegment("status").build().toString();