f6e07c83033333f81cc84074ba3ae46b0aa875ac
[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", Boolean.parseBoolean(env.getProperty("mso.infra.auditInventory")));
57                 } catch (Exception ex) {
58                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
59                 }
60         }
61
62         public void setupAuditVariable(BuildingBlockExecution execution) {
63                 try {
64                         execution.setVariable("auditInventory",createAuditInventory(execution));
65                 } catch (Exception ex) {
66                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
67                 }
68         }
69
70         private AuditInventory createAuditInventory(BuildingBlockExecution execution) throws BBObjectNotFoundException {
71                         AuditInventory auditInventory = new AuditInventory();
72
73                         GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
74                         VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
75                         CloudRegion cloudRegion = gBBInput.getCloudRegion();
76
77                         auditInventory.setCloudOwner(cloudRegion.getCloudOwner());
78                         auditInventory.setCloudRegion(cloudRegion.getLcpCloudRegionId());
79                         auditInventory.setTenantId(cloudRegion.getTenantId());
80                         auditInventory.setHeatStackName(vfModule.getVfModuleName());
81                         return auditInventory;
82         }
83 }