Refactor PCE networkanalyzer PceCalculation 61/100061/8
authorguillaume.lambert <guillaume.lambert@orange.com>
Thu, 10 Mar 2022 20:30:15 +0000 (21:30 +0100)
committerguillaume.lambert <guillaume.lambert@orange.com>
Tue, 22 Mar 2022 12:57:46 +0000 (13:57 +0100)
JIRA: TRNSPRTPCE-643
Signed-off-by: guillaume.lambert <guillaume.lambert@orange.com>
Change-Id: I83ec5e58c2690e66e6a65190f8770112a524d1d8

pce/src/main/java/org/opendaylight/transportpce/pce/networkanalyzer/PceCalculation.java

index 4b6dcc91e6cba2f96b488f522463ff04db360800..d046646811a5de677c5c77dba8d4a07b080e38e2 100644 (file)
@@ -8,6 +8,7 @@
 
 package org.opendaylight.transportpce.pce.networkanalyzer;
 
+import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
 import java.math.BigDecimal;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -137,12 +138,13 @@ public class PceCalculation {
         serviceFormatA = input.getServiceAEnd().getServiceFormat().getName();
         serviceFormatZ = input.getServiceZEnd().getServiceFormat().getName();
         serviceRate = input.getServiceAEnd().getServiceRate();
-        serviceType = ServiceTypes.getServiceType(serviceFormatA, serviceRate,
-            (NodeTypes.Xpdr.equals(portMapping.getNode(input.getServiceAEnd().getNodeId()).getNodeInfo().getNodeType())
-            && input.getServiceAEnd().getTxDirection() != null
-            && input.getServiceAEnd().getTxDirection().getPort() != null
-            && input.getServiceAEnd().getTxDirection().getPort().getPortName() != null)
-                ? portMapping.getMapping(input.getServiceAEnd().getNodeId(),
+        serviceType = ServiceTypes.getServiceType(
+            serviceFormatA,
+            serviceRate,
+            NodeTypes.Xpdr.equals(portMapping.getNode(input.getServiceAEnd().getNodeId()).getNodeInfo().getNodeType())
+                    && checkAendInputTxPortName()
+                ? portMapping.getMapping(
+                    input.getServiceAEnd().getNodeId(),
                     input.getServiceAEnd().getTxDirection().getPort().getPortName())
                 : null);
 
@@ -155,23 +157,38 @@ public class PceCalculation {
         return true;
     }
 
+    private boolean checkAendInputTxPortName() {
+        return checkAendInputTxPort()
+            && input.getServiceAEnd().getTxDirection().getPort().getPortName() != null;
+    }
+
+    private boolean checkAendInputTxPortDeviceName() {
+        return checkAendInputTxPort()
+            && input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName() != null;
+    }
+
+    private boolean checkAendInputTxPort() {
+        return input.getServiceAEnd() != null
+            && input.getServiceAEnd().getTxDirection() != null
+            && input.getServiceAEnd().getTxDirection().getPort() != null;
+    }
+
+    private boolean checkZendInputTxPortDeviceName() {
+        return input.getServiceZEnd() != null
+            && input.getServiceZEnd().getTxDirection() != null
+            && input.getServiceZEnd().getTxDirection().getPort() != null
+            && input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName() != null;
+    }
+
     private void getAZnodeId() {
-        if (input.getServiceAEnd() != null
-                && input.getServiceAEnd().getTxDirection() != null
-                && input.getServiceAEnd().getTxDirection().getPort() != null
-                && input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName() != null) {
-            anodeId = input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName();
-        } else {
-            anodeId = input.getServiceAEnd().getNodeId();
-        }
-        if (input.getServiceZEnd() != null
-                && input.getServiceZEnd().getTxDirection() != null
-                && input.getServiceZEnd().getTxDirection().getPort() != null
-                && input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName() != null) {
-            znodeId = input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName();
-        } else {
-            znodeId = input.getServiceZEnd().getNodeId();
-        }
+        anodeId =
+            checkAendInputTxPortDeviceName()
+                ? input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName()
+                : input.getServiceAEnd().getNodeId();
+        znodeId =
+            checkZendInputTxPortDeviceName()
+                ? input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName()
+                : input.getServiceZEnd().getNodeId();
     }
 
     private boolean readMdSal() {
@@ -475,6 +492,10 @@ public class PceCalculation {
         return;
     }
 
+    @SuppressWarnings("fallthrough")
+    @SuppressFBWarnings(
+        value = "SF_SWITCH_FALLTHROUGH",
+        justification = "intentional fallthrough")
     private boolean isAZendPceNode(String serviceFormat, PceOpticalNode pceNode, String azNodeId, String azEndPoint) {
         switch (serviceFormat) {
             case "Ethernet":
@@ -482,33 +503,20 @@ public class PceCalculation {
                 if (pceNode.getSupNetworkNodeId().equals(azNodeId)) {
                     return true;
                 }
-                if ("A".equals(azEndPoint)
-                        && this.input.getServiceAEnd().getTxDirection() != null
-                        && this.input.getServiceAEnd().getTxDirection().getPort() != null
-                        && this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName() != null
-                        && pceNode.getNodeId().getValue()
-                        .equals(this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName())) {
-                    return true;
-                }
-                if ("Z".equals(azEndPoint)
-                        && this.input.getServiceZEnd().getTxDirection() != null
-                        && this.input.getServiceZEnd().getTxDirection().getPort() != null
-                        && this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName() != null
-                        && pceNode.getNodeId().getValue()
-                        .equals(this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName())) {
-                    return true;
-                }
-                return false;
+            //fallthrough
             case "OTU":
-                if ("A".equals(azEndPoint) && pceNode.getNodeId().getValue()
-                        .equals(this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName())) {
-                    return true;
-                }
-                if ("Z".equals(azEndPoint) && pceNode.getNodeId().getValue()
-                        .equals(this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName())) {
-                    return true;
+                switch (azEndPoint) {
+                    case "A":
+                        return checkAendInputTxPortDeviceName()
+                            && pceNode.getNodeId().getValue()
+                                .equals(this.input.getServiceAEnd().getTxDirection().getPort().getPortDeviceName());
+                    case "Z":
+                        return checkZendInputTxPortDeviceName()
+                            && pceNode.getNodeId().getValue()
+                                .equals(this.input.getServiceZEnd().getTxDirection().getPort().getPortDeviceName());
+                    default:
+                        return false;
                 }
-                return false;
             default:
                 LOG.debug("Unsupported service Format {} for node {}", serviceFormat, pceNode.getNodeId().getValue());
                 return false;
@@ -780,7 +788,7 @@ public class PceCalculation {
         String moduleName = params[params.length - 1];
         for (McCapabilities mcCapabitility : mcCapabilities) {
             if (mcCapabitility.getMcNodeName().contains("XPDR")
-                && mcCapabitility.getSlotWidthGranularity() != null) {
+                    && mcCapabitility.getSlotWidthGranularity() != null) {
                 return mcCapabitility.getSlotWidthGranularity().getValue();
             }
             if (mcCapabitility.getMcNodeName().contains(moduleName)
@@ -806,11 +814,11 @@ public class PceCalculation {
         String moduleName = params[params.length - 1];
         for (McCapabilities mcCapabitility : mcCapabilities) {
             if (mcCapabitility.getMcNodeName().contains("XPDR")
-                && mcCapabitility.getCenterFreqGranularity() != null) {
+                    && mcCapabitility.getCenterFreqGranularity() != null) {
                 return mcCapabitility.getCenterFreqGranularity().getValue();
             }
             if (mcCapabitility.getMcNodeName().contains(moduleName)
-                && mcCapabitility.getCenterFreqGranularity() != null) {
+                    && mcCapabitility.getCenterFreqGranularity() != null) {
                 return mcCapabitility.getCenterFreqGranularity().getValue();
             }
         }