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;
28 import org.onap.so.adapters.nwrest.CreateNetworkRequest;
29 import org.onap.so.adapters.nwrest.CreateNetworkResponse;
30 import org.onap.so.adapters.nwrest.DeleteNetworkRequest;
31 import org.onap.so.adapters.nwrest.DeleteNetworkResponse;
32 import org.onap.so.adapters.nwrest.QueryNetworkResponse;
33 import org.onap.so.adapters.nwrest.RollbackNetworkRequest;
34 import org.onap.so.adapters.nwrest.RollbackNetworkResponse;
35 import org.onap.so.adapters.nwrest.UpdateNetworkRequest;
36 import org.onap.so.adapters.nwrest.UpdateNetworkResponse;
37 import org.onap.so.client.adapter.rest.AdapterRestClient;
38 import org.springframework.stereotype.Component;
41 public class NetworkAdapterClientImpl implements NetworkAdapterClient {
43 private final NetworkAdapterRestProperties props;
45 public NetworkAdapterClientImpl() {
46 this.props = new NetworkAdapterRestProperties();
50 public CreateNetworkResponse createNetwork(CreateNetworkRequest req) throws NetworkAdapterClientException{
52 return new AdapterRestClient(this.props, this.getUri("").build()).post(req,
53 CreateNetworkResponse.class);
54 } catch (InternalServerErrorException e) {
55 throw new NetworkAdapterClientException(e.getMessage());
60 public Response createNetworkAsync(CreateNetworkRequest req) throws NetworkAdapterClientException{
62 return new AdapterRestClient(this.props, this.getUri("").build()).post(req);
63 } catch (InternalServerErrorException e) {
64 throw new NetworkAdapterClientException(e.getMessage());
69 public DeleteNetworkResponse deleteNetwork(String aaiNetworkId, DeleteNetworkRequest req) throws NetworkAdapterClientException {
71 return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).delete(req,
72 DeleteNetworkResponse.class);
73 } catch (InternalServerErrorException e) {
74 throw new NetworkAdapterClientException(e.getMessage());
79 public Response deleteNetworkAsync(String aaiNetworkId, DeleteNetworkRequest req) 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) throws NetworkAdapterClientException {
90 return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).delete(req,
91 RollbackNetworkResponse.class);
92 } catch (InternalServerErrorException e) {
93 throw new NetworkAdapterClientException(e.getMessage());
98 public Response rollbackNetworkAsync(String aaiNetworkId, RollbackNetworkRequest req) throws NetworkAdapterClientException {
100 return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).delete(req);
101 } catch (InternalServerErrorException e) {
102 throw new NetworkAdapterClientException(e.getMessage());
107 public QueryNetworkResponse queryNetwork(String aaiNetworkId, String cloudSiteId, String tenantId,
108 String networkStackId, boolean skipAAI, String requestId, String serviceInstanceId) throws NetworkAdapterClientException {
109 UriBuilder builder = this.getUri("/" + aaiNetworkId);
110 if (cloudSiteId != null) {
111 builder.queryParam("cloudSiteId", cloudSiteId);
113 if (tenantId != null) {
114 builder.queryParam("tenantId", tenantId);
116 if (networkStackId != null) {
117 builder.queryParam("networkStackId", networkStackId);
120 builder.queryParam("skipAAI", skipAAI);
122 if (requestId != null) {
123 builder.queryParam("msoRequest.requestId", requestId);
125 if (serviceInstanceId != null) {
126 builder.queryParam("msoRequest.serviceInstanceId", serviceInstanceId);
129 return new AdapterRestClient(this.props, builder.build(), MediaType.APPLICATION_XML, MediaType.APPLICATION_XML)
130 .get(QueryNetworkResponse.class).get();
131 } catch (InternalServerErrorException e) {
132 throw new NetworkAdapterClientException(e.getMessage());
137 public UpdateNetworkResponse updateNetwork(String aaiNetworkId, UpdateNetworkRequest req) throws NetworkAdapterClientException {
139 return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).put(req,
140 UpdateNetworkResponse.class);
141 } catch (InternalServerErrorException e) {
142 throw new NetworkAdapterClientException(e.getMessage());
147 public Response updateNetworkAsync(String aaiNetworkId, UpdateNetworkRequest req) throws NetworkAdapterClientException{
149 return new AdapterRestClient(this.props, this.getUri("/" + aaiNetworkId).build()).put(req);
150 } catch (InternalServerErrorException e) {
151 throw new NetworkAdapterClientException(e.getMessage());
155 protected UriBuilder getUri(String path) {
156 return UriBuilder.fromPath(path);