b42edb8fa0bdb2f84c8624bf5eb94496a44c7227
[ccsdk/oran.git] /
1 /*-
2  * ========================LICENSE_START=================================
3  * ONAP : ccsdk oran
4  * ======================================================================
5  * Copyright (C) 2020-2023 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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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===================================
19  */
20
21 package org.onap.ccsdk.oran.a1policymanagementservice.clients;
22
23 import java.time.Instant;
24 import java.util.Arrays;
25 import java.util.Vector;
26
27 import org.json.JSONObject;
28 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
29 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy;
30 import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyType;
31 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
32 import reactor.core.publisher.Mono;
33
34 public class A1ClientHelper {
35
36     private A1ClientHelper() {}
37
38     protected static Mono<String> createOutputJsonResponse(String key, String value) {
39         JSONObject paramsJson = new JSONObject();
40         paramsJson.put(key, value);
41         JSONObject responseJson = new JSONObject();
42         responseJson.put("output", paramsJson);
43         return Mono.just(responseJson.toString());
44     }
45
46     protected static Ric createRic(String url) {
47         RicConfig cfg = RicConfig.builder().ricId("ric") //
48                 .baseUrl(url) //
49                 .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) //
50                 .build();
51         return new Ric(cfg);
52     }
53
54     protected static Policy createPolicy(String nearRtRicUrl, String policyId, String json, String type) {
55         String callbackUrl = "https://test.com";
56         return Policy.builder() //
57                 .id(policyId) //
58                 .json(json) //
59                 .ownerServiceId("service") //
60                 .ric(createRic(nearRtRicUrl)) //
61                 .type(createPolicyType(type)) //
62                 .lastModified(Instant.now()) //
63                 .isTransient(false) //
64                 .statusNotificationUri(callbackUrl) //
65                 .build();
66     }
67
68     protected static PolicyType createPolicyType(String name) {
69         return PolicyType.builder().id(name).schema("schema").build();
70     }
71
72     protected static String getCreateSchema(String policyType, String policyTypeId) {
73         JSONObject obj = new JSONObject(policyType);
74         JSONObject schemaObj = obj.getJSONObject("create_schema");
75         schemaObj.put("title", policyTypeId);
76         return schemaObj.toString();
77     }
78 }