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