100e95e23749d0e4fb0604931086c7e139a12031
[ccsdk/oran.git] /
1 /*-
2  * ========================LICENSE_START=================================
3  * ONAP : ccsdk oran
4  * ======================================================================
5  * Copyright (C) 2020 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.ImmutableRicConfig;
29 import org.onap.ccsdk.oran.a1policymanagementservice.configuration.RicConfig;
30 import org.onap.ccsdk.oran.a1policymanagementservice.repository.ImmutablePolicy;
31 import org.onap.ccsdk.oran.a1policymanagementservice.repository.ImmutablePolicyType;
32 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Policy;
33 import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyType;
34 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
35 import reactor.core.publisher.Mono;
36
37 public class A1ClientHelper {
38
39     private A1ClientHelper() {}
40
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());
47     }
48
49     protected static Ric createRic(String url) {
50         RicConfig cfg = ImmutableRicConfig.builder().ricId("ric") //
51                 .baseUrl(url) //
52                 .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) //
53                 .controllerName("") //
54                 .build();
55         return new Ric(cfg);
56     }
57
58     protected static Policy createPolicy(String nearRtRicUrl, String policyId, String json, String type) {
59         String callbackUrl = "https://test.com";
60         return ImmutablePolicy.builder() //
61                 .id(policyId) //
62                 .json(json) //
63                 .ownerServiceId("service") //
64                 .ric(createRic(nearRtRicUrl)) //
65                 .type(createPolicyType(type)) //
66                 .lastModified(Instant.now()) //
67                 .isTransient(false) //
68                 .statusNotificationUri(callbackUrl) //
69                 .build();
70     }
71
72     protected static PolicyType createPolicyType(String name) {
73         return ImmutablePolicyType.builder().id(name).schema("schema").build();
74     }
75
76     protected static String getCreateSchema(String policyType, String policyTypeId) {
77         JSONObject obj = new JSONObject(policyType);
78         JSONObject schemaObj = obj.getJSONObject("create_schema");
79         schemaObj.put("title", policyTypeId);
80         return schemaObj.toString();
81     }
82 }