From 6939ace38f276b40b7c07be18450604c5a469607 Mon Sep 17 00:00:00 2001 From: Remigiusz Janeczek Date: Thu, 12 Dec 2019 14:21:20 +0100 Subject: Externalize AssignPnf Building Block and refactor existing code accordingly Issue-ID: SO-2568 Change-Id: I1eec15862d6f0b5e8ae4c952b290be8d5fc786dd Signed-off-by: Remigiusz Janeczek --- .../delegate/AssignPnfInputsCheckerDelegate.java | 40 ++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegate.java (limited to 'bpmn/so-bpmn-infrastructure-common/src/main/java') diff --git a/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegate.java b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegate.java new file mode 100644 index 0000000000..9176948288 --- /dev/null +++ b/bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegate.java @@ -0,0 +1,40 @@ +package org.onap.so.bpmn.infrastructure.pnf.delegate; + +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 com.google.common.base.Strings; +import org.camunda.bpm.engine.delegate.DelegateExecution; +import org.camunda.bpm.engine.delegate.JavaDelegate; +import org.onap.so.bpmn.common.scripts.ExceptionUtil; +import org.springframework.stereotype.Component; + +@Component +public class AssignPnfInputsCheckerDelegate implements JavaDelegate { + + 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}$"; + + @Override + public void execute(DelegateExecution execution) { + validatePnfCorrelationId(execution); + validatePnfUuid(execution); + } + + 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"); + } + } + + private void validatePnfUuid(DelegateExecution execution) { + String pnfUuid = (String) execution.getVariable(PNF_UUID); + if (Strings.isNullOrEmpty(pnfUuid)) { + new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "pnfUuid variable not defined"); + } + if (!pnfUuid.matches(UUID_REGEX)) { + new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "pnfUuid is not a valid UUID"); + } + } +} -- cgit 1.2.3-korg