2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. 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
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.onap.so.client.adapter.network;
23 import javax.ws.rs.InternalServerErrorException;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.Response;
26 import javax.ws.rs.core.UriBuilder;
27 import org.onap.so.adapters.nwrest.CreateNetworkRequest;
28 import org.onap.so.adapters.nwrest.CreateNetworkResponse;
29 import org.onap.so.adapters.nwrest.DeleteNetworkRequest;
30 import org.onap.so.adapters.nwrest.DeleteNetworkResponse;
31 import org.onap.so.adapters.nwrest.QueryNetworkResponse;
32 import org.onap.so.adapters.nwrest.RollbackNetworkRequest;
33 import org.onap.so.adapters.nwrest.RollbackNetworkResponse;
34 import org.onap.so.adapters.nwrest.UpdateNetworkRequest;
35 import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
36 import org.onap.so.client.adapter.rest.AdapterRestClient;
37 import org.springframework.stereotype.Component;
40 public class NetworkAdapterClientImpl implements NetworkAdapterClient {
42 private final NetworkAdapterRestProperties props;
44 public NetworkAdapterClientImpl() {
45 this.props = new NetworkAdapterRestProperties();
49 public CreateNetworkResponse createNetwork(CreateNetworkRequest req) throws NetworkAdapterClientException {
51 return new AdapterRestClient(this.props, this.getUri("").build()).post(req, CreateNetworkResponse.class);
52 } catch (InternalServerErrorException e) {
53 throw new NetworkAdapterClientException(e.getMessage());
58 public Response createNetworkAsync(CreateNetworkRequest req) throws NetworkAdapterClientException {
60 return new AdapterRestClient(this.props, this.getUri("").build()).post(req);
61 } catch (InternalServerErrorException e) {
62 throw new NetworkAdapterClientException(e.getMessage());
67 public DeleteNetworkResponse deleteNetwork(String aaiNetworkId, DeleteNetworkRequest req)
68 throws NetworkAdapterClientException {
70 return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).delete(req,
71 DeleteNetworkResponse.class);
72 } catch (InternalServerErrorException e) {
73 throw new NetworkAdapterClientException(e.getMessage());
78 public Response deleteNetworkAsync(String aaiNetworkId, DeleteNetworkRequest req)
79 throws NetworkAdapterClientException {
81 return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).delete(req);
82 } catch (InternalServerErrorException e) {
83 throw new NetworkAdapterClientException(e.getMessage());
88 public RollbackNetworkResponse rollbackNetwork(String aaiNetworkId, RollbackNetworkRequest req)
89 throws NetworkAdapterClientException {
91 return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).delete(req,
92 RollbackNetworkResponse.class);
93 } catch (InternalServerErrorException e) {
94 throw new NetworkAdapterClientException(e.getMessage());
99 public Response rollbackNetworkAsync(String aaiNetworkId, RollbackNetworkRequest req)
100 throws NetworkAdapterClientException {
102 return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).delete(req);
103 } catch (InternalServerErrorException e) {
104 throw new NetworkAdapterClientException(e.getMessage());
109 public QueryNetworkResponse queryNetwork(String aaiNetworkId, String cloudSiteId, String tenantId,
110 String networkStackId, boolean skipAAI, String requestId, String serviceInstanceId)
111 throws NetworkAdapterClientException {
112 UriBuilder builder = this.getUri("/" + aaiNetworkId);
113 if (cloudSiteId != null) {
114 builder.queryParam("cloudSiteId", cloudSiteId);
116 if (tenantId != null) {
117 builder.queryParam("tenantId", tenantId);
119 if (networkStackId != null) {
120 builder.queryParam("networkStackId", networkStackId);
123 builder.queryParam("skipAAI", skipAAI);
125 if (requestId != null) {
126 builder.queryParam("msoRequest.requestId", requestId);
128 if (serviceInstanceId != null) {
129 builder.queryParam("msoRequest.serviceInstanceId", serviceInstanceId);
132 return new AdapterRestClient(this.props, builder.build(), MediaType.APPLICATION_XML,
133 MediaType.APPLICATION_XML).get(QueryNetworkResponse.class).get();
134 } catch (InternalServerErrorException e) {
135 throw new NetworkAdapterClientException(e.getMessage());
140 public UpdateNetworkResponse updateNetwork(String aaiNetworkId, UpdateNetworkRequest req)
141 throws NetworkAdapterClientException {
143 return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).put(req,
144 UpdateNetworkResponse.class);
145 } catch (InternalServerErrorException e) {
146 throw new NetworkAdapterClientException(e.getMessage());
151 public Response updateNetworkAsync(String aaiNetworkId, UpdateNetworkRequest req)
152 throws NetworkAdapterClientException {
154 return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).put(req);
155 } catch (InternalServerErrorException e) {
156 throw new NetworkAdapterClientException(e.getMessage());
160 protected UriBuilder getUri(String path) {
161 return UriBuilder.fromPath(path);