Add HubRessource Test
[externalapi/nbi.git] / src / main / java / org / onap / nbi / apis / hub / service / NotifierService.java
1 /**
2  *     Copyright (c) 2018 Orange
3  *
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
7  *
8  *         http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  */
16 package org.onap.nbi.apis.hub.service;
17
18 import org.onap.nbi.apis.hub.model.Event;
19 import org.onap.nbi.apis.hub.model.Subscriber;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.http.HttpStatus;
24 import org.springframework.http.ResponseEntity;
25 import org.springframework.scheduling.annotation.Async;
26 import org.springframework.stereotype.Service;
27 import org.springframework.web.client.RestTemplate;
28
29 import javax.validation.Valid;
30
31 @Service
32 public class NotifierService {
33     private final Logger logger = LoggerFactory.getLogger(NotifierService.class);
34
35     @Autowired
36     RestTemplate restTemplate;
37
38     @Async
39     public void run(Subscriber subscriber, @Valid Event event) {
40         ResponseEntity<String> re = restTemplate.postForEntity(subscriber.getCallback(), event, String.class);
41         if (re.getStatusCode() == HttpStatus.OK) logger.debug("FAILED");
42     }
43 }