Adapt TransportPCE code to Sulfur
[transportpce.git] / networkmodel / src / main / java / org / opendaylight / transportpce / networkmodel / listeners / DeviceListener221.java
index 9af7cfe3d94721420f88b622cc637f27da3de8c2..66e3704875669526c9728c74e4189b9f2b592fe1 100644 (file)
@@ -8,10 +8,9 @@
 
 package org.opendaylight.transportpce.networkmodel.listeners;
 
-import java.util.Collection;
 import java.util.LinkedList;
 import org.opendaylight.transportpce.common.mapping.PortMapping;
-import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev210310.network.nodes.Mapping;
+import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.portmapping.rev220316.mapping.Mapping;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.ChangeNotification;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.CreateTechInfoNotification;
 import org.opendaylight.yang.gen.v1.http.org.openroadm.device.rev181019.OrgOpenroadmDeviceListener;
@@ -31,6 +30,7 @@ public class DeviceListener221 implements OrgOpenroadmDeviceListener {
     private final PortMapping portMapping;
 
     public DeviceListener221(String nodeId, PortMapping portMapping) {
+        super();
         this.nodeId = nodeId;
         this.portMapping = portMapping;
     }
@@ -48,17 +48,18 @@ public class DeviceListener221 implements OrgOpenroadmDeviceListener {
             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);
+                    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);