Replace deprecated WebSecurityConfigurerAdapter
[cps.git] / cps-ncmp-service / src / main / java / org / onap / cps / ncmp / api / impl / utils / DataNodeHelper.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.utils;
22
23 import java.io.Serializable;
24 import java.util.Collection;
25 import java.util.List;
26 import java.util.Map;
27 import java.util.stream.Collectors;
28 import java.util.stream.Stream;
29 import lombok.AccessLevel;
30 import lombok.NoArgsConstructor;
31 import org.onap.cps.spi.model.DataNode;
32
33 @NoArgsConstructor(access = AccessLevel.PRIVATE)
34 public class DataNodeHelper {
35
36     /**
37      * The nested DataNode object is being flattened.
38      *
39      * @param dataNode object.
40      * @return DataNode as stream.
41      */
42     public static Stream<DataNode> flatten(final DataNode dataNode) {
43         return Stream.concat(Stream.of(dataNode),
44                 dataNode.getChildDataNodes().stream().flatMap(DataNodeHelper::flatten));
45     }
46
47     /**
48      * The leaves for each DataNode is listed as map.
49      *
50      * @param dataNodes as collection.
51      * @return list of map for the all leaves.
52      */
53     public static List<Map<String, Serializable>> getDataNodeLeaves(final Collection<DataNode> dataNodes) {
54         return dataNodes.stream()
55                 .flatMap(DataNodeHelper::flatten)
56                 .map(DataNode::getLeaves)
57                 .collect(Collectors.toList());
58     }
59
60     /**
61      * The cm handle and status is listed as a collection.
62      *
63      * @param dataNodeLeaves as a list of map.
64      * @return list of collection containing cm handle id and statuses.
65      */
66     public static List<Collection<Serializable>> getCmHandleIdToStatus(
67             final List<Map<String, Serializable>> dataNodeLeaves) {
68         return dataNodeLeaves.stream()
69                 .map(Map::values)
70                 .filter(col -> col.contains("PENDING")
71                         || col.contains("ACCEPTED")
72                         || col.contains("REJECTED"))
73                 .collect(Collectors.toList());
74     }
75 }