reduced code smells
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / adapter / vnf / tasks / VnfAdapterDeleteTasks.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2019 Samsung
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.adapter.vnf.tasks;
24
25 import org.onap.so.adapters.vnfrest.DeleteVfModuleRequest;
26 import org.onap.so.adapters.vnfrest.DeleteVolumeGroupRequest;
27 import org.onap.so.bpmn.common.BuildingBlockExecution;
28 import org.onap.so.bpmn.servicedecomposition.bbobjects.GenericVnf;
29 import org.onap.so.bpmn.servicedecomposition.bbobjects.ServiceInstance;
30 import org.onap.so.bpmn.servicedecomposition.bbobjects.VfModule;
31 import org.onap.so.bpmn.servicedecomposition.bbobjects.VolumeGroup;
32 import org.onap.so.bpmn.servicedecomposition.entities.GeneralBuildingBlock;
33 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
34 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
35 import org.onap.so.client.exception.ExceptionBuilder;
36 import org.onap.so.client.orchestration.VnfAdapterVfModuleResources;
37 import org.onap.so.client.orchestration.VnfAdapterVolumeGroupResources;
38 import org.springframework.beans.factory.annotation.Autowired;
39 import org.springframework.stereotype.Component;
40
41 @Component
42 public class VnfAdapterDeleteTasks {
43
44     private static final String VNFREST_REQUEST = "VNFREST_Request";
45
46     @Autowired
47     private ExtractPojosForBB extractPojosForBB;
48     @Autowired
49     private VnfAdapterVolumeGroupResources vnfAdapterVolumeGroupResources;
50     @Autowired
51     private VnfAdapterVfModuleResources vnfAdapterVfModuleResources;
52     @Autowired
53     private ExceptionBuilder exceptionUtil;
54
55     public void deleteVolumeGroup(BuildingBlockExecution execution) {
56         try {
57             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
58
59             ServiceInstance serviceInstance =
60                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
61             VolumeGroup volumeGroup = extractPojosForBB.extractByKey(execution, ResourceKey.VOLUME_GROUP_ID);
62
63             DeleteVolumeGroupRequest deleteVolumeGroupRequest = vnfAdapterVolumeGroupResources.deleteVolumeGroupRequest(
64                     gBBInput.getRequestContext(), gBBInput.getCloudRegion(), serviceInstance, volumeGroup);
65             execution.setVariable(VNFREST_REQUEST, deleteVolumeGroupRequest.toXmlString());
66             execution.setVariable("deleteVolumeGroupRequest", "true");
67         } catch (Exception ex) {
68             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
69         }
70     }
71
72     public void deleteVfModule(BuildingBlockExecution execution) {
73         try {
74             GeneralBuildingBlock gBBInput = execution.getGeneralBuildingBlock();
75
76             ServiceInstance serviceInstance =
77                     extractPojosForBB.extractByKey(execution, ResourceKey.SERVICE_INSTANCE_ID);
78             VfModule vfModule = extractPojosForBB.extractByKey(execution, ResourceKey.VF_MODULE_ID);
79             GenericVnf genericVnf = extractPojosForBB.extractByKey(execution, ResourceKey.GENERIC_VNF_ID);
80
81             DeleteVfModuleRequest deleteVfModuleRequest = vnfAdapterVfModuleResources.deleteVfModuleRequest(
82                     gBBInput.getRequestContext(), gBBInput.getCloudRegion(), serviceInstance, genericVnf, vfModule);
83             execution.setVariable(VNFREST_REQUEST, deleteVfModuleRequest.toXmlString());
84             execution.setVariable("deleteVfModuleRequest", "true");
85         } catch (Exception ex) {
86             exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
87         }
88     }
89 }