2 * ============LICENSE_START=======================================================
3 * Copyright (C) 2023 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.avcsubscription;
23 import java.util.List;
25 import java.util.stream.Collectors;
26 import org.mapstruct.Mapper;
27 import org.mapstruct.Mapping;
28 import org.mapstruct.Named;
29 import org.onap.cps.ncmp.api.impl.subscriptions.SubscriptionStatus;
30 import org.onap.cps.ncmp.api.models.SubscriptionEventResponse;
31 import org.onap.cps.ncmp.events.avc.subscription.v1.SubscriptionEventOutcome;
33 @Mapper(componentModel = "spring")
34 public interface SubscriptionOutcomeMapper {
36 @Mapping(source = "clientId", target = "event.subscription.clientID")
37 @Mapping(source = "subscriptionName", target = "event.subscription.name")
38 @Mapping(source = "cmHandleIdToStatus", target = "event.predicates.rejectedTargets",
39 qualifiedByName = "mapStatusToCmHandleRejected")
40 @Mapping(source = "cmHandleIdToStatus", target = "event.predicates.acceptedTargets",
41 qualifiedByName = "mapStatusToCmHandleAccepted")
42 @Mapping(source = "cmHandleIdToStatus", target = "event.predicates.pendingTargets",
43 qualifiedByName = "mapStatusToCmHandlePending")
44 SubscriptionEventOutcome toSubscriptionEventOutcome(
45 SubscriptionEventResponse subscriptionEventResponse);
48 * Maps StatusToCMHandle to list of TargetCmHandle rejected.
50 * @param targets as a map
51 * @return TargetCmHandle list
53 @Named("mapStatusToCmHandleRejected")
54 default List<Object> mapStatusToCmHandleRejected(Map<String, SubscriptionStatus> targets) {
55 return targets.entrySet()
56 .stream().filter(target -> SubscriptionStatus.REJECTED.equals(target.getValue()))
57 .map(Map.Entry::getKey)
58 .collect(Collectors.toList());
62 * Maps StatusToCMHandle to list of TargetCmHandle accepted.
64 * @param targets as a map
65 * @return TargetCmHandle list
67 @Named("mapStatusToCmHandleAccepted")
68 default List<Object> mapStatusToCmHandleAccepted(Map<String, SubscriptionStatus> targets) {
69 return targets.entrySet()
70 .stream().filter(target -> SubscriptionStatus.ACCEPTED.equals(target.getValue()))
71 .map(Map.Entry::getKey)
72 .collect(Collectors.toList());
76 * Maps StatusToCMHandle to list of TargetCmHandle pending.
78 * @param targets as a map
79 * @return TargetCmHandle list
81 @Named("mapStatusToCmHandlePending")
82 default List<Object> mapStatusToCmHandlePending(Map<String, SubscriptionStatus> targets) {
83 return targets.entrySet()
84 .stream().filter(target -> SubscriptionStatus.PENDING.equals(target.getValue()))
85 .map(Map.Entry::getKey)
86 .collect(Collectors.toList());