Containerization feature of SO
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / flowspecific / tasks / UnassignNetworkBB.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 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.flowspecific.tasks;
22
23 import java.util.Optional;
24
25 import org.onap.so.bpmn.common.BuildingBlockExecution;
26 import org.onap.so.client.aai.entities.AAIResultWrapper;
27 import org.onap.so.client.exception.ExceptionBuilder;
28 import org.onap.so.logger.MsoLogger;
29 import org.springframework.beans.factory.annotation.Autowired;
30 import org.springframework.stereotype.Component;
31
32 @Component
33 public class UnassignNetworkBB {
34
35         private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, UnassignNetworkBB.class);
36         
37         private static String MESSAGE_CANNOT_PERFORM_UNASSIGN = "Cannot perform Unassign Network. Network is still related to ";        
38         private static String MESSAGE_ERROR_ROLLBACK = " Rollback is not possible. Please restore data manually.";      
39         
40         @Autowired
41         private ExceptionBuilder exceptionUtil;
42
43         @Autowired
44         private NetworkBBUtils networkBBUtils;
45
46         /**
47          * BPMN access method to prepare overall error messages.
48          * 
49          * @param execution - BuildingBlockExecution
50          * @param relatedToValue - String, ex: vf-module
51          * @return void - nothing
52          * @throws Exception
53          */
54         
55         public void checkRelationshipRelatedTo(BuildingBlockExecution execution, String relatedToValue) throws Exception {
56                 try {
57                         AAIResultWrapper aaiResultWrapper = execution.getVariable("l3NetworkAAIResultWrapper");
58                         Optional<org.onap.aai.domain.yang.L3Network> l3network = aaiResultWrapper.asBean(org.onap.aai.domain.yang.L3Network.class);
59                         if (networkBBUtils.isRelationshipRelatedToExists(l3network, relatedToValue)) {
60                                 String msg = MESSAGE_CANNOT_PERFORM_UNASSIGN + relatedToValue;
61                                 execution.setVariable("ErrorUnassignNetworkBB", msg);
62                                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
63                         }
64                 } catch (Exception ex) {
65                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
66                 }
67         }       
68         
69         /**
70          * BPMN access method to getCloudRegionId
71          * 
72          * @param execution - BuildingBlockExecution
73          * @return void - nothing
74          * @throws Exception
75          */
76         
77         public void getCloudSdncRegion(BuildingBlockExecution execution) throws Exception {
78                 try {
79                         String cloudRegionSdnc = networkBBUtils.getCloudRegion(execution, SourceSystem.SDNC);
80                         execution.setVariable("cloudRegionSdnc", cloudRegionSdnc);
81                 } catch (Exception ex) {
82                         exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
83                 }
84         }               
85         
86         /**
87          * BPMN access method to prepare overall error messages.
88          * 
89          * @param execution - BuildingBlockExecution
90          * @return void - nothing
91          */
92         public void errorEncountered(BuildingBlockExecution execution) {
93                 String msg;
94                 boolean isRollbackNeeded = execution.getVariable("isRollbackNeeded") != null ? execution.getVariable("isRollbackNeeded") : false;
95                 if (isRollbackNeeded == true) {
96                         msg = execution.getVariable("ErrorUnassignNetworkBB") + MESSAGE_ERROR_ROLLBACK;
97                 } else {
98                         msg = execution.getVariable("ErrorUnassignNetworkBB");
99                 }
100                 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
101         }       
102         
103         
104 }