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 / VnfVolumeAdapterClientImpl.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.CreateVolumeGroupRequest;
27 import org.onap.so.adapters.vnfrest.CreateVolumeGroupResponse;
28 import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest;
29 import org.onap.so.adapters.vnfrest.DeleteVolumeGroupResponse;
30 import org.onap.so.adapters.vnfrest.QueryVolumeGroupResponse;
31 import org.onap.so.adapters.vnfrest.RollbackVolumeGroupRequest;
32 import org.onap.so.adapters.vnfrest.RollbackVolumeGroupResponse;
33 import org.onap.so.adapters.vnfrest.UpdateVolumeGroupRequest;
34 import org.onap.so.adapters.vnfrest.UpdateVolumeGroupResponse;
35 import org.onap.so.client.RestClient;
36 import org.onap.so.client.adapter.rest.AdapterRestClient;
37 import org.springframework.stereotype.Component;
38
39 @Component
40 public class VnfVolumeAdapterClientImpl implements VnfVolumeAdapterClient {
41
42     private final VnfVolumeAdapterRestProperties props;
43
44     public VnfVolumeAdapterClientImpl() {
45         this.props = new VnfVolumeAdapterRestProperties();
46     }
47
48     @Override
49     public CreateVolumeGroupResponse createVNFVolumes(CreateVolumeGroupRequest req) throws VnfAdapterClientException {
50         try {
51             return this.getAdapterRestClient("").post(req, CreateVolumeGroupResponse.class);
52         } catch (InternalServerErrorException e) {
53             throw new VnfAdapterClientException(e.getMessage());
54         }
55     }
56
57     @Override
58     public DeleteVolumeGroupResponse deleteVNFVolumes(String aaiVolumeGroupId, DeleteVolumeGroupRequest req)
59             throws VnfAdapterClientException {
60         try {
61             return this.getAdapterRestClient("/" + aaiVolumeGroupId).delete(req, DeleteVolumeGroupResponse.class);
62         } catch (InternalServerErrorException e) {
63             throw new VnfAdapterClientException(e.getMessage());
64         }
65     }
66
67     @Override
68     public RollbackVolumeGroupResponse rollbackVNFVolumes(String aaiVolumeGroupId, RollbackVolumeGroupRequest req)
69             throws VnfAdapterClientException {
70         try {
71             return this.getAdapterRestClient("/" + aaiVolumeGroupId + "/rollback").delete(req,
72                     RollbackVolumeGroupResponse.class);
73         } catch (InternalServerErrorException e) {
74             throw new VnfAdapterClientException(e.getMessage());
75         }
76     }
77
78     @Override
79     public UpdateVolumeGroupResponse updateVNFVolumes(String aaiVolumeGroupId, UpdateVolumeGroupRequest req)
80             throws VnfAdapterClientException {
81         try {
82             return this.getAdapterRestClient("/" + aaiVolumeGroupId).put(req, UpdateVolumeGroupResponse.class);
83         } catch (InternalServerErrorException e) {
84             throw new VnfAdapterClientException(e.getMessage());
85         }
86     }
87
88     @Override
89     public QueryVolumeGroupResponse queryVNFVolumes(String aaiVolumeGroupId, String cloudSiteId, String tenantId,
90             String volumeGroupStackId, Boolean skipAAI, String requestId, String serviceInstanceId)
91             throws VnfAdapterClientException {
92         try {
93             String path = buildQueryPath(aaiVolumeGroupId, cloudSiteId, tenantId, volumeGroupStackId, skipAAI,
94                     requestId, serviceInstanceId);
95             return this.getAdapterRestClient(path).get(QueryVolumeGroupResponse.class).get();
96         } catch (InternalServerErrorException e) {
97             throw new VnfAdapterClientException(e.getMessage());
98         }
99     }
100
101     protected String buildQueryPath(String aaiVolumeGroupId, String cloudSiteId, String tenantId,
102             String volumeGroupStackId, Boolean skipAAI, String requestId, String serviceInstanceId) {
103         javax.ws.rs.core.UriBuilder builder = this.getUri("/" + aaiVolumeGroupId);
104         builder.queryParam("cloudSiteId", cloudSiteId).queryParam("tenantId", tenantId)
105                 .queryParam("volumeGroupStackId", volumeGroupStackId).queryParam("skipAAI", skipAAI)
106                 .queryParam("msoRequest.requestId", requestId)
107                 .queryParam("msoRequest.serviceInstanceId", serviceInstanceId);
108         return builder.build().toString();
109     }
110
111     protected UriBuilder getUri(String path) {
112         return UriBuilder.fromPath(path);
113     }
114
115     protected RestClient getAdapterRestClient(String path) {
116         return new AdapterRestClient(props, this.getUri(path).build(), MediaType.APPLICATION_JSON,
117                 MediaType.APPLICATION_JSON);
118     }
119 }