clean some compilation warnings
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / validation / checks / ServicehandlerCompliancyCheck.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 package org.opendaylight.transportpce.servicehandler.validation.checks;
9
10 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ConnectionType;
11 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.RpcActions;
12 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeader;
13 import org.slf4j.Logger;
14 import org.slf4j.LoggerFactory;
15
16 /**
17  * Class for checking service sdnc-request-header compliancy.
18  *
19  */
20 public final class ServicehandlerCompliancyCheck {
21
22     private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerCompliancyCheck.class);
23
24     /**
25      * Check if a String is not null and not equal to void.
26      *
27      * @param value
28      *            String value
29      * @return true if String ok false if not
30      */
31     public static boolean checkString(String value) {
32         return ((value != null) && (value.compareTo("") != 0));
33     }
34
35     /**
36      * Check Compliancy of Service request.
37      *
38      * @param serviceName
39      *            Service Name
40      * @param sdncRequestHeader
41      *            sdncRequestHeader
42      * @param conType
43      *            Connection type
44      * @param action
45      *            RPC Actions
46      * @param contype
47      *            Boolean to check connection Type
48      * @param sdncRequest
49      *            Boolean to check sdncRequestHeader
50      *
51      * @return true if String ok false if not
52      */
53     public static ComplianceCheckResult check(String serviceName, SdncRequestHeader sdncRequestHeader,
54                                        ConnectionType conType, RpcActions action,
55                                        Boolean contype, Boolean sdncRequest) {
56         boolean result = true;
57         String message = "";
58         if (!checkString(serviceName)) {
59             result = false;
60             message = "Service Name is not set";
61         } else if (contype && (conType == null)) {
62             result = false;
63             message = "Service ConnectionType is not set";
64         }
65         if (sdncRequest) {
66             if (sdncRequestHeader != null) {
67                 RpcActions serviceAction = sdncRequestHeader.getRpcAction();
68                 String requestId = sdncRequestHeader.getRequestId();
69                 if (!checkString(requestId)) {
70                     result = false;
71                     message = "Service sdncRequestHeader 'request-id' is not set";
72                     LOG.debug(message);
73                 } else if (serviceAction != null) {
74                     if (serviceAction.compareTo(action) != 0) {
75                         result = false;
76                         message = "Service sdncRequestHeader rpc-action '" + serviceAction + "' not equal to '"
77                                 + action.name() + "'";
78                     }
79                 } else {
80                     result = false;
81                     message = "Service sndc-request-header 'rpc-action' is not set ";
82                 }
83
84             } else {
85                 result = false;
86                 message = "Service sndc-request-header is not set ";
87             }
88         }
89         LOG.debug(message);
90         return new ComplianceCheckResult(result, message);
91     }
92
93     private ServicehandlerCompliancyCheck() {
94     }
95
96 }