2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2020 Nordix Foundation.
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.so.svnfm.simulator.controller;
23 import javax.ws.rs.core.MediaType;
24 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.InlineResponse201;
25 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.PkgmSubscriptionRequest;
26 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsAuthentication;
27 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsAuthentication.AuthTypeEnum;
28 import org.onap.so.adapters.vnfmadapter.extclients.vnfm.packagemanagement.model.SubscriptionsAuthenticationParamsBasic;
29 import org.onap.so.svnfm.simulator.constants.Constant;
30 import org.onap.so.svnfm.simulator.services.SubscriptionManager;
31 import org.slf4j.Logger;
32 import org.slf4j.LoggerFactory;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.beans.factory.annotation.Value;
35 import org.springframework.http.ResponseEntity;
36 import org.springframework.web.bind.annotation.GetMapping;
37 import org.springframework.web.bind.annotation.PostMapping;
38 import org.springframework.web.bind.annotation.RequestBody;
39 import org.springframework.web.bind.annotation.RequestMapping;
40 import org.springframework.web.bind.annotation.RestController;
43 * @author Eoin Hanan (eoin.hanan@est.tech)
44 * @author Andrew Lamb (andrew.a.lamb@est.tech)
48 @RequestMapping(path = Constant.PACKAGE_MANAGEMENT_BASE_URL, produces = MediaType.APPLICATION_JSON, consumes = MediaType.APPLICATION_JSON)
49 public class SubscriptionNotificationController {
51 private SubscriptionManager subscriptionManager;
53 private static final Logger logger = LoggerFactory.getLogger(SubscriptionNotificationController.class);
55 @Value("${spring.security.usercredentials[0].username}")
56 private String username;
57 @Value("${spring.security.usercredentials[0].password}")
58 private String password;
60 @GetMapping(produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
61 public ResponseEntity<Void> testEndpoint() {
62 logger.info("Testing SubscriptionNotification Endpoint");
63 return ResponseEntity.noContent().build();
67 * Send subscription request
69 * @param pkgmSubscriptionRequest The subscription request
72 @PostMapping(value = Constant.SUBSCRIPTION_ENDPOINT, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
73 public ResponseEntity<?> subscribeForNotifications(@RequestBody final PkgmSubscriptionRequest pkgmSubscriptionRequest){
74 logger.info("Vnf Package Subscription Request received:\n{}", pkgmSubscriptionRequest);
76 if(pkgmSubscriptionRequest.getCallbackUri()==null){
77 logger.info("Subscription Request does not include call back URI ");
78 pkgmSubscriptionRequest.setCallbackUri(Constant.PACKAGE_MANAGEMENT_BASE_URL + Constant.NOTIFICATION_ENDPOINT);
81 if(pkgmSubscriptionRequest.getAuthentication()==null) {
82 pkgmSubscriptionRequest.setAuthentication(new SubscriptionsAuthentication()
83 .addAuthTypeItem(AuthTypeEnum.BASIC)
84 .paramsBasic(new SubscriptionsAuthenticationParamsBasic().userName(username).password(password)));
87 logger.info("Final Request being sent:\n{}", pkgmSubscriptionRequest);
89 final InlineResponse201 response = subscriptionManager.createSubscription(pkgmSubscriptionRequest);
90 logger.info("Response is:\n{}", response);
92 return ResponseEntity.ok().body(response);
96 * Endpoint to receive VNF package notifications
98 * @param notification The notification received
101 @PostMapping(value = Constant.NOTIFICATION_ENDPOINT, produces = {MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
102 public ResponseEntity<?> postVnfPackageNotification(@RequestBody Object notification){
103 logger.info("Vnf Notification received:\n{}", notification);
104 return ResponseEntity.noContent().build();