5200be9d652f9d88d86b8903c907897b5d5cdcc2
[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 import org.onap.aai.domain.yang.VpnBindings;
25 import org.onap.aaiclient.client.aai.entities.uri.AAIPluralResourceUri;
26 import org.onap.aaiclient.client.aai.entities.uri.AAIResourceUri;
27 import org.onap.aaiclient.client.aai.entities.uri.AAIUriFactory;
28 import org.onap.aaiclient.client.generated.fluentbuilders.AAIFluentTypeBuilder;
29 import org.onap.so.bpmn.common.InjectionHelper;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.Customer;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.VpnBinding;
32 import org.onap.so.client.aai.mapper.AAIObjectMapper;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
35
36 @Component
37 public class AAIVpnBindingResources {
38     @Autowired
39     private InjectionHelper injectionHelper;
40
41     @Autowired
42     private AAIObjectMapper aaiObjectMapper;
43
44     /**
45      * @param customer
46      */
47     public boolean existsCustomer(Customer customer) {
48         AAIResourceUri uriCustomer = AAIUriFactory
49                 .createResourceUri(AAIFluentTypeBuilder.business().customer(customer.getGlobalCustomerId()));
50         return injectionHelper.getAaiClient().exists(uriCustomer);
51     }
52
53     /**
54      * @param customerVpnId
55      * @return
56      */
57     public Optional<VpnBindings> getVpnBindingByCustomerVpnId(String customerVpnId) {
58         AAIPluralResourceUri aaiVpnBindingsResourceUri =
59                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vpnBindings())
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 =
70                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vpnBinding(vpnBinding.getVpnId()));
71         injectionHelper.getAaiClient().create(aaiVpnBindingResourceUri, aaiObjectMapper.mapVpnBinding(vpnBinding));
72     }
73
74     /**
75      * @param customer
76      */
77     public void createCustomer(Customer customer) {
78         AAIResourceUri uriCustomer = AAIUriFactory
79                 .createResourceUri(AAIFluentTypeBuilder.business().customer(customer.getGlobalCustomerId()));
80         injectionHelper.getAaiClient().create(uriCustomer, aaiObjectMapper.mapCustomer(customer));
81     }
82
83     /**
84      * Retrieve VPN Binding from AAI using vpn-id
85      * 
86      * @param vpnId - vpn-id required VPN Binding
87      * @return AAI VPN Binding
88      */
89     public Optional<org.onap.aai.domain.yang.VpnBinding> getVpnBinding(String vpnId) {
90         return injectionHelper.getAaiClient().get(org.onap.aai.domain.yang.VpnBinding.class,
91                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vpnBinding(vpnId)));
92     }
93
94
95     /**
96      * @param globalSubscriberId
97      * @param vpnId
98      */
99     public void connectCustomerToVpnBinding(String globalSubscriberId, String vpnId) {
100         AAIResourceUri customerURI =
101                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.business().customer(globalSubscriberId));
102         AAIResourceUri vpnBindingURI =
103                 AAIUriFactory.createResourceUri(AAIFluentTypeBuilder.network().vpnBinding(vpnId));
104         injectionHelper.getAaiClient().connect(customerURI, vpnBindingURI);
105     }
106 }