X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=tapi%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Ftransportpce%2Ftapi%2Fvalidation%2Fchecks%2FTopoConstraintCheck.java;h=8a07469702b91dc9f2f8531e02c8b314dd7bced2;hb=bc50910144ee7979d24233a8b6e630a4495a91f2;hp=4edf07d57921c0adaafb727381097565fa132bcc;hpb=79d36087f574a27f0ead2ce9c0d0f69065160916;p=transportpce.git diff --git a/tapi/src/main/java/org/opendaylight/transportpce/tapi/validation/checks/TopoConstraintCheck.java b/tapi/src/main/java/org/opendaylight/transportpce/tapi/validation/checks/TopoConstraintCheck.java index 4edf07d57..8a0746970 100644 --- a/tapi/src/main/java/org/opendaylight/transportpce/tapi/validation/checks/TopoConstraintCheck.java +++ b/tapi/src/main/java/org/opendaylight/transportpce/tapi/validation/checks/TopoConstraintCheck.java @@ -20,29 +20,86 @@ public final class TopoConstraintCheck { } public static boolean checkString(String value) { - return ((value != null) && (value.compareTo("") != 0)); + return ((value != null) && (!value.isEmpty())); } public static ComplianceCheckResult check(TopologyConstraint tc) { boolean result = true; String message = ""; - LOG.info("tc = {}", tc.toString()); - if (tc.getAvoidTopology() == null || tc.getExcludeLink() == null || tc.getExcludeNode() == null || tc - .getExcludePath() == null || tc.getIncludeLink() == null || tc.getIncludeNode() == null || tc - .getIncludePath() == null || tc.getIncludeTopology() == null || tc - .getPreferredTransportLayer() == null) { + LOG.info("tc = {}", tc); + if (checkNull(tc)) { LOG.info("tc is null"); - result = true; message = "Topology constraints are not managet yet"; - } else if (tc.getAvoidTopology().isEmpty() || tc.getExcludeLink().isEmpty() || tc.getExcludeNode().isEmpty() - || tc - .getExcludePath().isEmpty() || tc.getIncludeLink().isEmpty() || tc.getIncludeNode().isEmpty() || tc - .getIncludePath().isEmpty() || tc.getIncludeTopology().isEmpty() || tc.getPreferredTransportLayer() - .isEmpty()) { + } else if (checkEmpty(tc)) { result = false; message = "Topology constraints are not managet yet"; } return new ComplianceCheckResult(result, message); } + + private static boolean checkNull(TopologyConstraint tc) { + if (tc == null) { + return true; + } + if (tc.getAvoidTopology() == null) { + return true; + } + if (tc.getExcludeLink() == null) { + return true; + } + if (tc.getExcludeNode() == null) { + return true; + } + if (tc.getExcludePath() == null) { + return true; + } + if (tc.getIncludeLink() == null) { + return true; + } + if (tc.getIncludeNode() == null) { + return true; + } + if (tc.getIncludePath() == null) { + return true; + } + if (tc.getIncludeTopology() == null) { + return true; + } + return tc.getPreferredTransportLayer() == null; + } + + //Due to number of check to do, cyclomatic complexity cannot be easily improved + @java.lang.SuppressWarnings("squid:MethodCyclomaticComplexity") + private static boolean checkEmpty(TopologyConstraint tc) { + if (tc == null) { + return true; + } + if (tc.getAvoidTopology() != null && tc.getAvoidTopology().isEmpty()) { + return true; + } + if (tc.getExcludeLink() != null && tc.getExcludeLink().isEmpty()) { + return true; + } + if (tc.getExcludeNode() != null && tc.getExcludeNode().isEmpty()) { + return true; + } + if (tc.getExcludePath() != null && tc.getExcludePath().isEmpty()) { + return true; + } + if (tc.getIncludeLink() != null && tc.getIncludeLink().isEmpty()) { + return true; + } + if (tc.getIncludeNode() != null && tc.getIncludeNode().isEmpty()) { + return true; + } + if (tc.getIncludePath() != null && tc.getIncludePath().isEmpty()) { + return true; + } + if (tc.getIncludeTopology() != null && tc.getIncludeTopology().isEmpty()) { + return true; + } + return tc.getPreferredTransportLayer() != null && tc.getPreferredTransportLayer().isEmpty(); + + } }