Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / adapter / vnf / VnfAdapterClientImpl.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
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.so.client.adapter.vnf;
22
23 import javax.ws.rs.InternalServerErrorException;
24 import javax.ws.rs.core.MediaType;
25 import javax.ws.rs.core.UriBuilder;
26 import org.onap.so.adapters.vnfrest.CreateVfModuleRequest;
27 import org.onap.so.adapters.vnfrest.CreateVfModuleResponse;
28 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
29 import org.onap.so.adapters.vnfrest.DeleteVfModuleResponse;
30 import org.onap.so.adapters.vnfrest.QueryVfModuleResponse;
31 import org.onap.so.adapters.vnfrest.RollbackVfModuleRequest;
32 import org.onap.so.adapters.vnfrest.RollbackVfModuleResponse;
33 import org.onap.so.adapters.vnfrest.UpdateVfModuleRequest;
34 import org.onap.so.adapters.vnfrest.UpdateVfModuleResponse;
35 import org.onap.so.client.adapter.rest.AdapterRestClient;
36 import org.springframework.stereotype.Component;
37
38 @Component
39 public class VnfAdapterClientImpl implements VnfAdapterClient {
40
41     private static final String VF_MODULES = "/vf-modules/";
42
43     private VnfAdapterRestProperties props;
44
45     public VnfAdapterClientImpl() {
46         this.props = new VnfAdapterRestProperties();
47     }
48
49     public VnfAdapterClientImpl(VnfAdapterRestProperties props) {
50         this.props = props;
51     }
52
53     @Override
54     public CreateVfModuleResponse createVfModule(String aaiVnfId, CreateVfModuleRequest req)
55             throws VnfAdapterClientException {
56         try {
57             return new AdapterRestClient(this.props, this.getUri("/" + aaiVnfId + "/vf-modules").build()).post(req,
58                     CreateVfModuleResponse.class);
59         } catch (InternalServerErrorException e) {
60             throw new VnfAdapterClientException(e.getMessage());
61         }
62     }
63
64     @Override
65     public RollbackVfModuleResponse rollbackVfModule(String aaiVnfId, String aaiVfModuleId, RollbackVfModuleRequest req)
66             throws VnfAdapterClientException {
67         try {
68             return new AdapterRestClient(this.props,
69                     this.getUri("/" + aaiVnfId + VF_MODULES + aaiVfModuleId + "/rollback").build()).delete(req,
70                             RollbackVfModuleResponse.class);
71         } catch (InternalServerErrorException e) {
72             throw new VnfAdapterClientException(e.getMessage());
73         }
74     }
75
76     @Override
77     public DeleteVfModuleResponse deleteVfModule(String aaiVnfId, String aaiVfModuleId, DeleteVfModuleRequest req)
78             throws VnfAdapterClientException {
79         try {
80             return new AdapterRestClient(this.props, this.getUri("/" + aaiVnfId + VF_MODULES + aaiVfModuleId).build())
81                     .delete(req, DeleteVfModuleResponse.class);
82         } catch (InternalServerErrorException e) {
83             throw new VnfAdapterClientException(e.getMessage());
84         }
85     }
86
87     @Override
88     public UpdateVfModuleResponse updateVfModule(String aaiVnfId, String aaiVfModuleId, UpdateVfModuleRequest req)
89             throws VnfAdapterClientException {
90         try {
91             return new AdapterRestClient(this.props, this.getUri("/" + aaiVnfId + VF_MODULES + aaiVfModuleId).build())
92                     .put(req, UpdateVfModuleResponse.class);
93         } catch (InternalServerErrorException e) {
94             throw new VnfAdapterClientException(e.getMessage());
95         }
96     }
97
98     @Override
99     public QueryVfModuleResponse queryVfModule(String aaiVnfId, String aaiVfModuleId, String cloudSiteId,
100             String tenantId, String vfModuleName, boolean skipAAI, String requestId, String serviceInstanceId)
101             throws VnfAdapterClientException {
102         UriBuilder builder = this.getUri("/" + aaiVnfId + VF_MODULES + aaiVfModuleId);
103         if (cloudSiteId != null) {
104             builder.queryParam("cloudSiteId", cloudSiteId);
105         }
106         if (tenantId != null) {
107             builder.queryParam("tenantId", tenantId);
108         }
109         if (vfModuleName != null) {
110             builder.queryParam("vfModuleName", vfModuleName);
111         }
112
113         builder.queryParam("skipAAI", skipAAI);
114
115         if (requestId != null) {
116             builder.queryParam("msoRequest.requestId", requestId);
117         }
118         if (serviceInstanceId != null) {
119             builder.queryParam("msoRequest.serviceInstanceId", serviceInstanceId);
120         }
121         try {
122             return new AdapterRestClient(this.props, builder.build(), MediaType.APPLICATION_JSON,
123                     MediaType.APPLICATION_JSON).get(QueryVfModuleResponse.class).get();
124         } catch (InternalServerErrorException e) {
125             throw new VnfAdapterClientException(e.getMessage());
126         }
127     }
128
129     public UriBuilder getUri(String path) {
130         return UriBuilder.fromPath(path);
131     }
132
133 }