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
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.api.impl.events.cmsubscription.service;
23 import java.util.ArrayList;
24 import java.util.List;
26 import java.util.stream.Collectors;
27 import lombok.RequiredArgsConstructor;
28 import org.onap.cps.ncmp.api.impl.events.cmsubscription.CmNotificationSubscriptionNcmpOutEventProducer;
29 import org.onap.cps.ncmp.api.impl.events.cmsubscription.DmiCmNotificationSubscriptionCacheHandler;
30 import org.onap.cps.ncmp.api.impl.events.cmsubscription.mapper.CmNotificationSubscriptionNcmpOutEventMapper;
31 import org.onap.cps.ncmp.events.cmnotificationsubscription_merge1_0_0.client_to_ncmp.CmNotificationSubscriptionNcmpInEvent;
32 import org.onap.cps.ncmp.events.cmnotificationsubscription_merge1_0_0.client_to_ncmp.Predicate;
33 import org.onap.cps.ncmp.events.cmsubscription_merge1_0_0.ncmp_to_client.CmNotificationSubscriptionNcmpOutEvent;
34 import org.springframework.stereotype.Service;
37 @RequiredArgsConstructor
38 public class CmNotificationSubscriptionHandlerServiceImpl implements CmNotificationSubscriptionHandlerService {
40 private final CmNotificationSubscriptionPersistenceService cmNotificationSubscriptionPersistenceService;
41 private final CmNotificationSubscriptionNcmpOutEventMapper cmNotificationSubscriptionNcmpOutEventMapper;
42 private final CmNotificationSubscriptionNcmpOutEventProducer cmNotificationSubscriptionNcmpOutEventProducer;
43 private final DmiCmNotificationSubscriptionCacheHandler dmiCmNotificationSubscriptionCacheHandler;
46 public void processSubscriptionCreateRequest(
47 final CmNotificationSubscriptionNcmpInEvent cmNotificationSubscriptionNcmpInEvent) {
48 final String subscriptionId = cmNotificationSubscriptionNcmpInEvent.getData().getSubscriptionId();
49 final List<Predicate> predicates = cmNotificationSubscriptionNcmpInEvent.getData().getPredicates();
51 if (cmNotificationSubscriptionPersistenceService.isUniqueSubscriptionId(subscriptionId)) {
52 dmiCmNotificationSubscriptionCacheHandler.add(subscriptionId, predicates);
54 final Set<String> subscriptionTargetFilters = predicates.stream().flatMap(
55 predicate -> predicate.getTargetFilter().stream()).collect(Collectors.toSet());
56 rejectAndPublishCmNotificationSubscriptionCreateRequest(subscriptionId,
57 new ArrayList<>(subscriptionTargetFilters));
61 private void rejectAndPublishCmNotificationSubscriptionCreateRequest(final String subscriptionId,
62 final List<String> subscriptionTargetFilters) {
63 final CmNotificationSubscriptionNcmpOutEvent cmNotificationSubscriptionNcmpOutEvent =
64 cmNotificationSubscriptionNcmpOutEventMapper
65 .toCmNotificationSubscriptionNcmpOutEventForRejectedRequest(subscriptionId,
66 subscriptionTargetFilters);
67 cmNotificationSubscriptionNcmpOutEventProducer.publishCmNotificationSubscriptionNcmpOutEvent(subscriptionId,
68 "subscriptionCreateResponse", cmNotificationSubscriptionNcmpOutEvent, false);