2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2024-2025 Nordix Foundation
4 * ================================================================================
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
17 * SPDX-License-Identifier: Apache-2.0
18 * ============LICENSE_END=========================================================
21 package org.onap.cps.ncmp.impl.cmnotificationsubscription.dmi;
23 import static org.onap.cps.ncmp.events.NcmpEventDataSchema.SUBSCRIPTIONS_V1;
25 import io.cloudevents.CloudEvent;
27 import lombok.RequiredArgsConstructor;
28 import org.onap.cps.events.EventsPublisher;
29 import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_dmi.DmiInEvent;
30 import org.onap.cps.ncmp.utils.events.NcmpEvent;
31 import org.springframework.beans.factory.annotation.Value;
32 import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
33 import org.springframework.stereotype.Component;
36 @RequiredArgsConstructor
37 @ConditionalOnProperty(name = "notification.enabled", havingValue = "true", matchIfMissing = true)
38 public class DmiInEventProducer {
40 private final EventsPublisher<CloudEvent> eventsPublisher;
42 @Value("${app.ncmp.avc.cm-subscription-dmi-in}")
43 private String dmiInEventTopic;
46 * Publish the event to the provided dmi plugin with key as subscription id and the event is in Cloud Event format.
48 * @param subscriptionId Cm Subscription Id
49 * @param dmiPluginName Dmi Plugin Name
50 * @param eventType Type of event
51 * @param dmiInEvent Cm Notification Subscription event for Dmi
53 public void publishDmiInEvent(final String subscriptionId, final String dmiPluginName,
54 final String eventType, final DmiInEvent dmiInEvent) {
55 eventsPublisher.publishCloudEvent(dmiInEventTopic, subscriptionId,
56 buildAndGetDmiInEventAsCloudEvent(subscriptionId, dmiPluginName, eventType, dmiInEvent));
60 private CloudEvent buildAndGetDmiInEventAsCloudEvent(final String subscriptionId, final String dmiPluginName,
61 final String eventType, final DmiInEvent dmiInEvent) {
62 return NcmpEvent.builder()
64 .dataSchema(SUBSCRIPTIONS_V1.getDataSchema())
65 .extensions(Map.of("correlationid", String.join("#", subscriptionId, dmiPluginName)))