2  * ============LICENSE_START=======================================================
 
   3  * ONAP : ccsdk features
 
   4  * ================================================================================
 
   5  * Copyright (C) 2022 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.onf14.dom.impl.util;
 
  24 import com.google.common.base.VerifyException;
 
  25 import java.time.Instant;
 
  26 import java.util.ArrayList;
 
  27 import java.util.Collection;
 
  28 import java.util.Iterator;
 
  29 import java.util.List;
 
  30 import org.opendaylight.mdsal.dom.api.DOMEvent;
 
  31 import org.opendaylight.mdsal.dom.api.DOMNotification;
 
  32 import org.opendaylight.yangtools.yang.common.QName;
 
  33 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
 
  34 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifierWithPredicates;
 
  35 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
 
  36 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerNode;
 
  37 import org.opendaylight.yangtools.yang.data.api.schema.LeafNode;
 
  38 import org.opendaylight.yangtools.yang.data.api.schema.LeafSetEntryNode;
 
  39 import org.opendaylight.yangtools.yang.data.api.schema.MapEntryNode;
 
  40 import org.slf4j.Logger;
 
  41 import org.slf4j.LoggerFactory;
 
  43 public class Onf14DMDOMUtility {
 
  45     public static final Logger LOG = LoggerFactory.getLogger(Onf14DMDOMUtility.class);
 
  47     private Onf14DMDOMUtility() {}
 
  49     public static String getLeafValue(DataContainerNode componentEntry, QName leafQName) {
 
  50         NodeIdentifier leafNodeIdentifier = new NodeIdentifier(leafQName);
 
  52             LeafNode<?> optLeafNode = (LeafNode<?>) componentEntry.getChildByArg(leafNodeIdentifier);
 
  53             if (optLeafNode.body() instanceof QName) {
 
  54                 LOG.debug("Leaf is of type QName"); // Ex:
 
  55                                                     // ImmutableLeafNode{identifier=(urn:onf:yang:air-interface-2-0?revision=2020-01-21)severity,
 
  56                                                     // body=(urn:onf:yang:air-interface-2-0?revision=2020-01-21)SEVERITY_TYPE_MAJOR}
 
  57                 String severity_ = optLeafNode.body().toString();
 
  58                 return severity_.substring(severity_.indexOf(')') + 1); // Any other solution??
 
  60             return optLeafNode.body().toString();
 
  61         } catch (VerifyException ve) {
 
  62             LOG.debug("Leaf with QName {} not found", leafQName);
 
  67     public static List<String> getLeafListValue(DataContainerNode componentEntry, QName leafListQName) {
 
  68         List<String> containsChildList = new ArrayList<>();
 
  70             DataContainerChild childSet = componentEntry.getChildByArg(new NodeIdentifier(leafListQName));
 
  71             Collection<?> childEntry = (Collection<?>) childSet.body();
 
  72             Iterator<?> childEntryItr = childEntry.iterator();
 
  73             while (childEntryItr.hasNext()) {
 
  74                 LeafSetEntryNode<?> childEntryNode = (LeafSetEntryNode<?>) childEntryItr.next();
 
  75                 containsChildList.add(childEntryNode.body().toString());
 
  77         } catch (VerifyException ve) {
 
  78             LOG.debug("Child for {} does not exist", leafListQName);
 
  80         return containsChildList;
 
  83     public static String getUuidFromEquipment(MapEntryNode equipment) {
 
  84         LOG.debug("Equipment Identifier is {}", equipment.getIdentifier());
 
  85         NodeIdentifierWithPredicates componentKey = equipment.getIdentifier(); // list key
 
  86         LOG.debug("Key Name is - {}", componentKey.keySet());
 
  87         LOG.debug("Key Value is - {}",
 
  88                 componentKey.getValue(Onf14DevicemanagerQNames.CORE_MODEL_CC_EQPT_GLOBAL_CLASS_UUID));
 
  90         return componentKey.getValue(Onf14DevicemanagerQNames.CORE_MODEL_CC_EQPT_GLOBAL_CLASS_UUID).toString();
 
  93     public static Instant getNotificationInstant(DOMNotification notification) {
 
  94         if (notification instanceof DOMEvent) {
 
  95             return ((DOMEvent) notification).getEventInstant();