2 * ========================LICENSE_START=================================
5 * Copyright (C) 2020 Nordix Foundation
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.oransc.policyagent.clients;
23 import java.util.Arrays;
24 import java.util.Vector;
26 import org.json.JSONObject;
27 import org.oransc.policyagent.configuration.ImmutableRicConfig;
28 import org.oransc.policyagent.configuration.RicConfig;
29 import org.oransc.policyagent.repository.ImmutablePolicy;
30 import org.oransc.policyagent.repository.ImmutablePolicyType;
31 import org.oransc.policyagent.repository.Policy;
32 import org.oransc.policyagent.repository.PolicyType;
33 import org.oransc.policyagent.repository.Ric;
34 import reactor.core.publisher.Mono;
36 public class A1ClientHelper {
38 private A1ClientHelper() {
41 protected static Mono<String> createOutputJsonResponse(String key, String value) {
42 JSONObject paramsJson = new JSONObject();
43 paramsJson.put(key, value);
44 JSONObject responseJson = new JSONObject();
45 responseJson.put("output", paramsJson);
46 return Mono.just(responseJson.toString());
49 protected static Ric createRic(String url) {
50 RicConfig cfg = ImmutableRicConfig.builder().name("ric") //
52 .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) //
53 .controllerName("") //
58 protected static Policy createPolicy(String nearRtRicUrl, String policyId, String json, String type) {
59 return ImmutablePolicy.builder() //
62 .ownerServiceName("service") //
63 .ric(createRic(nearRtRicUrl)) //
64 .type(createPolicyType(type)) //
65 .lastModified("now") //
69 protected static PolicyType createPolicyType(String name) {
70 return ImmutablePolicyType.builder().name(name).schema("schema").build();
73 protected static String getCreateSchema(String policyType, String policyTypeId) {
74 JSONObject obj = new JSONObject(policyType);
75 JSONObject schemaObj = obj.getJSONObject("create_schema");
76 schemaObj.put("title", policyTypeId);
77 return schemaObj.toString();