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