e413124b4bb51e1c6c530b411383c153f013c9cf
[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 org.onap.so.adapters.vevnfm.subscription.SubscribeSender;
24 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.LccnSubscriptionRequest;
25 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsAuthentication;
26 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.model.SubscriptionsAuthenticationParamsBasic;
27 import org.springframework.beans.factory.annotation.Autowired;
28 import org.springframework.beans.factory.annotation.Value;
29 import org.springframework.stereotype.Service;
30
31 @Service
32 public class SubscriberService {
33
34     private static final char COLON = ':';
35
36     @Value("${notification.url}")
37     private String notificationUrl;
38
39     @Value("${server.port}")
40     private String serverPort;
41
42     @Value("${system.url}")
43     private String systemUrl;
44
45     @Autowired
46     private SubscribeSender sender;
47
48     public boolean subscribe(final String endpoint) {
49         final LccnSubscriptionRequest request = createRequest();
50         return sender.send(endpoint, request);
51     }
52
53     private LccnSubscriptionRequest createRequest() {
54         final LccnSubscriptionRequest request = new LccnSubscriptionRequest();
55         request.callbackUri(getCallbackUri());
56         final SubscriptionsAuthenticationParamsBasic paramsBasic = new SubscriptionsAuthenticationParamsBasic();
57         final SubscriptionsAuthentication authentication = new SubscriptionsAuthentication();
58         authentication.setParamsBasic(paramsBasic);
59         request.authentication(authentication);
60
61         return request;
62     }
63
64     private String getCallbackUri() {
65         return systemUrl + COLON + serverPort + notificationUrl;
66     }
67 }