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 com.google.gson.FieldNamingPolicy;
24 import com.google.gson.Gson;
25 import com.google.gson.GsonBuilder;
27 import java.util.Arrays;
28 import java.util.Vector;
30 import org.json.JSONObject;
31 import org.oransc.policyagent.configuration.ImmutableRicConfig;
32 import org.oransc.policyagent.configuration.RicConfig;
33 import org.oransc.policyagent.repository.ImmutablePolicy;
34 import org.oransc.policyagent.repository.ImmutablePolicyType;
35 import org.oransc.policyagent.repository.Policy;
36 import org.oransc.policyagent.repository.PolicyType;
37 import org.oransc.policyagent.repository.Ric;
38 import reactor.core.publisher.Mono;
40 public class A1ClientHelper {
41 private static Gson gson = new GsonBuilder() //
42 .setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_DASHES) //
45 private A1ClientHelper() {
48 protected static String createInputJsonString(SdncOscAdapterInput inputParams) {
49 JSONObject inputJson = new JSONObject();
50 inputJson.put("input", new JSONObject(gson.toJson(inputParams)));
51 return inputJson.toString();
54 protected static Mono<String> createOutputJsonResponse(String key, String value) {
55 JSONObject paramsJson = new JSONObject();
56 paramsJson.put(key, value);
57 JSONObject responseJson = new JSONObject();
58 responseJson.put("output", paramsJson);
59 return Mono.just(responseJson.toString());
62 protected static Ric createRic(String url) {
63 RicConfig cfg = ImmutableRicConfig.builder().name("ric") //
65 .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) //
70 protected static Policy createPolicy(String nearRtRicUrl, String policyId, String json, String type) {
71 return ImmutablePolicy.builder() //
74 .ownerServiceName("service") //
75 .ric(createRic(nearRtRicUrl)) //
76 .type(createPolicyType(type)) //
77 .lastModified("now") //
81 protected static PolicyType createPolicyType(String name) {
82 return ImmutablePolicyType.builder().name(name).schema("schema").build();