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.utils;
23 import java.io.Serializable;
24 import java.util.Collection;
25 import java.util.List;
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;
33 @NoArgsConstructor(access = AccessLevel.PRIVATE)
34 public class DataNodeHelper {
37 * The nested DataNode object is being flattened.
39 * @param dataNode object.
40 * @return DataNode as stream.
42 public static Stream<DataNode> flatten(final DataNode dataNode) {
43 return Stream.concat(Stream.of(dataNode),
44 dataNode.getChildDataNodes().stream().flatMap(DataNodeHelper::flatten));
48 * The leaves for each DataNode is listed as map.
50 * @param dataNodes as collection.
51 * @return list of map for the all leaves.
53 public static List<Map<String, Serializable>> getDataNodeLeaves(final Collection<DataNode> dataNodes) {
54 return dataNodes.stream()
55 .flatMap(DataNodeHelper::flatten)
56 .map(node -> node.getLeaves())
57 .collect(Collectors.toList());
61 * The cm handle and status is listed as a collection.
63 * @param dataNodeLeaves as a list of map.
64 * @return list of collection containing cm handle id and statuses.
66 public static List<Collection<Serializable>> getCmHandleIdToStatus(
67 final List<Map<String, Serializable>> dataNodeLeaves) {
68 return dataNodeLeaves.stream()
69 .map(target -> target.values())
70 .filter(col -> col.contains("PENDING")
71 | col.contains("ACCEPTED")
72 | col.contains("REJECTED"))
73 .collect(Collectors.toList());