Replaced all tabs with spaces in java and pom.xml
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / audit / AuditTasks.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.audit;
22
23
24 import org.onap.so.audit.beans.AuditInventory;
25 import org.onap.so.bpmn.common.BuildingBlockExecution;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.CloudRegion;
27 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
28 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
29 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
30 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
31 import org.onap.so.client.exception.BBObjectNotFoundException;
32 import org.onap.so.client.exception.ExceptionBuilder;
33 import org.slf4j.Logger;
34 import org.slf4j.LoggerFactory;
35 import org.springframework.beans.factory.annotation.Autowired;
36 import org.springframework.core.env.Environment;
37 import org.springframework.stereotype.Component;
38
39 @Component
40 public class AuditTasks {
41
42     private static final Logger logger = LoggerFactory.getLogger(AuditTasks.class);
43
44     @Autowired
45     private ExceptionBuilder exceptionUtil;
46
47     @Autowired
48     private ExtractPojosForBB extractPojosForBB;
49
50     @Autowired
51     private Environment env;
52
53     public void isAuditNeeded(BuildingBlockExecution execution) {
54         try {
55             logger.debug("auditInventoryNeeded Value: {}", env.getProperty("mso.infra.auditInventory"));
56             execution.setVariable("auditInventoryNeeded",
57                     Boolean.parseBoolean(env.getProperty("mso.infra.auditInventory")));
58         } catch (Exception ex) {
59             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
60         }
61     }
62
63     public void setupAuditVariable(BuildingBlockExecution execution) {
64         try {
65             execution.setVariable("auditInventory", createAuditInventory(execution));
66         } catch (Exception ex) {
67             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
68         }
69     }
70
71     private AuditInventory createAuditInventory(BuildingBlockExecution execution) throws BBObjectNotFoundException {
72         AuditInventory auditInventory = new AuditInventory();
73
74         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
75         VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
76         CloudRegion cloudRegion = gBBInput.getCloudRegion();
77
78         auditInventory.setCloudOwner(cloudRegion.getCloudOwner());
79         auditInventory.setCloudRegion(cloudRegion.getLcpCloudRegionId());
80         auditInventory.setTenantId(cloudRegion.getTenantId());
81         auditInventory.setHeatStackName(vfModule.getVfModuleName());
82         return auditInventory;
83     }
84 }