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.rev230526.ConnectionType;
11 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.RpcActions;
12 import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev230526.sdnc.request.header.SdncRequestHeader;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526.add.openroadm.operational.modes.to.catalog.input.OperationalModeInfo;
14 import org.slf4j.Logger;
15 import org.slf4j.LoggerFactory;
18 * Class for checking service sdnc-request-header compliance.
21 public final class ServicehandlerComplianceCheck {
23 private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerComplianceCheck.class);
25 // This is class is public so that these messages can be accessed from Junit (avoid duplications).
26 public static final class LogMessages {
28 public static final String SERVICENAME_NOT_SET;
29 public static final String CONNECTIONTYPE_NOT_SET;
30 public static final String REQUESTID_NOT_SET;
31 public static final String RPCACTION_NOT_SET;
32 public static final String HEADER_NOT_SET;
34 public static final String CATALOG_REQUESTID_NOT_SET;
35 public static final String CATALOG_HEADER_NOT_SET;
36 public static final String CATALOG_REQUESTSYSTEMID_NOT_SET;
37 public static final String CATALOG_RPCACTION_NOT_SET;
38 public static final String CATALOG_OPERATIONAL_MODE_INFO_NOT_SET;
40 // Static blocks are generated once and spare memory.
42 SERVICENAME_NOT_SET = "Service Name (common-id for Temp service) is not set";
43 CONNECTIONTYPE_NOT_SET = "Service ConnectionType is not set";
44 REQUESTID_NOT_SET = "Service sdncRequestHeader 'request-id' is not set";
45 RPCACTION_NOT_SET = "Service sdncRequestHeader 'rpc-action' is not set";
46 HEADER_NOT_SET = "Service sdncRequestHeader is not set";
47 CATALOG_REQUESTID_NOT_SET = "sdnc-request-header 'request-id' is not set";
48 CATALOG_REQUESTSYSTEMID_NOT_SET = "sdnc-request-header 'request-system-id' is not set";
49 CATALOG_HEADER_NOT_SET = "sdnc-request-header is not set";
50 CATALOG_RPCACTION_NOT_SET = "sdnc-request-header 'rpc-action' is not set";
51 CATALOG_OPERATIONAL_MODE_INFO_NOT_SET = "operational-mode-info is not set";
54 public static String rpcactionsDiffers(RpcActions action1, RpcActions action2) {
56 "Service sdncRequestHeader rpc-action '" + action1.name() + "' not equal to '" + action2.name() + "'";
59 public static String catalogRpcactionsDiffers(RpcActions action1, RpcActions action2) {
61 "Catalog sdnc-request-header rpc-action '" + action1.name() + "' not equal to '" + action2.name() + "'";
64 private LogMessages() {
69 * Check if a String is not null and not equal to void.
73 * @return true if String ok false if not
75 public static boolean checkString(String value) {
76 return value != null && !value.isEmpty();
80 * Check Compliance of Service request.
84 * @param sdncRequestHeader
91 * Boolean to check connection Type
93 * Boolean to check sdncRequestHeader
95 * @return true if Service Request OK and false if not
97 public static ComplianceCheckResult check(String serviceName, SdncRequestHeader sdncRequestHeader,
98 ConnectionType conType, RpcActions action,
99 Boolean contype, Boolean sdncRequest) {
100 if (!checkString(serviceName)) {
101 return new ComplianceCheckResult(false, LogMessages.SERVICENAME_NOT_SET);
103 if (contype && (conType == null)) {
104 return new ComplianceCheckResult(false, LogMessages.CONNECTIONTYPE_NOT_SET);
107 if (sdncRequestHeader == null) {
108 return new ComplianceCheckResult(false, LogMessages.HEADER_NOT_SET);
110 if (!checkString(sdncRequestHeader.getRequestId())) {
111 return new ComplianceCheckResult(false, LogMessages.REQUESTID_NOT_SET);
113 RpcActions serviceAction = sdncRequestHeader.getRpcAction();
114 if (serviceAction == null) {
115 return new ComplianceCheckResult(false, LogMessages.RPCACTION_NOT_SET);
117 if (serviceAction.compareTo(action) != 0) {
118 return new ComplianceCheckResult(false, LogMessages.rpcactionsDiffers(serviceAction, action));
121 return new ComplianceCheckResult(true, "");
124 public static ComplianceCheckResult checkORCatalog(SdncRequestHeader sdncRequestHeader,
125 OperationalModeInfo operationalModeInfo, RpcActions action,
126 Boolean sdncRequest) {
127 String resultMsg = sdncRequestHeaderValidate(sdncRequest, sdncRequestHeader, action).getMessage();
128 if (resultMsg.contains("sdnc-request-header")) {
129 return new ComplianceCheckResult(false, resultMsg);
131 if (operationalModeInfo == null) {
132 return new ComplianceCheckResult(false, LogMessages.CATALOG_OPERATIONAL_MODE_INFO_NOT_SET);
134 return new ComplianceCheckResult(true, "");
137 public static ComplianceCheckResult checkSpecificCatalog(SdncRequestHeader sdncRequestHeader,
138 org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev230526
139 .add.specific.operational.modes.to.catalog.input.OperationalModeInfo operationalModeInfoSpecific,
140 RpcActions action, Boolean sdncRequest) {
141 String resultMsg = sdncRequestHeaderValidate(sdncRequest, sdncRequestHeader, action).getMessage();
142 if (resultMsg.contains("sdnc-request-header")) {
143 return new ComplianceCheckResult(false,resultMsg);
145 if (operationalModeInfoSpecific == null) {
146 return new ComplianceCheckResult(false, LogMessages.CATALOG_OPERATIONAL_MODE_INFO_NOT_SET);
148 return new ComplianceCheckResult(true, "");
151 public static ComplianceCheckResult sdncRequestHeaderValidate(Boolean sdncRequest,
152 SdncRequestHeader sdncRequestHeader, RpcActions action) {
154 if (sdncRequestHeader == null) {
155 return new ComplianceCheckResult(false, LogMessages.CATALOG_HEADER_NOT_SET);
157 if (!checkString(sdncRequestHeader.getRequestId())) {
158 return new ComplianceCheckResult(false, LogMessages.CATALOG_REQUESTID_NOT_SET);
160 if (!checkString(sdncRequestHeader.getRequestSystemId())) {
161 return new ComplianceCheckResult(false, LogMessages.CATALOG_REQUESTSYSTEMID_NOT_SET);
163 RpcActions serviceAction = sdncRequestHeader.getRpcAction();
164 if (serviceAction == null) {
165 return new ComplianceCheckResult(false, LogMessages.CATALOG_RPCACTION_NOT_SET);
167 if (serviceAction.compareTo(action) != 0) {
168 return new ComplianceCheckResult(false, LogMessages.catalogRpcactionsDiffers(serviceAction, action));
171 return new ComplianceCheckResult(true, "");
174 private ServicehandlerComplianceCheck() {