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