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