Catalog RPC Implementation
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / validation / checks / ServicehandlerComplianceCheck.java
index 85b8a1d08c9ffef2d029bf27278c308618306ea6..f59a3e7d64cddd8357c3a024d6ed810611f5c725 100644 (file)
@@ -10,6 +10,9 @@ package org.opendaylight.transportpce.servicehandler.validation.checks;
 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.
@@ -17,6 +20,8 @@ import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev2
  */
 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 {
 
@@ -26,6 +31,12 @@ public final class ServicehandlerComplianceCheck {
         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";
@@ -33,6 +44,11 @@ public final class ServicehandlerComplianceCheck {
             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) {
@@ -40,6 +56,12 @@ public final class ServicehandlerComplianceCheck {
                 "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() {
         }
     }
@@ -101,6 +123,61 @@ public final class ServicehandlerComplianceCheck {
         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() {
     }