94fb6a86741e0b21c3353b2e4cc76dc81efcd4d8
[so.git] /
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 com.google.common.base.Strings;
27 import org.camunda.bpm.engine.delegate.DelegateExecution;
28 import org.camunda.bpm.engine.delegate.JavaDelegate;
29 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
30 import org.onap.so.logger.MsoLogger;
31 import org.springframework.beans.factory.annotation.Autowired;
32 import org.springframework.beans.factory.annotation.Value;
33 import org.springframework.stereotype.Component;
34
35 @Component
36 public class PnfCheckInputs implements JavaDelegate {
37
38     private static MsoLogger LOGGER = MsoLogger.getMsoLogger(MsoLogger.Catalog.GENERAL, PnfCheckInputs.class);
39
40     private String defaultTimeout;
41
42     @Autowired
43     public PnfCheckInputs(@Value("${aai.pnfEntryNotificationTimeout}") String defaultTimeout) {
44         this.defaultTimeout = defaultTimeout;
45     }
46
47     @Override
48     public void execute(DelegateExecution execution) {
49         String correlationId = (String) execution.getVariable(CORRELATION_ID);
50         if (Strings.isNullOrEmpty(correlationId)) {
51             new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, "correlationId variable not defined");
52         }
53         String timeout = (String) execution.getVariable(TIMEOUT_FOR_NOTIFICATION);
54         if (Strings.isNullOrEmpty(timeout)) {
55             LOGGER.debug("timeoutForPnfEntryNotification variable not found, setting default");
56             if (defaultTimeout == null) {
57                 new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999,
58                         "default timeoutForPnfEntryNotification value not defined");
59             }
60             execution.setVariable(TIMEOUT_FOR_NOTIFICATION, defaultTimeout);
61         }
62     }
63
64 }