2 * Copyright © 2017 Orange, Inc. and others. All rights reserved.
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
8 package org.opendaylight.transportpce.servicehandler.validation.checks;
10 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.ConnectionType;
11 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.RpcActions;
12 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.sdnc.request.header.SdncRequestHeader;
15 * Class for checking service sdnc-request-header compliance.
18 public final class ServicehandlerComplianceCheck {
20 // This is class is public so that these messages can be accessed from Junit (avoid duplications).
21 public static final class LogMessages {
23 public static final String SERVICENAME_NOT_SET;
24 public static final String CONNECTIONTYPE_NOT_SET;
25 public static final String REQUESTID_NOT_SET;
26 public static final String RPCACTION_NOT_SET;
27 public static final String HEADER_NOT_SET;
29 // Static blocks are generated once and spare memory.
31 SERVICENAME_NOT_SET = "Service Name (common-id for Temp service) is not set";
32 CONNECTIONTYPE_NOT_SET = "Service ConnectionType is not set";
33 REQUESTID_NOT_SET = "Service sdncRequestHeader 'request-id' is not set";
34 RPCACTION_NOT_SET = "Service sdncRequestHeader 'rpc-action' is not set";
35 HEADER_NOT_SET = "Service sdncRequestHeader is not set";
38 public static String rpcactionsDiffers(RpcActions action1, RpcActions action2) {
40 "Service sdncRequestHeader rpc-action '" + action1.name() + "' not equal to '" + action2.name() + "'";
43 private LogMessages() {
48 * Check if a String is not null and not equal to void.
52 * @return true if String ok false if not
54 public static boolean checkString(String value) {
55 return ((value != null) && (!value.isEmpty()));
59 * Check Compliance of Service request.
63 * @param sdncRequestHeader
70 * Boolean to check connection Type
72 * Boolean to check sdncRequestHeader
74 * @return true if Service Request OK and false if not
76 public static ComplianceCheckResult check(String serviceName, SdncRequestHeader sdncRequestHeader,
77 ConnectionType conType, RpcActions action,
78 Boolean contype, Boolean sdncRequest) {
79 if (!checkString(serviceName)) {
80 return new ComplianceCheckResult(false, LogMessages.SERVICENAME_NOT_SET);
82 if (contype && (conType == null)) {
83 return new ComplianceCheckResult(false, LogMessages.CONNECTIONTYPE_NOT_SET);
86 if (sdncRequestHeader == null) {
87 return new ComplianceCheckResult(false, LogMessages.HEADER_NOT_SET);
89 RpcActions serviceAction = sdncRequestHeader.getRpcAction();
90 String requestId = sdncRequestHeader.getRequestId();
91 if (!checkString(requestId)) {
92 return new ComplianceCheckResult(false, LogMessages.REQUESTID_NOT_SET);
94 if (serviceAction == null) {
95 return new ComplianceCheckResult(false, LogMessages.RPCACTION_NOT_SET);
97 if (serviceAction.compareTo(action) != 0) {
98 return new ComplianceCheckResult(false, LogMessages.rpcactionsDiffers(serviceAction, action));
101 return new ComplianceCheckResult(true, "");
104 private ServicehandlerComplianceCheck() {