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 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;
33 public class SubscriberService {
35 private static final char COLON = ':';
37 @Value("${system.url}")
38 private String systemUrl;
40 @Value("${server.port}")
41 private String serverPort;
43 @Value("${notification.url}")
44 private String notificationUrl;
46 @Value("${spring.security.usercredentials[0].username}")
47 private String username;
49 @Value("${spring.security.usercredentials[0].openpass}")
50 private String openpass;
53 private SubscribeSender sender;
55 public boolean subscribe(final String endpoint) {
56 final LccnSubscriptionRequest request = createRequest();
57 return sender.send(endpoint, request);
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(username);
66 paramsBasic.setPassword(openpass);
67 authentication.setAuthType(Collections.singletonList(SubscriptionsAuthentication.AuthTypeEnum.BASIC));
68 authentication.setParamsBasic(paramsBasic);
69 request.authentication(authentication);
74 private String getCallbackUri() {
75 return systemUrl + COLON + serverPort + notificationUrl;