import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.ConnectionType;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.RpcActions;
import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev211210.sdnc.request.header.SdncRequestHeader;
+import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev211210.add.openroadm.operational.modes.to.catalog.input.OperationalModeInfo;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
/**
* Class for checking service sdnc-request-header compliance.
*/
public final class ServicehandlerComplianceCheck {
+ private static final Logger LOG = LoggerFactory.getLogger(ServicehandlerComplianceCheck.class);
+
// This is class is public so that these messages can be accessed from Junit (avoid duplications).
public static final class LogMessages {
public static final String RPCACTION_NOT_SET;
public static final String HEADER_NOT_SET;
+ public static final String CATALOG_REQUESTID_NOT_SET;
+ public static final String CATALOG_HEADER_NOT_SET;
+ public static final String CATALOG_REQUESTSYSTEMID_NOT_SET;
+ public static final String CATALOG_RPCACTION_NOT_SET;
+ public static final String CATALOG_OPERATIONAL_MODE_INFO_NOT_SET;
+
// Static blocks are generated once and spare memory.
static {
SERVICENAME_NOT_SET = "Service Name (common-id for Temp service) is not set";
REQUESTID_NOT_SET = "Service sdncRequestHeader 'request-id' is not set";
RPCACTION_NOT_SET = "Service sdncRequestHeader 'rpc-action' is not set";
HEADER_NOT_SET = "Service sdncRequestHeader is not set";
+ CATALOG_REQUESTID_NOT_SET = "sdnc-request-header 'request-id' is not set";
+ CATALOG_REQUESTSYSTEMID_NOT_SET = "sdnc-request-header 'request-system-id' is not set";
+ CATALOG_HEADER_NOT_SET = "sdnc-request-header is not set";
+ CATALOG_RPCACTION_NOT_SET = "sdnc-request-header 'rpc-action' is not set";
+ CATALOG_OPERATIONAL_MODE_INFO_NOT_SET = "operational-mode-info is not set";
}
public static String rpcactionsDiffers(RpcActions action1, RpcActions action2) {
"Service sdncRequestHeader rpc-action '" + action1.name() + "' not equal to '" + action2.name() + "'";
}
+ public static String catalogRpcactionsDiffers(RpcActions action1, RpcActions action2) {
+ return
+ "Catalog sdnc-request-header rpc-action '" + action1.name() + "' not equal to '" + action2.name()
+ + "'";
+ }
+
private LogMessages() {
}
}
return new ComplianceCheckResult(true, "");
}
+ public static ComplianceCheckResult checkORCatalog(SdncRequestHeader sdncRequestHeader,
+ OperationalModeInfo operationalModeInfo, RpcActions action,
+ Boolean sdncRequest) {
+
+ ComplianceCheckResult result = sdncRequestHeaderValidate(sdncRequest, sdncRequestHeader, action);
+ if (result.getMessage().contains("sdnc-request-header")) {
+ return new ComplianceCheckResult(false,result.getMessage());
+ }
+ if (operationalModeInfo == null) {
+ return new ComplianceCheckResult(false, LogMessages.CATALOG_OPERATIONAL_MODE_INFO_NOT_SET);
+ }
+
+ return new ComplianceCheckResult(true, "");
+ }
+
+ public static ComplianceCheckResult checkSpecificCatalog(SdncRequestHeader sdncRequestHeader, org.opendaylight.yang
+ .gen.v1.http.org.openroadm.service.rev211210.add.specific.operational.modes.to.catalog.input
+ .OperationalModeInfo operationalModeInfoSpecific, RpcActions action, Boolean sdncRequest) {
+
+ ComplianceCheckResult result = sdncRequestHeaderValidate(sdncRequest, sdncRequestHeader, action);
+ if (result.getMessage().contains("sdnc-request-header")) {
+ return new ComplianceCheckResult(false,result.getMessage());
+ }
+ if (operationalModeInfoSpecific == null) {
+ return new ComplianceCheckResult(false, LogMessages.CATALOG_OPERATIONAL_MODE_INFO_NOT_SET);
+ }
+ return new ComplianceCheckResult(true, "");
+ }
+
+ public static ComplianceCheckResult sdncRequestHeaderValidate(Boolean sdncRequest, SdncRequestHeader
+ sdncRequestHeader, RpcActions action) {
+ if (sdncRequest) {
+ if (sdncRequestHeader == null) {
+ return new ComplianceCheckResult(false, LogMessages.CATALOG_HEADER_NOT_SET);
+ }
+ RpcActions serviceAction = sdncRequestHeader.getRpcAction();
+ String requestId = sdncRequestHeader.getRequestId();
+ String requestSystemId = sdncRequestHeader.getRequestSystemId();
+ if (!checkString(requestId)) {
+ return new ComplianceCheckResult(false, LogMessages.CATALOG_REQUESTID_NOT_SET);
+ }
+ if (!checkString(requestSystemId)) {
+ return new ComplianceCheckResult(false, LogMessages.CATALOG_REQUESTSYSTEMID_NOT_SET);
+ }
+ if (serviceAction == null) {
+ return new ComplianceCheckResult(false, LogMessages.CATALOG_RPCACTION_NOT_SET);
+ }
+ if (serviceAction.compareTo(action) != 0) {
+ return new ComplianceCheckResult(false, LogMessages.catalogRpcactionsDiffers(serviceAction, action));
+ }
+ }
+ return new ComplianceCheckResult(true, "");
+ }
+
+
private ServicehandlerComplianceCheck() {
}