Fix few code issues
[transportpce.git] / servicehandler / src / main / java / org / opendaylight / transportpce / servicehandler / validation / ServiceCreateValidation.java
index 6d962aea0dcfdaa0ff12044ef150739cd985cfce..93f80eca1ae333ba1a440e6aacb2a4d01e36de39 100644 (file)
@@ -10,82 +10,77 @@ package org.opendaylight.transportpce.servicehandler.validation;
 
 import org.opendaylight.transportpce.common.OperationResult;
 import org.opendaylight.transportpce.servicehandler.ServiceEndpointType;
+import org.opendaylight.transportpce.servicehandler.ServiceInput;
 import org.opendaylight.transportpce.servicehandler.validation.checks.CheckCoherencyHardSoft;
 import org.opendaylight.transportpce.servicehandler.validation.checks.ComplianceCheckResult;
-import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerCompliancyCheck;
+import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerComplianceCheck;
 import org.opendaylight.transportpce.servicehandler.validation.checks.ServicehandlerTxRxCheck;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.ConnectionType;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.RpcActions;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.common.service.types.rev161014.sdnc.request.header.SdncRequestHeader;
-import org.opendaylight.yang.gen.v1.http.org.openroadm.service.rev161014.ServiceCreateInput;
+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.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class ServiceCreateValidation {
     private static final Logger LOG = LoggerFactory.getLogger(ServiceCreateValidation.class);
 
-    public static OperationResult validateServiceCreateRequest(ServiceCreateInput input) {
+    public static OperationResult validateServiceCreateRequest(ServiceInput input, RpcActions rpcActions) {
         /*
          * Upon receipt of service
          * -create RPC, service header and sdnc
          * -request header compliancy are verified.
          */
-        LOG.debug("checking Service Compliancy ...");
-        try {
-            String serviceNmame = input.getServiceName();
-            SdncRequestHeader sdncRequestHeader = input.getSdncRequestHeader();
-            ConnectionType conType = input.getConnectionType();
-            ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerCompliancyCheck.check(
-                    serviceNmame, sdncRequestHeader, conType, RpcActions.ServiceCreate, true, true);
-            if (serviceHandlerCheckResult.hasPassed()) {
-                LOG.debug("Service request compliant !");
-            } else {
-                return OperationResult.failed(serviceHandlerCheckResult.getMessage());
-            }
+        LOG.debug("checking Service Compliance ...");
+        String serviceNmame = input.getServiceName();
+        SdncRequestHeader sdncRequestHeader = input.getSdncRequestHeader();
+        ConnectionType conType = input.getConnectionType();
+        ComplianceCheckResult serviceHandlerCheckResult = ServicehandlerComplianceCheck.check(
+                serviceNmame, sdncRequestHeader, conType, rpcActions, true, true);
+        if (serviceHandlerCheckResult.hasPassed()) {
+            LOG.debug("Service request compliant !");
+        } else {
+            return OperationResult.failed(serviceHandlerCheckResult.getMessage());
+        }
+        /*
+         * If compliant, service-request parameters are verified in order to
+         * check if there is no missing parameter that prevents calculating
+         * a path and implement a service.
+         */
+        LOG.debug("checking Tx/Rx Info for AEnd ...");
+        ComplianceCheckResult txrxCheckAEnd = ServicehandlerTxRxCheck.check(input.getServiceAEnd(),
+                ServiceEndpointType.SERVICEAEND);
+        if (txrxCheckAEnd.hasPassed()) {
+            LOG.debug("Tx/Rx Info for AEnd checked !");
+        } else {
+            return OperationResult.failed(txrxCheckAEnd.getMessage());
+        }
+
+        LOG.debug("checking Tx/Rx Info for ZEnd ...");
+        ComplianceCheckResult txrxCheckZEnd = ServicehandlerTxRxCheck.check(input.getServiceZEnd(),
+                ServiceEndpointType.SERVICEZEND);
+        if (txrxCheckZEnd.hasPassed()) {
+            LOG.debug("Tx/Rx Info for ZEnd checked");
             /*
-             * If compliant, service-request parameters are verified in order to
-             * check if there is no missing parameter that prevents calculating
-             * a path and implement a service.
+             * If OK, common-id is verified in order to see if there is
+             * no routing policy provided. If yes, the routing
+             * constraints of the policy are recovered and coherency
+             * with hard/soft constraints provided in the input of the
+             * RPC.
              */
-            LOG.debug("checking Tx/Rx Info for AEnd ...");
-            ComplianceCheckResult txrxCheckAEnd = ServicehandlerTxRxCheck.check(input.getServiceAEnd(),
-                    ServiceEndpointType.SERVICEAEND);
-            if (txrxCheckAEnd.hasPassed()) {
-                LOG.debug("Tx/Rx Info for AEnd checked !");
-            } else {
-                return OperationResult.failed(txrxCheckAEnd.getMessage());
-            }
-
-            LOG.debug("checking Tx/Rx Info for ZEnd ...");
-            ComplianceCheckResult txrxCheckZEnd = ServicehandlerTxRxCheck.check(input.getServiceZEnd(),
-                    ServiceEndpointType.SERVICEZEND);
-            if (txrxCheckZEnd.hasPassed()) {
-                LOG.debug("Tx/Rx Info for ZEnd checked");
-                /*
-                 * If OK, common-id is verified in order to see if there is
-                 * no routing policy provided. If yes, the routing
-                 * constraints of the policy are recovered and coherency
-                 * with hard/soft constraints provided in the input of the
-                 * RPC.
-                 */
-            } else {
-                return OperationResult.failed(txrxCheckZEnd.getMessage());
-            }
+        } else {
+            return OperationResult.failed(txrxCheckZEnd.getMessage());
+        }
 
-            if (input.getCommonId() != null) {
-                LOG.debug("Common-id specified");
-                // Check coherency with hard/soft constraints
-                if (CheckCoherencyHardSoft.check(input.getHardConstraints(), input.getSoftConstraints())) {
-                    LOG.debug("hard/soft constraints coherent !");
-                } else {
-                    return OperationResult.failed("hard/soft constraints are not coherent !");
-                }
+        if (input.getCommonId() != null) {
+            LOG.debug("Common-id specified");
+            // Check coherency with hard/soft constraints
+            if (CheckCoherencyHardSoft.check(input.getHardConstraints(), input.getSoftConstraints())) {
+                LOG.debug("hard/soft constraints coherent !");
             } else {
-                LOG.warn("Common-id not specified !");
+                return OperationResult.failed("hard/soft constraints are not coherent !");
             }
-        } catch (NullPointerException e) {
-            LOG.error("one of input parameter is null ",e);
-            OperationResult.failed("one of input parameter is null.");
+        } else {
+            LOG.warn("Common-id not specified !");
         }
         return OperationResult.ok("Validation successful.");
     }