e9d6d784291999dc1bf1035c3eaa28bac594f7da
[cps.git] /
1 /*
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
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.impl.cmnotificationsubscription.ncmp;
22
23 import static org.onap.cps.ncmp.impl.cmnotificationsubscription.ncmp.NcmpOutEventProducer.buildAndGetNcmpOutEventAsCloudEvent;
24
25 import io.cloudevents.CloudEvent;
26 import java.util.Map;
27 import lombok.RequiredArgsConstructor;
28 import lombok.extern.slf4j.Slf4j;
29 import org.onap.cps.events.EventsPublisher;
30 import org.onap.cps.ncmp.impl.cmnotificationsubscription.cache.DmiCacheHandler;
31 import org.onap.cps.ncmp.impl.cmnotificationsubscription.models.DmiCmSubscriptionDetails;
32 import org.onap.cps.ncmp.impl.cmnotificationsubscription_1_0_0.ncmp_to_client.NcmpOutEvent;
33
34 @Slf4j
35 @RequiredArgsConstructor
36 public class NcmpOutEventPublishingTask implements Runnable {
37
38     private final String topicName;
39     private final String subscriptionId;
40     private final String eventType;
41     private final EventsPublisher<CloudEvent> eventsPublisher;
42     private final NcmpOutEventMapper ncmpOutEventMapper;
43     private final DmiCacheHandler dmiCacheHandler;
44
45     /**
46      * Delegating the responsibility of publishing NcmpOutEvent as a separate task which will
47      * be called after a specified delay.
48      */
49     @Override
50     public void run() {
51         final Map<String, DmiCmSubscriptionDetails> dmiSubscriptionsPerDmi =
52                 dmiCacheHandler.get(subscriptionId);
53         final NcmpOutEvent ncmpOutEvent = ncmpOutEventMapper.toNcmpOutEvent(subscriptionId,
54                 dmiSubscriptionsPerDmi);
55         eventsPublisher.publishCloudEvent(topicName, subscriptionId,
56                 buildAndGetNcmpOutEventAsCloudEvent(subscriptionId, eventType, ncmpOutEvent));
57         dmiCacheHandler.removeAcceptedAndRejectedDmiSubscriptionEntries(subscriptionId);
58     }
59 }