Format Java code with respect to ONAP Code Style
[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"); you may not use this file except
5  * in compliance with the License. You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software distributed under the License
10  * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11  * or implied. See the License for the specific language governing permissions and limitations under
12  * the License.
13  */
14
15 package org.onap.nbi.apis.hub.service;
16
17 import javax.validation.Valid;
18 import org.onap.nbi.apis.hub.model.Event;
19 import org.onap.nbi.apis.hub.model.Subscriber;
20 import org.onap.nbi.exceptions.BackendFunctionalException;
21 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory;
23 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.scheduling.annotation.Async;
25 import org.springframework.stereotype.Service;
26 import org.springframework.web.client.RestTemplate;
27
28 @Service
29 public class NotifierService {
30
31     private final Logger logger = LoggerFactory.getLogger(NotifierService.class);
32
33     @Autowired
34     RestTemplate restTemplate;
35
36     @Async
37     public void run(Subscriber subscriber, @Valid Event event) {
38         try {
39             restTemplate.postForEntity(subscriber.getCallback(), event, Object.class);
40         } catch (BackendFunctionalException e) {
41             logger.error(" unable to post event to {} , receive {}, {}", subscriber.getCallback(), e.getHttpStatus(),
42                     e.getBodyResponse());
43         }
44
45     }
46 }