2 * ========================LICENSE_START=================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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===================================
21 package org.onap.ccsdk.oran.a1policymanagementservice.clients;
23 import java.time.Instant;
24 import java.util.Arrays;
25 import java.util.Vector;
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;
34 public class A1ClientHelper {
36 private A1ClientHelper() {}
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());
46 protected static Ric createRic(String url) {
47 RicConfig cfg = RicConfig.builder().ricId("ric") //
49 .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) //
54 protected static Policy createPolicy(String nearRtRicUrl, String policyId, String json, String type) {
55 String callbackUrl = "https://test.com";
56 return Policy.builder() //
59 .ownerServiceId("service") //
60 .ric(createRic(nearRtRicUrl)) //
61 .type(createPolicyType(type)) //
62 .lastModified(Instant.now()) //
63 .isTransient(false) //
64 .statusNotificationUri(callbackUrl) //
68 protected static PolicyType createPolicyType(String name) {
69 return PolicyType.builder().id(name).schema("schema").build();
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();