2 * ============LICENSE_START=======================================================
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
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.flowspecific.tasks;
23 import java.util.Optional;
25 import org.onap.so.bpmn.common.BuildingBlockExecution;
26 import org.onap.so.bpmn.servicedecomposition.bbobjects.L3Network;
27 import org.onap.so.bpmn.servicedecomposition.entities.ResourceKey;
28 import org.onap.so.bpmn.servicedecomposition.tasks.ExtractPojosForBB;
29 import org.onap.so.client.aai.entities.AAIResultWrapper;
30 import org.onap.so.client.exception.ExceptionBuilder;
31 import org.onap.so.client.orchestration.AAINetworkResources;
32 import org.onap.so.logger.MsoLogger;
33 import org.springframework.beans.factory.annotation.Autowired;
34 import org.springframework.stereotype.Component;
37 public class UnassignNetworkBB {
39 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, UnassignNetworkBB.class);
41 private static String MESSAGE_CANNOT_PERFORM_UNASSIGN = "Cannot perform Unassign Network. Network is still related to ";
42 private static String MESSAGE_ERROR_ROLLBACK = " Rollback is not possible. Please restore data manually.";
45 private ExceptionBuilder exceptionUtil;
48 private NetworkBBUtils networkBBUtils;
51 private ExtractPojosForBB extractPojosForBB;
54 private AAINetworkResources aaiNetworkResources;
57 * BPMN access method to prepare overall error messages.
59 * @param execution - BuildingBlockExecution
60 * @param relatedToValue - String, ex: vf-module
61 * @return void - nothing
65 public void checkRelationshipRelatedTo(BuildingBlockExecution execution, String relatedToValue) throws Exception {
67 L3Network l3network = extractPojosForBB.extractByKey(execution, ResourceKey.NETWORK_ID,
68 execution.getLookupMap().get(ResourceKey.NETWORK_ID));
69 AAIResultWrapper aaiResultWrapper = aaiNetworkResources.queryNetworkWrapperById(l3network);
70 Optional<org.onap.aai.domain.yang.L3Network> network = aaiResultWrapper.asBean(org.onap.aai.domain.yang.L3Network.class);
71 if (networkBBUtils.isRelationshipRelatedToExists(network, relatedToValue)) {
72 String msg = MESSAGE_CANNOT_PERFORM_UNASSIGN + relatedToValue;
73 execution.setVariable("ErrorUnassignNetworkBB", msg);
74 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);
76 } catch (Exception ex) {
77 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
82 * BPMN access method to getCloudRegionId
84 * @param execution - BuildingBlockExecution
85 * @return void - nothing
89 public void getCloudSdncRegion(BuildingBlockExecution execution) throws Exception {
91 String cloudRegionSdnc = networkBBUtils.getCloudRegion(execution, SourceSystem.SDNC);
92 execution.setVariable("cloudRegionSdnc", cloudRegionSdnc);
93 } catch (Exception ex) {
94 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
99 * BPMN access method to prepare overall error messages.
101 * @param execution - BuildingBlockExecution
102 * @return void - nothing
104 public void errorEncountered(BuildingBlockExecution execution) {
106 boolean isRollbackNeeded = execution.getVariable("isRollbackNeeded") != null ? execution.getVariable("isRollbackNeeded") : false;
107 if (isRollbackNeeded == true) {
108 msg = execution.getVariable("ErrorUnassignNetworkBB") + MESSAGE_ERROR_ROLLBACK;
110 msg = execution.getVariable("ErrorUnassignNetworkBB");
112 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);