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.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;
33 public class UnassignNetworkBB {
35 private static final MsoLogger msoLogger = MsoLogger.getMsoLogger(MsoLogger.Catalog.BPEL, UnassignNetworkBB.class);
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.";
41 private ExceptionBuilder exceptionUtil;
44 private NetworkBBUtils networkBBUtils;
47 * BPMN access method to prepare overall error messages.
49 * @param execution - BuildingBlockExecution
50 * @param relatedToValue - String, ex: vf-module
51 * @return void - nothing
55 public void checkRelationshipRelatedTo(BuildingBlockExecution execution, String relatedToValue) throws Exception {
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);
64 } catch (Exception ex) {
65 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
70 * BPMN access method to getCloudRegionId
72 * @param execution - BuildingBlockExecution
73 * @return void - nothing
77 public void getCloudSdncRegion(BuildingBlockExecution execution) throws Exception {
79 String cloudRegionSdnc = networkBBUtils.getCloudRegion(execution, SourceSystem.SDNC);
80 execution.setVariable("cloudRegionSdnc", cloudRegionSdnc);
81 } catch (Exception ex) {
82 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, ex);
87 * BPMN access method to prepare overall error messages.
89 * @param execution - BuildingBlockExecution
90 * @return void - nothing
92 public void errorEncountered(BuildingBlockExecution execution) {
94 boolean isRollbackNeeded = execution.getVariable("isRollbackNeeded") != null ? execution.getVariable("isRollbackNeeded") : false;
95 if (isRollbackNeeded == true) {
96 msg = execution.getVariable("ErrorUnassignNetworkBB") + MESSAGE_ERROR_ROLLBACK;
98 msg = execution.getVariable("ErrorUnassignNetworkBB");
100 exceptionUtil.buildAndThrowWorkflowException(execution, 7000, msg);