Merge "Refactor ConvertORTopoToTapiTopoTest"
[transportpce.git] / pce / src / main / java / org / opendaylight / transportpce / pce / PceComplianceCheck.java
1 /*
2  * Copyright © 2017 AT&T 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.pce;
9
10 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev240205.PathComputationRequestInput;
11 import org.opendaylight.yang.gen.v1.http.org.opendaylight.transportpce.pce.rev240205.PathComputationRerouteRequestInput;
12 import org.slf4j.Logger;
13 import org.slf4j.LoggerFactory;
14
15 /*
16  * Class to check RPCs Compliancy.
17  */
18 public final class PceComplianceCheck {
19
20     private static final Logger LOG = LoggerFactory.getLogger(PceComplianceCheck.class);
21
22     private PceComplianceCheck() {
23     }
24
25     /*
26      * Check if a String is not null and not equal to ''.
27      *
28      * @param value String value
29      *
30      * @return  true  if String ok
31      *          false if not
32      */
33     public static boolean checkString(String value) {
34         return (value != null) && (value.compareTo("") != 0);
35     }
36
37     public static PceComplianceCheckResult check(PathComputationRequestInput input) {
38         String message = "";
39         Boolean result = true;
40         if (input != null) {
41             LOG.info("New request {} for new service {}",
42                     input.getServiceHandlerHeader().getRequestId(), input.getServiceName());
43             if (!checkString(input.getServiceName())) {
44                 result = false;
45                 message = "Service Name is not set";
46                 LOG.debug(message);
47             } else {
48                 if (!checkString(input.getServiceHandlerHeader().getRequestId())) {
49                     result = false;
50                     message = "ServiceHandlerHeader Request-ID  is not set";
51                     LOG.debug(message);
52                 }
53             }
54         } else {
55             result = false;
56         }
57         return new PceComplianceCheckResult(result, message);
58     }
59
60     public static PceComplianceCheckResult check(PathComputationRerouteRequestInput input) {
61         if (input == null) {
62             return new PceComplianceCheckResult(false, "");
63         }
64         if (input.getEndpoints() == null
65                 || input.getEndpoints().getAEndTp() == null
66                 || input.getEndpoints().getZEndTp() == null) {
67             String message = "At least one of the termination points is missing";
68             LOG.debug(message);
69             return new PceComplianceCheckResult(false, message);
70         }
71         return new PceComplianceCheckResult(true, "");
72     }
73
74 }