eb00713851cd163693e768ae267bc5e493369d0a
[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.Policy;
31 import org.onap.ccsdk.oran.a1policymanagementservice.repository.PolicyType;
32 import org.onap.ccsdk.oran.a1policymanagementservice.repository.Ric;
33 import reactor.core.publisher.Mono;
34
35 public class A1ClientHelper {
36
37     private A1ClientHelper() {}
38
39     protected static Mono<String> createOutputJsonResponse(String key, String value) {
40         JSONObject paramsJson = new JSONObject();
41         paramsJson.put(key, value);
42         JSONObject responseJson = new JSONObject();
43         responseJson.put("output", paramsJson);
44         return Mono.just(responseJson.toString());
45     }
46
47     protected static Ric createRic(String url) {
48         RicConfig cfg = ImmutableRicConfig.builder().ricId("ric") //
49                 .baseUrl(url) //
50                 .managedElementIds(new Vector<String>(Arrays.asList("kista_1", "kista_2"))) //
51                 .controllerName("") //
52                 .build();
53         return new Ric(cfg);
54     }
55
56     protected static Policy createPolicy(String nearRtRicUrl, String policyId, String json, String type) {
57         String callbackUrl = "https://test.com";
58         return Policy.builder() //
59                 .id(policyId) //
60                 .json(json) //
61                 .ownerServiceId("service") //
62                 .ric(createRic(nearRtRicUrl)) //
63                 .type(createPolicyType(type)) //
64                 .lastModified(Instant.now()) //
65                 .isTransient(false) //
66                 .statusNotificationUri(callbackUrl) //
67                 .build();
68     }
69
70     protected static PolicyType createPolicyType(String name) {
71         return PolicyType.builder().id(name).schema("schema").build();
72     }
73
74     protected static String getCreateSchema(String policyType, String policyTypeId) {
75         JSONObject obj = new JSONObject(policyType);
76         JSONObject schemaObj = obj.getJSONObject("create_schema");
77         schemaObj.put("title", policyTypeId);
78         return schemaObj.toString();
79     }
80 }