CM Subscription: REfactor classes of producers and consumers
[cps.git] / cps-ncmp-service / src / main / java / org / onap / cps / ncmp / api / impl / events / cmsubscription / CmNotificationSubscriptionEventsHandler.java
1 /*
2  * ============LICENSE_START=======================================================
3  * Copyright (c) 2024 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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  *
17  *  SPDX-License-Identifier: Apache-2.0
18  *  ============LICENSE_END=========================================================
19  */
20
21 package org.onap.cps.ncmp.api.impl.events.cmsubscription;
22
23 import lombok.RequiredArgsConstructor;
24 import org.onap.cps.ncmp.api.impl.events.cmsubscription.producer.CmNotificationSubscriptionDmiInEventProducer;
25 import org.onap.cps.ncmp.api.impl.events.cmsubscription.producer.CmNotificationSubscriptionNcmpOutEventProducer;
26 import org.onap.cps.ncmp.events.cmnotificationsubscription_merge1_0_0.ncmp_to_dmi.CmNotificationSubscriptionDmiInEvent;
27 import org.onap.cps.ncmp.events.cmsubscription_merge1_0_0.ncmp_to_client.CmNotificationSubscriptionNcmpOutEvent;
28 import org.springframework.stereotype.Service;
29
30 @Service
31 @RequiredArgsConstructor
32 public class CmNotificationSubscriptionEventsHandler {
33     private final CmNotificationSubscriptionNcmpOutEventProducer cmNotificationSubscriptionNcmpOutEventProducer;
34     private final CmNotificationSubscriptionDmiInEventProducer cmNotificationSubscriptionDmiInEventProducer;
35
36     /**
37      * Publish the event to the client who requested the subscription with key as subscription id and event is Cloud
38      * Event compliant.
39      *
40      * @param subscriptionId                         Cm Subscription Id
41      * @param eventType                              Type of event
42      * @param cmNotificationSubscriptionNcmpOutEvent Cm Notification Subscription Event for the
43      *                                               client
44      * @param isScheduledEvent                       Determines if the event is to be scheduled
45      *                                               or published now
46      */
47     public void publishCmNotificationSubscriptionNcmpOutEvent(final String subscriptionId, final String eventType,
48                                                   final CmNotificationSubscriptionNcmpOutEvent
49                                                           cmNotificationSubscriptionNcmpOutEvent,
50                                                   final boolean isScheduledEvent) {
51         cmNotificationSubscriptionNcmpOutEventProducer.publishCmNotificationSubscriptionNcmpOutEvent(subscriptionId,
52                 eventType, cmNotificationSubscriptionNcmpOutEvent, isScheduledEvent);
53     }
54
55     /**
56      * Publish the event to the provided dmi plugin with key as subscription id and the event is in Cloud Event format.
57      *
58      * @param subscriptionId                       Cm Subscription Id
59      * @param dmiPluginName                        Dmi Plugin Name
60      * @param eventType                            Type of event
61      * @param cmNotificationSubscriptionDmiInEvent Cm Notification Subscription event for Dmi
62      */
63     public void publishCmNotificationSubscriptionDmiInEvent(final String subscriptionId, final String dmiPluginName,
64                                                             final String eventType,
65                                                             final CmNotificationSubscriptionDmiInEvent
66                                                                     cmNotificationSubscriptionDmiInEvent) {
67         cmNotificationSubscriptionDmiInEventProducer.publishCmNotificationSubscriptionDmiInEvent(subscriptionId,
68                 dmiPluginName, eventType, cmNotificationSubscriptionDmiInEvent);
69     }
70 }