2 * Copyright © 2018 Orange, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.transportpce.tapi.validation.checks;
10 import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult;
11 import org.opendaylight.yang.gen.v1.urn.onf.otcc.yang.tapi.connectivity.rev221121.create.connectivity.service.input.TopologyConstraint;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
15 public final class TopoConstraintCheck {
17 private static final Logger LOG = LoggerFactory.getLogger(TopoConstraintCheck.class);
19 private TopoConstraintCheck() {
22 public static boolean checkString(String value) {
23 return ((value != null) && (!value.isEmpty()));
26 public static ComplianceCheckResult check(TopologyConstraint topoConstraint) {
27 boolean result = true;
29 LOG.info("tc = {}", topoConstraint);
30 if (checkNull(topoConstraint)) {
31 LOG.info("tc is null");
32 message = "Topology constraints are not managet yet";
33 } else if (checkEmpty(topoConstraint)) {
35 message = "Topology constraints are not managet yet";
38 return new ComplianceCheckResult(result, message);
41 private static boolean checkNull(TopologyConstraint tc) {
45 if (tc.getExcludeTopology() == null) {
48 if (tc.getExcludeLink() == null) {
51 if (tc.getExcludeNode() == null) {
54 if (tc.getExcludePath() == null) {
57 if (tc.getIncludeLink() == null) {
60 if (tc.getIncludeNode() == null) {
63 if (tc.getIncludePath() == null) {
66 if (tc.getIncludeTopology() == null) {
69 return tc.getPreferredTransportLayer() == null;
72 //Due to number of check to do, cyclomatic complexity cannot be easily improved
73 @java.lang.SuppressWarnings("squid:MethodCyclomaticComplexity")
74 private static boolean checkEmpty(TopologyConstraint tc) {
78 if (tc.getExcludeTopology() != null && tc.getExcludeTopology().isEmpty()) {
81 if (tc.getExcludeLink() != null && tc.getExcludeLink().isEmpty()) {
84 if (tc.getExcludeNode() != null && tc.getExcludeNode().isEmpty()) {
87 if (tc.getExcludePath() != null && tc.getExcludePath().isEmpty()) {
90 if (tc.getIncludeLink() != null && tc.getIncludeLink().isEmpty()) {
93 if (tc.getIncludeNode() != null && tc.getIncludeNode().isEmpty()) {
96 if (tc.getIncludePath() != null && tc.getIncludePath().isEmpty()) {
99 if (tc.getIncludeTopology() != null && tc.getIncludeTopology().isEmpty()) {
102 //TODO: check this changes : do not understand the rational of this class
103 return tc.getPreferredTransportLayer() != null && tc.getPreferredTransportLayer() == null;