2 * ============LICENSE_START=======================================================
3 * ONAP : ccsdk features
4 * ================================================================================
5 * Copyright (C) 2021 highstreet technologies GmbH Intellectual Property.
7 * ================================================================================
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 * ============LICENSE_END=========================================================
22 package org.onap.ccsdk.features.sdnr.wt.devicemanager.oran.impl.dom;
24 import java.time.Instant;
25 import java.util.ArrayList;
26 import java.util.Collection;
27 import java.util.HashSet;
28 import java.util.Iterator;
29 import java.util.List;
32 import org.opendaylight.mdsal.dom.api.DOMEvent;
33 import org.opendaylight.mdsal.dom.api.DOMNotification;
34 import org.opendaylight.yangtools.yang.common.QName;
35 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
36 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
37 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
38 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
39 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
40 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
41 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
42 import org.slf4j.Logger;
43 import org.slf4j.LoggerFactory;
45 import com.google.common.base.VerifyException;
47 public class ORanDMDOMUtility {
48 public static final Logger LOG = LoggerFactory.getLogger(ORanDMDOMUtility.class);
50 public static String getKeyValue(MapEntryNode componentEntry) {
51 NodeIdentifierWithPredicates componentKey = componentEntry.getIdentifier(); // list key
52 return (String) componentKey.getValue(ORanDeviceManagerQNames.IETF_HW_COMPONENT_LIST_KEY);
55 public static String getLeafValue(DataContainerNode componentEntry, QName leafQName) {
56 NodeIdentifier leafNodeIdentifier = new NodeIdentifier(leafQName);
58 LeafNode<?> optLeafNode = (LeafNode<?>) componentEntry.getChildByArg(leafNodeIdentifier);
59 if (optLeafNode.body() instanceof QName) {
60 LOG.debug("Leaf is of type QName");
62 return optLeafNode.body().toString();
63 } catch (VerifyException ve) {
64 LOG.debug("Leaf with QName {} not found", leafQName.toString());
69 public static Set<String> getLeafListValue(DataContainerNode componentEntry, QName leafListQName) {
70 Set<String> containsChildList = new HashSet<String>();
72 DataContainerChild childSet = componentEntry.getChildByArg(new NodeIdentifier(leafListQName));
73 Collection<?> childEntry = (Collection<?>) childSet.body();
74 Iterator<?> childEntryItr = childEntry.iterator();
75 while (childEntryItr.hasNext()) {
76 LeafSetEntryNode<?> childEntryNode = (LeafSetEntryNode<?>) childEntryItr.next();
77 containsChildList.add(childEntryNode.body().toString());
79 } catch (VerifyException ve) {
80 LOG.debug("Child for {} does not exist", leafListQName);
82 return containsChildList;
85 public static Instant getNotificationInstant(DOMNotification notification) {
86 if (notification instanceof DOMEvent) {
87 return ((DOMEvent) notification).getEventInstant();