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;
13 import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.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()
65 private LogMessages() {
70 * Check if a String is not null and not equal to void.
74 * @return true if String ok false if not
76 public static boolean checkString(String value) {
77 return ((value != null) && (!value.isEmpty()));
81 * Check Compliance of Service request.
85 * @param sdncRequestHeader
92 * Boolean to check connection Type
94 * Boolean to check sdncRequestHeader
96 * @return true if Service Request OK and false if not
98 public static ComplianceCheckResult check(String serviceName, SdncRequestHeader sdncRequestHeader,
99 ConnectionType conType, RpcActions action,
100 Boolean contype, Boolean sdncRequest) {
101 if (!checkString(serviceName)) {
102 return new ComplianceCheckResult(false, LogMessages.SERVICENAME_NOT_SET);
104 if (contype && (conType == null)) {
105 return new ComplianceCheckResult(false, LogMessages.CONNECTIONTYPE_NOT_SET);
108 if (sdncRequestHeader == null) {
109 return new ComplianceCheckResult(false, LogMessages.HEADER_NOT_SET);
111 RpcActions serviceAction = sdncRequestHeader.getRpcAction();
112 String requestId = sdncRequestHeader.getRequestId();
113 if (!checkString(requestId)) {
114 return new ComplianceCheckResult(false, LogMessages.REQUESTID_NOT_SET);
116 if (serviceAction == null) {
117 return new ComplianceCheckResult(false, LogMessages.RPCACTION_NOT_SET);
119 if (serviceAction.compareTo(action) != 0) {
120 return new ComplianceCheckResult(false, LogMessages.rpcactionsDiffers(serviceAction, action));
123 return new ComplianceCheckResult(true, "");
126 public static ComplianceCheckResult checkORCatalog(SdncRequestHeader sdncRequestHeader,
127 OperationalModeInfo operationalModeInfo, RpcActions action,
128 Boolean sdncRequest) {
130 ComplianceCheckResult result = sdncRequestHeaderValidate(sdncRequest, sdncRequestHeader, action);
131 if (result.getMessage().contains("sdnc-request-header")) {
132 return new ComplianceCheckResult(false,result.getMessage());
134 if (operationalModeInfo == null) {
135 return new ComplianceCheckResult(false, LogMessages.CATALOG_OPERATIONAL_MODE_INFO_NOT_SET);
138 return new ComplianceCheckResult(true, "");
141 public static ComplianceCheckResult checkSpecificCatalog(SdncRequestHeader sdncRequestHeader, org.opendaylight.yang
142 .gen.v1.http.org.openroadm.service.rev211210.add.specific.operational.modes.to.catalog.input
143 .OperationalModeInfo operationalModeInfoSpecific, RpcActions action, Boolean sdncRequest) {
145 ComplianceCheckResult result = sdncRequestHeaderValidate(sdncRequest, sdncRequestHeader, action);
146 if (result.getMessage().contains("sdnc-request-header")) {
147 return new ComplianceCheckResult(false,result.getMessage());
149 if (operationalModeInfoSpecific == null) {
150 return new ComplianceCheckResult(false, LogMessages.CATALOG_OPERATIONAL_MODE_INFO_NOT_SET);
152 return new ComplianceCheckResult(true, "");
155 public static ComplianceCheckResult sdncRequestHeaderValidate(Boolean sdncRequest, SdncRequestHeader
156 sdncRequestHeader, RpcActions action) {
158 if (sdncRequestHeader == null) {
159 return new ComplianceCheckResult(false, LogMessages.CATALOG_HEADER_NOT_SET);
161 RpcActions serviceAction = sdncRequestHeader.getRpcAction();
162 String requestId = sdncRequestHeader.getRequestId();
163 String requestSystemId = sdncRequestHeader.getRequestSystemId();
164 if (!checkString(requestId)) {
165 return new ComplianceCheckResult(false, LogMessages.CATALOG_REQUESTID_NOT_SET);
167 if (!checkString(requestSystemId)) {
168 return new ComplianceCheckResult(false, LogMessages.CATALOG_REQUESTSYSTEMID_NOT_SET);
170 if (serviceAction == null) {
171 return new ComplianceCheckResult(false, LogMessages.CATALOG_RPCACTION_NOT_SET);
173 if (serviceAction.compareTo(action) != 0) {
174 return new ComplianceCheckResult(false, LogMessages.catalogRpcactionsDiffers(serviceAction, action));
177 return new ComplianceCheckResult(true, "");
181 private ServicehandlerComplianceCheck() {