2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.adapters.vevnfm.service;
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;
32 public class SubscriberService {
34 private static final char COLON = ':';
36 @Value("${notification.url}")
37 private String notificationUrl;
39 @Value("${server.port}")
40 private String serverPort;
42 @Value("${system.url}")
43 private String systemUrl;
46 private SubscribeSender sender;
48 public boolean subscribe(final String endpoint) {
49 final LccnSubscriptionRequest request = createRequest();
50 return sender.send(endpoint, request);
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);
64 private String getCallbackUri() {
65 return systemUrl + COLON + serverPort + notificationUrl;