NonRT-RIC A1 Northbound API
[nonrtric.git] / sdnc-a1-controller / northbound / nonrt-ric-api / provider / src / main / java / org / onap / sdnc / northbound / restadpter / NearRicUrlProvider.java
1 /*-
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
8  *
9  *      http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  * SPDX-License-Identifier: Apache-2.0
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.sdnc.northbound.restadpter;
22
23 import org.springframework.web.util.UriComponentsBuilder;
24
25 /**
26  * This class provides Near-RIC api to invoke the A1 interface
27  * 
28  * @author lathishbabu.ganesan@est.tech
29  *
30  */
31
32 public class NearRicUrlProvider {
33
34   private String baseUrl;
35
36   public NearRicUrlProvider() {
37     // Near ric ip is passed in payload
38     baseUrl = "http://localhost:8080/a1-p/";
39   }
40
41   /**
42    * Retrieve the base url of the Near-RIC
43    * 
44    * @return the base url
45    */
46   public String getBaseUrl() {
47     return UriComponentsBuilder.fromUriString(baseUrl).build().toString();
48   }
49
50   /**
51    * Retrieve the url of A1 healthcheck
52    * 
53    * @return the health check url
54    */
55   public String getHealthCheck() {
56     return UriComponentsBuilder.fromUriString(getBaseUrl()).pathSegment("healthcheck").build()
57         .toString();
58   }
59
60   /**
61    * Retrieve the policy type url
62    * 
63    * @return the base url with the policytypes
64    */
65   public String getPolicyTypes() {
66     return UriComponentsBuilder.fromUriString(getBaseUrl()).pathSegment("policytypes").build()
67         .toString();
68   }
69
70   /**
71    * Retrieve the url of policy type id
72    * 
73    * @param policyTypeId Policy Type Id
74    * @return the policy type id url
75    */
76   public String getPolicyTypeId(final String policyTypeId) {
77     return UriComponentsBuilder.fromUriString(getBaseUrl()).pathSegment("policytypes")
78         .pathSegment(policyTypeId).build().toString();
79   }
80
81   /**
82    * Retrieve the url of the policy instances
83    * 
84    * @param policyTypeId Policy Type Id
85    * @return the policy instances for the given policy type
86    */
87   public String getPolicyInstances(final String policyTypeId) {
88     return UriComponentsBuilder.fromUriString(getPolicyTypeId(policyTypeId)).pathSegment("policies")
89         .build().toString();
90   }
91
92   /**
93    * Retrieve the url of the policy instance id
94    * 
95    * @param policyTypeId Policy Type Id
96    * @param policyInstanceId Policy Instance Id
97    * @return the policy instance id for the given policy type
98    */
99   public String getPolicyInstanceId(final String policyTypeId, final String policyInstanceId) {
100     return UriComponentsBuilder.fromUriString(getPolicyTypeId(policyTypeId)).pathSegment("policies")
101         .pathSegment(policyInstanceId).build().toString();
102   }
103
104   /**
105    * Retrieve the url of the policy instance id status
106    * 
107    * @param policyTypeId Policy Type Id
108    * @param policyInstanceId Policy Instance Id
109    * @return the policy instance id status for the given policy type
110    */
111   public String getPolicyInstanceIdStatus(final String policyTypeId,
112       final String policyInstanceId) {
113     return UriComponentsBuilder.fromUriString(getPolicyInstanceId(policyTypeId, policyInstanceId))
114         .pathSegment("status").build().toString();
115   }
116 }