8bd55f0f90805ef5e9b6b158c9364c9d9f791f03
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / client / orchestration / AAIVpnBindingResources.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.orchestration;
22
23 import java.util.Optional;
24
25 import javax.ws.rs.NotFoundException;
26
27 import org.onap.aai.domain.yang.VpnBindings;
28 import org.onap.so.bpmn.common.InjectionHelper;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding;
31 import org.onap.so.client.aai.AAIObjectType;
32 import org.onap.so.client.aai.entities.uri.AAIResourceUri;
33 import org.onap.so.client.aai.entities.uri.AAIUriFactory;
34 import org.onap.so.client.aai.mapper.AAIObjectMapper;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.stereotype.Component;
37
38 @Component
39 public class AAIVpnBindingResources {
40         @Autowired
41         private InjectionHelper injectionHelper;
42         
43         @Autowired
44         private AAIObjectMapper aaiObjectMapper;
45         
46         /**
47          * @param customer
48          */
49         public boolean existsCustomer(Customer customer) {
50                 AAIResourceUri uriCustomer = AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, customer.getGlobalCustomerId());
51                 return injectionHelper.getAaiClient().exists(uriCustomer);
52         }
53
54         /**
55          * @param customerVpnId
56          * @return
57          */
58         public Optional<VpnBindings> getVpnBindingByCustomerVpnId (String customerVpnId) {
59                 AAIResourceUri aaiVpnBindingsResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.VPN_BINDINGS)
60                                                                                         .queryParam("customer-vpn-id",customerVpnId);
61                 return injectionHelper.getAaiClient().get(VpnBindings.class,aaiVpnBindingsResourceUri); 
62                 
63         }
64
65         /**
66          * @param vpnBinding
67          */
68         public void createVpnBinding(VpnBinding vpnBinding) {
69                 AAIResourceUri aaiVpnBindingResourceUri = AAIUriFactory.createResourceUri(AAIObjectType.VPN_BINDING,vpnBinding.getVpnId());
70                 injectionHelper.getAaiClient().create(aaiVpnBindingResourceUri, aaiObjectMapper.mapVpnBinding(vpnBinding));
71         }
72
73         /**
74          * @param customer
75          */
76         public void createCustomer(Customer customer) {
77                 AAIResourceUri uriCustomer = AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, customer.getGlobalCustomerId());
78                 injectionHelper.getAaiClient().create(uriCustomer, aaiObjectMapper.mapCustomer(customer));
79         }
80
81         /**
82          * Retrieve VPN Binding from AAI using vpn-id
83          * @param vpnId - vpn-id required VPN Binding
84          * @return AAI VPN Binding
85          */
86         public Optional<org.onap.aai.domain.yang.VpnBinding> getVpnBinding(String vpnId){
87                 return injectionHelper.getAaiClient()
88                                 .get(org.onap.aai.domain.yang.VpnBinding.class, AAIUriFactory.createResourceUri(AAIObjectType.VPN_BINDING, vpnId));
89         }
90
91
92         /**
93          * @param globalSubscriberId
94          * @param vpnId
95          */
96         public void connectCustomerToVpnBinding(String globalSubscriberId, String vpnId) {
97                 AAIResourceUri customerURI = AAIUriFactory.createResourceUri(AAIObjectType.CUSTOMER, globalSubscriberId);
98                 AAIResourceUri vpnBindingURI = AAIUriFactory.createResourceUri(AAIObjectType.VPN_BINDING,vpnId);
99                 injectionHelper.getAaiClient().connect(customerURI, vpnBindingURI);
100         }
101 }