Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / java / org / onap / so / bpmn / infrastructure / pnf / delegate / PnfCheckInputs.java
index e9b0bc7..b52110e 100644 (file)
 
 package org.onap.so.bpmn.infrastructure.pnf.delegate;
 
-import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
+import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_INSTANCE_ID;
 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION;
-
 import com.google.common.base.Strings;
-import java.util.regex.Pattern;
 import org.camunda.bpm.engine.delegate.DelegateExecution;
 import org.camunda.bpm.engine.delegate.JavaDelegate;
 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
-import org.onap.so.logger.MsoLogger;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
 import org.springframework.stereotype.Component;
@@ -39,28 +37,29 @@ import org.springframework.stereotype.Component;
 @Component
 public class PnfCheckInputs implements JavaDelegate {
 
-    private static final Pattern UUID_PATTERN = Pattern
-        .compile("(?i)^[0-9a-f]{8}-[0-9a-f]{4}-[1-5]{1}[0-9a-f]{3}-[89ab]{1}[0-9a-f]{3}-[0-9a-f]{12}$");
-    private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, PnfCheckInputs.class);
+    public static final String UUID_REGEX =
+            "(?i)^[0-9a-f]{8}-[0-9a-f]{4}-[1-5]{1}[0-9a-f]{3}-[89ab]{1}[0-9a-f]{3}-[0-9a-f]{12}$";
 
-    private String defaultTimeout;
+    private String pnfEntryNotificationTimeout;
 
     @Autowired
-    public PnfCheckInputs(@Value("${aai.pnfEntryNotificationTimeout}") String defaultTimeout) {
-        this.defaultTimeout = defaultTimeout;
+    public PnfCheckInputs(@Value("${aai.pnfEntryNotificationTimeout}") String pnfEntryNotificationTimeout) {
+        this.pnfEntryNotificationTimeout = pnfEntryNotificationTimeout;
     }
 
     @Override
     public void execute(DelegateExecution execution) {
-        validateCorrelationId(execution);
+        validatePnfCorrelationId(execution);
         validatePnfUuid(execution);
         validateTimeout(execution);
+        validateServiceInstanceId(execution);
     }
 
-    private void validateCorrelationId(DelegateExecution execution) {
-        String correlationId = (String) execution.getVariable(CORRELATION_ID);
-        if (Strings.isNullOrEmpty(correlationId)) {
-            new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "correlationId variable not defined");
+    private void validatePnfCorrelationId(DelegateExecution execution) {
+        String pnfCorrelationId = (String) execution.getVariable(PNF_CORRELATION_ID);
+        if (Strings.isNullOrEmpty(pnfCorrelationId)) {
+            new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999,
+                    "pnfCorrelationId variable not defined");
         }
     }
 
@@ -69,20 +68,24 @@ public class PnfCheckInputs implements JavaDelegate {
         if (Strings.isNullOrEmpty(pnfUuid)) {
             new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "pnfUuid variable not defined");
         }
-        if (!UUID_PATTERN.matcher(pnfUuid).matches()) {
+        if (!pnfUuid.matches(UUID_REGEX)) {
             new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "pnfUuid is not a valid UUID");
         }
     }
 
     private void validateTimeout(DelegateExecution execution) {
-        String timeout = (String) execution.getVariable(TIMEOUT_FOR_NOTIFICATION);
-        if (Strings.isNullOrEmpty(timeout)) {
-            LOGGER.debug("timeoutForPnfEntryNotification variable not found, setting default");
-            if (defaultTimeout == null) {
-                new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999,
-                    "default timeoutForPnfEntryNotification value not defined");
-            }
-            execution.setVariable(TIMEOUT_FOR_NOTIFICATION, defaultTimeout);
+        if (Strings.isNullOrEmpty(pnfEntryNotificationTimeout)) {
+            new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999,
+                    "timeoutForPnfEntryNotification value not defined");
+        }
+        execution.setVariable(TIMEOUT_FOR_NOTIFICATION, pnfEntryNotificationTimeout);
+    }
+
+    private void validateServiceInstanceId(DelegateExecution execution) {
+        String serviceInstanceId = (String) execution.getVariable(SERVICE_INSTANCE_ID);
+        if (Strings.isNullOrEmpty(serviceInstanceId)) {
+            new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999,
+                    "serviceInstanceId variable not defined");
         }
     }
 }