1 package org.onap.ccsdk.features.sdnr.wt.devicemanager.onf14.dom.impl.util;
3 import com.google.common.base.VerifyException;
4 import java.time.Instant;
5 import java.util.ArrayList;
6 import java.util.Collection;
7 import java.util.Iterator;
9 import org.opendaylight.mdsal.dom.api.DOMEvent;
10 import org.opendaylight.mdsal.dom.api.DOMNotification;
11 import org.opendaylight.yangtools.yang.common.QName;
12 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
13 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
14 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
15 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
16 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
17 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
18 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
19 import org.slf4j.Logger;
20 import org.slf4j.LoggerFactory;
22 public class Onf14DMDOMUtility {
24 public static final Logger LOG = LoggerFactory.getLogger(Onf14DMDOMUtility.class);
26 private Onf14DMDOMUtility() {}
28 public static String getLeafValue(DataContainerNode componentEntry, QName leafQName) {
29 NodeIdentifier leafNodeIdentifier = new NodeIdentifier(leafQName);
31 LeafNode<?> optLeafNode = (LeafNode<?>) componentEntry.getChildByArg(leafNodeIdentifier);
32 if (optLeafNode.body() instanceof QName) {
33 LOG.debug("Leaf is of type QName"); //Ex: ImmutableLeafNode{identifier=(urn:onf:yang:air-interface-2-0?revision=2020-01-21)severity, body=(urn:onf:yang:air-interface-2-0?revision=2020-01-21)SEVERITY_TYPE_MAJOR}
34 String severity_ = optLeafNode.body().toString();
35 return severity_.substring(severity_.indexOf(')')+1); //Any other solution??
37 return optLeafNode.body().toString();
38 } catch (VerifyException ve) {
39 LOG.debug("Leaf with QName {} not found", leafQName);
44 public static List<String> getLeafListValue(DataContainerNode componentEntry, QName leafListQName) {
45 List<String> containsChildList = new ArrayList<>();
47 DataContainerChild childSet = componentEntry.getChildByArg(new NodeIdentifier(leafListQName));
48 Collection<?> childEntry = (Collection<?>) childSet.body();
49 Iterator<?> childEntryItr = childEntry.iterator();
50 while (childEntryItr.hasNext()) {
51 LeafSetEntryNode<?> childEntryNode = (LeafSetEntryNode<?>) childEntryItr.next();
52 containsChildList.add(childEntryNode.body().toString());
54 } catch (VerifyException ve) {
55 LOG.debug("Child for {} does not exist", leafListQName);
57 return containsChildList;
60 public static String getUuidFromEquipment(MapEntryNode equipment) {
61 LOG.debug("Equipment Identifier is {}", equipment.getIdentifier());
62 NodeIdentifierWithPredicates componentKey = equipment.getIdentifier(); // list key
63 LOG.debug("Key Name is - {}", componentKey.keySet());
64 LOG.debug("Key Value is - {}",
65 componentKey.getValue(Onf14DevicemanagerQNames.CORE_MODEL_CC_EQPT_GLOBAL_CLASS_UUID));
67 return componentKey.getValue(Onf14DevicemanagerQNames.CORE_MODEL_CC_EQPT_GLOBAL_CLASS_UUID).toString();
70 public static Instant getNotificationInstant(DOMNotification notification) {
71 if (notification instanceof DOMEvent) {
72 return ((DOMEvent) notification).getEventInstant();