fix 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 contype
39      *            Boolean to check connection Type
40      * @param sndcRequest
41      *            Boolean to check sndcRequestHeader
42      *
43      * @return true if String ok false if not
44      */
45     public static ComplianceCheckResult check(String serviceName, SdncRequestHeader sdncRequestHeader,
46                                        ConnectionType conType, RpcActions action,
47                                        Boolean contype, Boolean sndcRequest) {
48         boolean result = true;
49         String message = "";
50         if (!checkString(serviceName)) {
51             result = false;
52             message = "Service Name is not set";
53         } else if (contype && (conType == null)) {
54             result = false;
55             message = "Service ConnectionType is not set";
56         }
57         if (sndcRequest) {
58             if (sdncRequestHeader != null) {
59                 RpcActions serviceAction = sdncRequestHeader.getRpcAction();
60                 String requestId = sdncRequestHeader.getRequestId();
61                 if (!checkString(requestId)) {
62                     result = false;
63                     message = "Service sdncRequestHeader 'request-id' is not set";
64                     LOG.debug(message);
65                 } else if (serviceAction != null) {
66                     if (serviceAction.compareTo(action) != 0) {
67                         result = false;
68                         message = "Service sdncRequestHeader rpc-action '" + serviceAction + "' not equal to '"
69                                 + action.name() + "'";
70                     }
71                 } else {
72                     result = false;
73                     message = "Service sndc-request-header 'rpc-action' is not set ";
74                 }
75
76             } else {
77                 result = false;
78                 message = "Service sndc-request-header is not set ";
79             }
80         }
81         LOG.debug(message);
82         return new ComplianceCheckResult(result, message);
83     }
84
85     public ServicehandlerCompliancyCheck() {
86     }
87
88 }