29914252d814f834014ef19e649775fd3fa701c1
[so.git] /
1 package org.onap.so.bpmn.infrastructure.pnf.tasks;
2
3 import joptsimple.internal.Strings;
4 import org.onap.so.bpmn.common.BuildingBlockExecution;
5 import org.onap.so.client.exception.BBObjectNotFoundException;
6 import org.slf4j.Logger;
7 import org.slf4j.LoggerFactory;
8 import org.springframework.stereotype.Component;
9 import java.io.IOException;
10 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.AAI_CONTAINS_INFO_ABOUT_PNF;
11 import static org.onap.so.bpmn.infrastructure.pnf.delegate.ExecutionVariableNames.PNF_CORRELATION_ID;
12
13 @Component
14 public class CheckAaiForPnfCorrelationId extends PnfBaseTasks {
15     private static final Logger logger = LoggerFactory.getLogger(CheckAaiForPnfCorrelationId.class);
16
17     @Override
18     public void execute(BuildingBlockExecution execution) {
19         try {
20             String pnfCorrelationId = extractPnf(execution).getPnfName();
21             checkIfPnfCorrelationIdPresent(execution, pnfCorrelationId);
22             checkIfPnfExistsInAai(execution, pnfCorrelationId);
23         } catch (BBObjectNotFoundException e) {
24             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, e);
25         }
26
27     }
28
29     private void checkIfPnfCorrelationIdPresent(BuildingBlockExecution execution, String pnfCorrelationId) {
30         if (Strings.isNullOrEmpty(pnfCorrelationId)) {
31             exceptionUtil.buildAndThrowWorkflowException(execution, 500, PNF_CORRELATION_ID + " is not set");
32         }
33     }
34
35     private void checkIfPnfExistsInAai(BuildingBlockExecution execution, String pnfCorrelationId) {
36         try {
37             boolean isEntry = pnfManagement.getEntryFor(pnfCorrelationId).isPresent();
38             logger.debug("AAI entry is found for pnf correlation id {}: {}", PNF_CORRELATION_ID, isEntry);
39             execution.setVariable(AAI_CONTAINS_INFO_ABOUT_PNF, isEntry);
40         } catch (IOException e) {
41             logger.error("Exception in check AAI for pnf_correlation_id execution", e);
42             exceptionUtil.buildAndThrowWorkflowException(execution, 9999, e);
43         }
44     }
45 }