Bump upstream dependencies to Ca
[transportpce.git] / networkmodel / src / main / java / org / opendaylight / transportpce / networkmodel / listeners / DeviceListener121.java
index d8aa5ed64678754bde11a1f55e8b5de501774aa0..6223854326e890d1b09167648db86ae030faa29f 100644 (file)
@@ -8,55 +8,64 @@
 
 package org.opendaylight.transportpce.networkmodel.listeners;
 
-import java.util.Collection;
 import java.util.LinkedList;
+import java.util.Set;
+import org.opendaylight.mdsal.binding.api.NotificationService.CompositeListener;
 import org.opendaylight.transportpce.common.mapping.PortMapping;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210315.mapping.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev231221.mapping.Mapping;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.ChangeNotification;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OrgOpenroadmDeviceListener;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.OtdrScanResult;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.change.notification.Edit;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.pack.Ports;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev170206.circuit.packs.CircuitPacks;
+import org.opendaylight.yangtools.yang.binding.DataObjectStep;
 import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
-import org.opendaylight.yangtools.yang.binding.InstanceIdentifier.PathArgument;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-public class DeviceListener121 implements OrgOpenroadmDeviceListener {
+public class DeviceListener121 {
 
     private static final Logger LOG = LoggerFactory.getLogger(DeviceListener121.class);
     private final String nodeId;
     private final PortMapping portMapping;
 
     public DeviceListener121(String nodeId, PortMapping portMapping) {
+        super();
         this.nodeId = nodeId;
         this.portMapping = portMapping;
     }
 
+    public CompositeListener getCompositeListener() {
+        return new CompositeListener(Set.of(
+            new CompositeListener.Component<>(ChangeNotification.class, this::onChangeNotification),
+            new CompositeListener.Component<>(OtdrScanResult.class, this::onOtdrScanResult)
+        ));
+    }
+
     /**
      * Callback for change-notification.
      *
      * @param notification ChangeNotification object
      */
-    @Override
-    public void onChangeNotification(ChangeNotification notification) {
+
+    void onChangeNotification(ChangeNotification notification) {
         if (notification.getEdit() == null) {
             LOG.warn("unable to handle {} notificatin received - list of edit is null", ChangeNotification.QNAME);
             return;
         }
         for (Edit edit : notification.getEdit()) {
+            if (edit.getTarget() == null) {
+                continue;
+            }
             // 1. Detect the org-openroadm-device object modified
             switch (edit.getTarget().getTargetType().getSimpleName()) {
                 case "Ports":
-                    LinkedList<PathArgument> path = new LinkedList<>();
-                    path.addAll((Collection<? extends PathArgument>) edit.getTarget().getPathArguments());
-                    InstanceIdentifier<Ports> portIID = (InstanceIdentifier<Ports>) InstanceIdentifier
-                        .create(path);
+                    LinkedList<DataObjectStep<?>> path = new LinkedList<>();
+                    edit.getTarget().getPathArguments().forEach(p -> path.add(p));
+                    InstanceIdentifier<Ports> portIID = InstanceIdentifier.unsafeOf(path);
                     String portName = InstanceIdentifier.keyOf(portIID).getPortName();
                     path.removeLast();
-                    InstanceIdentifier<CircuitPacks> cpIID = (InstanceIdentifier<CircuitPacks>) InstanceIdentifier
-                        .create(path);
+                    InstanceIdentifier<CircuitPacks> cpIID = InstanceIdentifier.unsafeOf(path);
                     String cpName = InstanceIdentifier.keyOf(cpIID).getCircuitPackName();
                     LOG.info("port {} of circruit-pack {} modified on device {}", portName, cpName, this.nodeId);
                     Mapping oldMapping = portMapping.getMapping(nodeId, cpName, portName);
@@ -86,8 +95,7 @@ public class DeviceListener121 implements OrgOpenroadmDeviceListener {
      *
      * @param notification OtdrScanResult object
      */
-    @Override
-    public void onOtdrScanResult(OtdrScanResult notification) {
+    private void onOtdrScanResult(OtdrScanResult notification) {
         LOG.info("Notification {} received {}", OtdrScanResult.QNAME, notification);
     }