91769482887158d5dbfd9ddac698c43080737fc8
[so.git] /
1 package org.onap.so.bpmn.infrastructure.pnf.delegate;
2
3 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
4 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
5 import com.google.common.base.Strings;
6 import org.camunda.bpm.engine.delegate.DelegateExecution;
7 import org.camunda.bpm.engine.delegate.JavaDelegate;
8 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
9 import org.springframework.stereotype.Component;
10
11 @Component
12 public class AssignPnfInputsCheckerDelegate implements JavaDelegate {
13
14     public static final String UUID_REGEX =
15             "(?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}$";
16
17     @Override
18     public void execute(DelegateExecution execution) {
19         validatePnfCorrelationId(execution);
20         validatePnfUuid(execution);
21     }
22
23     private void validatePnfCorrelationId(DelegateExecution execution) {
24         String pnfCorrelationId = (String) execution.getVariable(PNF_CORRELATION_ID);
25         if (Strings.isNullOrEmpty(pnfCorrelationId)) {
26             new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999,
27                     "pnfCorrelationId variable not defined");
28         }
29     }
30
31     private void validatePnfUuid(DelegateExecution execution) {
32         String pnfUuid = (String) execution.getVariable(PNF_UUID);
33         if (Strings.isNullOrEmpty(pnfUuid)) {
34             new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "pnfUuid variable not defined");
35         }
36         if (!pnfUuid.matches(UUID_REGEX)) {
37             new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "pnfUuid is not a valid UUID");
38         }
39     }
40 }