2 * Copyright (c) 2018 Orange
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org.onap.nbi.apis.hub;
18 import org.onap.nbi.apis.hub.model.Subscriber;
19 import org.onap.nbi.apis.hub.model.Subscription;
20 import org.onap.nbi.apis.hub.repository.SubscriberRepository;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.http.MediaType;
25 import org.springframework.http.ResponseEntity;
26 import org.springframework.scheduling.annotation.EnableScheduling;
27 import org.springframework.web.bind.annotation.PostMapping;
28 import org.springframework.web.bind.annotation.RequestBody;
29 import org.springframework.web.bind.annotation.RequestMapping;
30 import org.springframework.web.bind.annotation.RestController;
31 import org.springframework.web.servlet.support.ServletUriComponentsBuilder;
36 @RequestMapping("/hub")
38 public class HubResource {
40 Logger logger = LoggerFactory.getLogger(HubResource.class);
43 SubscriberRepository subscriberRepository;
45 @PostMapping(consumes = MediaType.APPLICATION_JSON_VALUE)
46 public ResponseEntity<Subscriber> createEventSubscription(@RequestBody Subscription subscription) {
47 logger.debug("Received subscription request: {}", subscription);
49 Subscriber sub = Subscriber.createFromRequest(subscription);
50 sub = subscriberRepository.save(sub);
52 URI location = ServletUriComponentsBuilder
55 .buildAndExpand(sub.getId())
58 return ResponseEntity.created(location).build();