8/23: merge casablanca to master
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / java / org / onap / so / bpmn / infrastructure / pnf / delegate / PnfCheckInputs.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  * ============LICENSE_END=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.pnf.delegate;
22
23 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
24 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.TIMEOUT_FOR_NOTIFICATION;
25
26 import org.camunda.bpm.engine.delegate.DelegateExecution;
27 import org.camunda.bpm.engine.delegate.JavaDelegate;
28 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
29 import org.onap.so.logger.MsoLogger;
30 import org.springframework.beans.factory.annotation.Autowired;
31 import org.springframework.beans.factory.annotation.Value;
32 import org.springframework.stereotype.Component;
33
34 @Component
35 public class PnfCheckInputs implements JavaDelegate {
36
37     private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, PnfCheckInputs.class);
38
39     private String defaultTimeout;
40
41     @Autowired
42     public PnfCheckInputs(@Value("${aai.pnfEntryNotificationTimeout}") String defaultTimeout) {
43         this.defaultTimeout = defaultTimeout;
44     }
45
46     @Override
47     public void execute(DelegateExecution execution) {
48         String correlationId = (String) execution.getVariable(CORRELATION_ID);
49         if (correlationId == null) {
50             new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "correlationId variable not defined");
51         }
52         String timeout = (String) execution.getVariable(TIMEOUT_FOR_NOTIFICATION);
53         if (timeout == null) {
54             LOGGER.debug("timeoutForPnfEntryNotification variable not found, setting default");
55             if (defaultTimeout == null) {
56                 new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999,
57                         "default timeoutForPnfEntryNotification value not defined");
58             }
59             execution.setVariable(TIMEOUT_FOR_NOTIFICATION, defaultTimeout);
60         }
61     }
62
63 }