diff options
author | Remigiusz Janeczek <remigiusz.janeczek@nokia.com> | 2019-12-12 14:21:20 +0100 |
---|---|---|
committer | Remigiusz Janeczek <remigiusz.janeczek@nokia.com> | 2019-12-20 09:38:24 +0100 |
commit | 6939ace38f276b40b7c07be18450604c5a469607 (patch) | |
tree | 59f3129fe7ca56092cd442c8ff5d35609e66face /bpmn/so-bpmn-infrastructure-common/src/main | |
parent | b9765b97e0fd8a99c5b27263638eb05483f14e29 (diff) |
Externalize AssignPnf Building Block and refactor existing code accordingly
Issue-ID: SO-2568
Change-Id: I1eec15862d6f0b5e8ae4c952b290be8d5fc786dd
Signed-off-by: Remigiusz Janeczek <remigiusz.janeczek@nokia.com>
Diffstat (limited to 'bpmn/so-bpmn-infrastructure-common/src/main')
-rw-r--r-- | bpmn/so-bpmn-infrastructure-common/src/main/java/org/onap/so/bpmn/infrastructure/pnf/delegate/AssignPnfInputsCheckerDelegate.java | 40 |
1 files changed, 40 insertions, 0 deletions
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"); + } + } +} |