2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Modifications Copyright 2018 Nokia
8 * ================================================================================
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
13 * http://www.apache.org/licenses/LICENSE-2.0
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 * ============LICENSE_END=========================================================
23 package org.onap.so.bpmn.infrastructure.pnf.delegate;
25 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
26 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_UUID;
27 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.SERVICE_INSTANCE_ID;
28 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION;
30 import com.google.common.base.Strings;
31 import org.camunda.bpm.engine.delegate.DelegateExecution;
32 import org.camunda.bpm.engine.delegate.JavaDelegate;
33 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
34 import org.springframework.beans.factory.annotation.Autowired;
35 import org.springframework.beans.factory.annotation.Value;
36 import org.springframework.stereotype.Component;
39 public class PnfCheckInputs implements JavaDelegate {
41 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}$";
43 private String pnfEntryNotificationTimeout;
46 public PnfCheckInputs(@Value("${aai.pnfEntryNotificationTimeout}") String pnfEntryNotificationTimeout) {
47 this.pnfEntryNotificationTimeout = pnfEntryNotificationTimeout;
51 public void execute(DelegateExecution execution) {
52 validateCorrelationId(execution);
53 validatePnfUuid(execution);
54 validateTimeout(execution);
55 validateServiceInstanceId(execution);
58 private void validateCorrelationId(DelegateExecution execution) {
59 String correlationId = (String) execution.getVariable(CORRELATION_ID);
60 if (Strings.isNullOrEmpty(correlationId)) {
61 new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "correlationId variable not defined");
65 private void validatePnfUuid(DelegateExecution execution) {
66 String pnfUuid = (String) execution.getVariable(PNF_UUID);
67 if (Strings.isNullOrEmpty(pnfUuid)) {
68 new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "pnfUuid variable not defined");
70 if (!pnfUuid.matches(UUID_REGEX)) {
71 new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "pnfUuid is not a valid UUID");
75 private void validateTimeout(DelegateExecution execution) {
76 if (Strings.isNullOrEmpty(pnfEntryNotificationTimeout)) {
77 new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999,
78 "timeoutForPnfEntryNotification value not defined");
80 execution.setVariable(TIMEOUT_FOR_NOTIFICATION, pnfEntryNotificationTimeout);
83 private void validateServiceInstanceId(DelegateExecution execution) {
84 String serviceInstanceId = (String) execution.getVariable(SERVICE_INSTANCE_ID);
85 if (Strings.isNullOrEmpty(serviceInstanceId)) {
86 new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "serviceInstanceId variable not defined");