2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.onap.so.bpmn.infrastructure.audit;
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;
40 public class AuditTasks {
42 private static final Logger logger = LoggerFactory.getLogger(AuditTasks.class);
45 private ExceptionBuilder exceptionUtil;
48 private ExtractPojosForBB extractPojosForBB;
51 private Environment env;
53 public void isAuditNeeded(BuildingBlockExecution execution) {
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);
63 public void setupAuditVariable(BuildingBlockExecution execution) {
65 execution.setVariable("auditInventory", createAuditInventory(execution));
66 } catch (Exception ex) {
67 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
71 private AuditInventory createAuditInventory(BuildingBlockExecution execution) throws BBObjectNotFoundException {
72 AuditInventory auditInventory = new AuditInventory();
74 GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
75 VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
76 CloudRegion cloudRegion = gBBInput.getCloudRegion();
78 auditInventory.setCloudOwner(cloudRegion.getCloudOwner());
79 auditInventory.setCloudRegion(cloudRegion.getLcpCloudRegionId());
80 auditInventory.setTenantId(cloudRegion.getTenantId());
81 auditInventory.setHeatStackName(vfModule.getVfModuleName());
82 return auditInventory;