Merge "remove unused code"
[so.git] / bpmn / so-bpmn-infrastructure-common / src / main / java / org / onap / so / bpmn / infrastructure / pnf / delegate / CheckAaiForCorrelationIdDelegate.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.AAI_CONTAINS_INFO_ABOUT_IP;
24 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF;
25 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.CORRELATION_ID;
26
27 import java.io.IOException;
28
29 import org.camunda.bpm.engine.delegate.DelegateExecution;
30 import org.camunda.bpm.engine.delegate.JavaDelegate;
31 import org.onap.so.bpmn.common.scripts.ExceptionUtil;
32 import org.onap.so.bpmn.infrastructure.pnf.implementation.AaiConnection;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
35
36 /**
37  * Implementation of "Check AAI for correlation_id" task in CreateAndActivatePnfResource.bpmn
38  *
39  * Inputs:
40  * - correlationId - String
41  *
42  * Outputs:
43  * - aaiContainsInfoAboutPnf - local Boolean
44  */
45
46 @Component
47 public class CheckAaiForCorrelationIdDelegate implements JavaDelegate {
48     private AaiConnection aaiConnection;
49
50     @Autowired
51     public void setAaiConnection(AaiConnection aaiConnection) {
52         this.aaiConnection = aaiConnection;
53     }
54
55     @Override
56     public void execute(DelegateExecution execution) {
57         String correlationId = (String) execution.getVariable(CORRELATION_ID);
58         if (correlationId == null) {
59             new ExceptionUtil().buildAndThrowWorkflowException(execution, 500, CORRELATION_ID + " is not set");
60         }
61         try {
62             boolean isEntry = aaiConnection.getEntryFor(correlationId).isPresent();
63             execution.setVariableLocal(AAI_CONTAINS_INFO_ABOUT_PNF, isEntry);
64         } catch (IOException e) {
65             new ExceptionUtil().buildAndThrowWorkflowException(execution, 9999, e.getMessage());
66         }
67     }
68 }