Stubpce Update
[transportpce.git] / tests / stubpce / src / main / java / org / opendaylight / transportpce / stubpce / CompliancyCheck.java
1 /*
2  * Copyright © 2017 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
9
10 package org.opendaylight.transportpce.stubpce;
11
12 import org.opendaylight.yang.gen.v1.http.org.transportpce.b.c._interface.servicepath.rev170426.PathComputationRequestInput;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16
17 /**
18  * Class to check RPCs Compliancy.
19  *
20  * @author Martial Coulibaly ( martial.coulibaly@gfi.com ) on behalf of Orange
21  *
22  */
23 public class CompliancyCheck {
24     /** Logging. */
25     private static final Logger LOG = LoggerFactory.getLogger(CompliancyCheck.class);
26     /** Response message from procedure. */
27     private String message;
28
29     private PathComputationRequestInput input;
30
31     public CompliancyCheck(PathComputationRequestInput prcInput) {
32         input = prcInput;
33     }
34
35     /**
36      * Check if a String is not
37      * null and not equal to ''.
38      *
39      * @param value String value
40      * @return  true  if String ok
41      *          false if not
42      */
43     public Boolean checkString(String value) {
44         Boolean result = false;
45         if ((value != null) && (value.compareTo("") != 0)) {
46             result = true;
47         }
48         return result;
49
50     }
51
52     /**
53      * check if service name
54      * or ServiceHandlerHeader
55      * is set in RPC request.
56      *
57      * @return true  if  settings is ok,
58      *          false if not
59      */
60     public Boolean check() {
61         Boolean result = true;
62         if (input != null) {
63             if (!checkString(input.getServiceName())) {
64                 result = false;
65                 message = "Service Name is not set";
66                 LOG.debug(message);
67             } else {
68                 if (!checkString(input.getServiceHandlerHeader().getRequestId())) {
69                     result = false;
70                     message = "ServiceHandlerHeader Request-ID  is not set";
71                     LOG.debug(message);
72                 }
73             }
74         } else {
75             result = false;
76         }
77         return result;
78     }
79
80     public String getMessage() {
81         return message;
82     }
83
84
85     public void setMessage(String message) {
86         this.message = message;
87     }
88
89 }