2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.client.sdnc;
25 import java.util.LinkedHashMap;
26 import javax.ws.rs.core.UriBuilder;
27 import org.onap.so.client.BaseClient;
28 import org.onap.so.client.exception.BadResponseException;
29 import org.onap.so.client.exception.MapperException;
30 import org.onap.so.client.sdnc.beans.SDNCProperties;
31 import org.onap.so.client.sdnc.endpoint.SDNCTopology;
32 import org.springframework.beans.factory.annotation.Autowired;
33 import org.springframework.core.ParameterizedTypeReference;
34 import org.springframework.http.HttpHeaders;
35 import org.springframework.stereotype.Component;
38 public class SDNCClient {
41 private SDNCProperties properties;
43 private SdnCommonTasks sdnCommonTasks;
47 * @param request - takes in a generated object from sdnc client - creates a json request string and sends it to
48 * sdnc - receives and validates the linkedhashmap sent back from sdnc
49 * @throws MapperException
50 * @throws BadResponseException
52 public String post(Object request, SDNCTopology topology) throws MapperException, BadResponseException {
53 String jsonRequest = sdnCommonTasks.buildJsonRequest(request);
54 String targetUrl = properties.getHost() + properties.getPath() + ":" + topology.toString() + "/";
55 BaseClient<String, LinkedHashMap<String, Object>> STOClient = new BaseClient<>();
57 STOClient.setTargetUrl(targetUrl);
58 HttpHeaders httpHeader = sdnCommonTasks.getHttpHeaders(properties.getAuth(), true);
59 STOClient.setHttpHeader(httpHeader);
60 LinkedHashMap<String, Object> output =
61 STOClient.post(jsonRequest, new ParameterizedTypeReference<LinkedHashMap<String, Object>>() {});
62 return sdnCommonTasks.validateSDNResponse(output);
66 public String post(Object request, String url) throws MapperException, BadResponseException {
67 String jsonRequest = sdnCommonTasks.buildJsonRequest(request);
68 BaseClient<String, LinkedHashMap<String, Object>> STOClient = new BaseClient<>();
69 STOClient.setTargetUrl(url);
70 HttpHeaders httpHeader = sdnCommonTasks.getHttpHeaders(properties.getAuth(), true);
71 STOClient.setHttpHeader(httpHeader);
72 LinkedHashMap<String, Object> output =
73 STOClient.post(jsonRequest, new ParameterizedTypeReference<LinkedHashMap<String, Object>>() {});
74 return sdnCommonTasks.validateSDNResponse(output);
79 * @param queryLink - takes in a link to topology that needs to be queried - creates a json request string and sends
80 * it to sdnc - receives and validates the linkedhashmap sent back from sdnc *
81 * @throws MapperException
82 * @throws BadResponseException
84 public String get(String queryLink) throws MapperException, BadResponseException {
86 String jsonRequest = sdnCommonTasks.buildJsonRequest(request);
87 String targetUrl = UriBuilder.fromUri(properties.getHost()).path(queryLink).build().toString();
88 BaseClient<String, LinkedHashMap<String, Object>> STOClient = new BaseClient<>();
89 STOClient.setTargetUrl(targetUrl);
90 HttpHeaders httpHeader = sdnCommonTasks.getHttpHeaders(properties.getAuth(), false);
91 STOClient.setHttpHeader(httpHeader);
92 LinkedHashMap<String, Object> output =
93 STOClient.get(jsonRequest, new ParameterizedTypeReference<LinkedHashMap<String, Object>>() {});
94 return sdnCommonTasks.validateSDNGetResponse(output);