aa07ed65a264e0228cc6d9d9a794ed7972871b6e
[so.git] /
1 /*-
2  * ============LICENSE_START=======================================================
3  * SO
4  * ================================================================================
5  * Copyright (C) 2020 Samsung. 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.adapters.vevnfm.service;
22
23 import java.util.Collections;
24 import org.onap.so.adapters.vevnfm.subscription.SubscribeSender;
25 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
26 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsAuthentication;
27 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsAuthenticationParamsBasic;
28 import org.springframework.beans.factory.annotation.Autowired;
29 import org.springframework.beans.factory.annotation.Value;
30 import org.springframework.stereotype.Service;
31
32 @Service
33 public class SubscriberService {
34
35     private static final char COLON = ':';
36
37     @Value("${system.url}")
38     private String systemUrl;
39
40     @Value("${server.port}")
41     private String serverPort;
42
43     @Value("${notification.url}")
44     private String notificationUrl;
45
46     @Value("${notification.username}")
47     private String notificationUsername;
48
49     @Value("${notification.password}")
50     private String notificationPassword;
51
52     @Autowired
53     private SubscribeSender sender;
54
55     public boolean subscribe(final String endpoint) {
56         final LccnSubscriptionRequest request = createRequest();
57         return sender.send(endpoint, request);
58     }
59
60     private LccnSubscriptionRequest createRequest() {
61         final LccnSubscriptionRequest request = new LccnSubscriptionRequest();
62         request.callbackUri(getCallbackUri());
63         final SubscriptionsAuthenticationParamsBasic paramsBasic = new SubscriptionsAuthenticationParamsBasic();
64         final SubscriptionsAuthentication authentication = new SubscriptionsAuthentication();
65         paramsBasic.setUserName(notificationUsername);
66         paramsBasic.setPassword(notificationPassword);
67         authentication.setAuthType(Collections.singletonList(SubscriptionsAuthentication.AuthTypeEnum.BASIC));
68         authentication.setParamsBasic(paramsBasic);
69         request.authentication(authentication);
70
71         return request;
72     }
73
74     private String getCallbackUri() {
75         return systemUrl + COLON + serverPort + notificationUrl;
76     }
77 }