Add DMaaP Integration to retrieve AAI-EVENT
[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 package org.onap.nbi.apis.hub.service;
15
16 import javax.validation.Valid;
17 import org.onap.nbi.apis.hub.model.Event;
18 import org.onap.nbi.apis.hub.model.Subscriber;
19 import org.onap.nbi.exceptions.BackendFunctionalException;
20 import org.slf4j.Logger;
21 import org.slf4j.LoggerFactory;
22 import org.springframework.beans.factory.annotation.Autowired;
23 import org.springframework.scheduling.annotation.Async;
24 import org.springframework.stereotype.Service;
25 import org.springframework.web.client.RestTemplate;
26
27 @Service
28 public class NotifierService {
29
30   private final Logger logger = LoggerFactory.getLogger(NotifierService.class);
31
32   @Autowired
33   RestTemplate restTemplate;
34
35   @Async
36   public void run(Subscriber subscriber, @Valid Event event) {
37     try {
38       restTemplate.postForEntity(subscriber.getCallback(), event, Object.class);
39     } catch (BackendFunctionalException e) {
40       logger.error(" unable to post event to {} , receive {}, {}", subscriber.getCallback(),
41           e.getHttpStatus(), e.getBodyResponse());
42     }
43
44   }
45 }