Improve 32K limit tests
[cps.git] / cps-ncmp-service / src / main / java / org / onap / cps / ncmp / api / impl / events / avcsubscription / SubscriptionOutcomeMapper.java
1 /*
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
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.avcsubscription;
22
23 import java.util.List;
24 import java.util.Map;
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;
32
33 @Mapper(componentModel = "spring")
34 public interface SubscriptionOutcomeMapper {
35
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);
46
47     /**
48      * Maps StatusToCMHandle to list of TargetCmHandle rejected.
49      *
50      * @param targets as a map
51      * @return TargetCmHandle list
52      */
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());
59     }
60
61     /**
62      * Maps StatusToCMHandle to list of TargetCmHandle accepted.
63      *
64      * @param targets as a map
65      * @return TargetCmHandle list
66      */
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());
73     }
74
75     /**
76      * Maps StatusToCMHandle to list of TargetCmHandle pending.
77      *
78      * @param targets as a map
79      * @return TargetCmHandle list
80      */
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());
87     }
88 }