Migration to TAPI 2.4 Step1
[transportpce.git] / tapi / src / main / java / org / opendaylight / transportpce / tapi / validation / checks / TopoConstraintCheck.java
1 /*
2  * Copyright © 2018 Orange, Inc. and others.  All rights reserved.
3  *
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
7  */
8 package org.opendaylight.transportpce.tapi.validation.checks;
9
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;
14
15 public final class TopoConstraintCheck {
16
17     private static final Logger LOG = LoggerFactory.getLogger(TopoConstraintCheck.class);
18
19     private TopoConstraintCheck() {
20     }
21
22     public static boolean checkString(String value) {
23         return ((value != null) && (!value.isEmpty()));
24     }
25
26     public static ComplianceCheckResult check(TopologyConstraint topoConstraint) {
27         boolean result = true;
28         String message = "";
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)) {
34             result = false;
35             message = "Topology constraints are not managet yet";
36         }
37
38         return new ComplianceCheckResult(result, message);
39     }
40
41     private static boolean checkNull(TopologyConstraint tc) {
42         if (tc == null) {
43             return true;
44         }
45         if (tc.getExcludeTopology() == null) {
46             return true;
47         }
48         if (tc.getExcludeLink() == null) {
49             return true;
50         }
51         if (tc.getExcludeNode() == null) {
52             return true;
53         }
54         if (tc.getExcludePath() == null) {
55             return true;
56         }
57         if (tc.getIncludeLink() == null) {
58             return true;
59         }
60         if (tc.getIncludeNode() == null) {
61             return true;
62         }
63         if (tc.getIncludePath() == null) {
64             return true;
65         }
66         if (tc.getIncludeTopology() == null) {
67             return true;
68         }
69         return tc.getPreferredTransportLayer() == null;
70     }
71
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) {
75         if (tc == null) {
76             return true;
77         }
78         if (tc.getExcludeTopology() != null && tc.getExcludeTopology().isEmpty()) {
79             return true;
80         }
81         if (tc.getExcludeLink() != null && tc.getExcludeLink().isEmpty()) {
82             return true;
83         }
84         if (tc.getExcludeNode() != null && tc.getExcludeNode().isEmpty()) {
85             return true;
86         }
87         if (tc.getExcludePath() != null && tc.getExcludePath().isEmpty()) {
88             return true;
89         }
90         if (tc.getIncludeLink() != null && tc.getIncludeLink().isEmpty()) {
91             return true;
92         }
93         if (tc.getIncludeNode() != null && tc.getIncludeNode().isEmpty()) {
94             return true;
95         }
96         if (tc.getIncludePath() != null && tc.getIncludePath().isEmpty()) {
97             return true;
98         }
99         if (tc.getIncludeTopology() != null && tc.getIncludeTopology().isEmpty()) {
100             return true;
101         }
102         //TODO: check this changes : do not understand the rational of this class
103         return tc.getPreferredTransportLayer() != null && tc.getPreferredTransportLayer() == null;
104
105     }
106 }