Adapt A1 controller to latest A1 spec
[nonrtric.git] / sdnc-a1-controller / northbound / nonrt-ric-api / provider / src / main / java / org / onap / sdnc / northbound / restadapter / 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.restadapter;
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   public NearRicUrlProvider() {
35   }
36
37   /**
38    * Retrieve the base url of the Near-RIC
39    *
40    * @param nearRtRicUrl the near-rt-ric url
41    * @return the base url
42    */
43   public String getBaseUrl(final String nearRtRicUrl) {
44     String baseUrl = nearRtRicUrl + "/A1-P/v1";
45     return UriComponentsBuilder.fromUriString(baseUrl).build().toString();
46   }
47
48   /**
49    * Retrieve the policytypes url
50    *
51    * @param nearRtRicUrl the near-rt-ric url
52    * @return the policytypes url
53    */
54   public String policyTypesUrl(final String nearRtRicUrl) {
55     return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicUrl)).pathSegment("policytypes")
56             .build().toString();
57   }
58
59   /**
60    * Retrieve the policies url
61    *
62    * @param nearRtRicUrl the near-rt-ric url
63    * @return the policies url
64    */
65   public String policiesUrl(final String nearRtRicUrl) {
66     return UriComponentsBuilder.fromUriString(getBaseUrl(nearRtRicUrl)).pathSegment("policies")
67             .build().toString();
68   }
69
70   /**
71    * Retrieve the url of policy type
72    *
73    * @param nearRtRicUrl the near-rt-ric url
74    * @param policyTypeId Policy Type Id
75    * @return the policy type url
76    */
77   public String getPolicyTypeUrl(final String nearRtRicUrl, final String policyTypeId) {
78     return UriComponentsBuilder.fromUriString(policyTypesUrl(nearRtRicUrl)).pathSegment(policyTypeId)
79         .build().toString();
80   }
81
82   /**
83    * Retrieve the url of putPolicy
84    *
85    * @param nearRtRicUrl the near-rt-ric url
86    * @param policyId Policy Id
87    * @param policyTypeId Policy Type Id
88    * @return the putPolicy url
89    */
90   public String putPolicyUrl(final String nearRtRicUrl, final String policyId, final String policyTypeId) {
91     return UriComponentsBuilder.fromUriString(policiesUrl(nearRtRicUrl)).pathSegment(policyId)
92             .pathSegment("?policyTypeId=").pathSegment(policyTypeId).build().toString();
93   }
94
95   /**
96    * Retrieve the url of deletePolicy
97    *
98    * @param nearRtRicUrl the near-rt-ric url
99    * @param policyId Policy Id
100    * @return the deletePolicy url
101    */
102   public String deletePolicyUrl(final String nearRtRicUrl, final String policyId) {
103     return UriComponentsBuilder.fromUriString(policiesUrl(nearRtRicUrl)).pathSegment(policyId)
104             .build().toString();
105   }
106 }