Modify spectrum assignment management in PCE
[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.rev210701.PathComputationRequestInput;
11 import org.slf4j.Logger;
12 import org.slf4j.LoggerFactory;
13
14 /*
15  * Class to check RPCs Compliancy.
16  */
17 public final class PceComplianceCheck {
18
19     private static final Logger LOG = LoggerFactory.getLogger(PceComplianceCheck.class);
20
21     private PceComplianceCheck() {
22     }
23
24     /*
25      * Check if a String is not null and not equal to ''.
26      *
27      * @param value String value
28      *
29      * @return  true  if String ok
30      *          false if not
31      */
32     public static boolean checkString(String value) {
33         return (value != null) && (value.compareTo("") != 0);
34     }
35
36     public static PceComplianceCheckResult check(PathComputationRequestInput input) {
37         String message = "";
38         Boolean result = true;
39         if (input != null) {
40             LOG.info("New request {} for new service {}",
41                     input.getServiceHandlerHeader().getRequestId(), input.getServiceName());
42             if (!checkString(input.getServiceName())) {
43                 result = false;
44                 message = "Service Name is not set";
45                 LOG.debug(message);
46             } else {
47                 if (!checkString(input.getServiceHandlerHeader().getRequestId())) {
48                     result = false;
49                     message = "ServiceHandlerHeader Request-ID  is not set";
50                     LOG.debug(message);
51                 }
52             }
53         } else {
54             result = false;
55         }
56         return new PceComplianceCheckResult(result, message);
57     }
58
59 }