2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * Copyright (C) 2018-2021 Nokia. All rights reserved.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
21 package org.onap.dcae.common;
24 import io.vavr.collection.Map;
25 import org.onap.dcae.common.model.VesEvent;
26 import org.onap.dcae.common.publishing.DMaaPEventPublisher;
27 import org.onap.dcae.restapi.EventValidatorException;
28 import org.slf4j.Logger;
29 import org.slf4j.LoggerFactory;
30 import org.springframework.http.HttpStatus;
32 import java.util.List;
34 import static org.onap.dcae.restapi.ApiException.DOMAIN_NOT_DEFINED_FOR_STREAM_ID;
37 public class EventSender {
39 private Map<String, String> streamIdToDmaapIds;
40 private DMaaPEventPublisher eventPublisher;
41 private static final Logger log = LoggerFactory.getLogger(EventSender.class);
43 public EventSender(DMaaPEventPublisher eventPublisher, Map<String, String> streamIdToDmaapIds) {
44 this.eventPublisher = eventPublisher;
45 this.streamIdToDmaapIds = streamIdToDmaapIds;
48 public HttpStatus send(List<VesEvent> vesEvents) {
49 String topic = streamIdToDmaapIds
50 .get(vesEvents.get(0).getStreamId())
52 log.error("No StreamID defined for publish - Message dropped " + vesEvents.get(0).asJsonObject());
53 throw new EventValidatorException(DOMAIN_NOT_DEFINED_FOR_STREAM_ID);
55 return eventPublisher.sendEvent(vesEvents, topic);