2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2020 Nokia 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.workflow.tasks.utils;
23 import org.apache.commons.lang3.StringUtils;
24 import org.camunda.bpm.engine.delegate.DelegateExecution;
25 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType;
26 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
28 public final class WorkflowResourceIdsUtils {
30 private WorkflowResourceIdsUtils() {
31 throw new IllegalStateException("Utility class");
34 public static void setResourceIdByWorkflowType(WorkflowResourceIds workflowResourceIds, WorkflowType resourceType,
36 switch (resourceType) {
38 workflowResourceIds.setServiceInstanceId(resourceId);
41 workflowResourceIds.setVnfId(resourceId);
44 workflowResourceIds.setPnfId(resourceId);
47 workflowResourceIds.setVfModuleId(resourceId);
50 workflowResourceIds.setVolumeGroupId(resourceId);
53 workflowResourceIds.setNetworkId(resourceId);
55 case NETWORKCOLLECTION:
56 workflowResourceIds.setNetworkCollectionId(resourceId);
59 workflowResourceIds.setConfigurationId(resourceId);
62 workflowResourceIds.setInstanceGroupId(resourceId);
67 public static void setInstanceNameByWorkflowType(WorkflowResourceIds workflowResourceIds, WorkflowType resourceType,
68 String instanceName) {
69 if (resourceType == WorkflowType.VNF) {
70 workflowResourceIds.setVnfInstanceName(instanceName);
71 } else if (resourceType == WorkflowType.VFMODULE) {
72 workflowResourceIds.setVfModuleInstanceName(instanceName);
76 public static String getResourceIdByWorkflowType(WorkflowResourceIds workflowResourceIds,
77 WorkflowType resourceType) {
78 switch (resourceType) {
80 return StringUtils.defaultString(workflowResourceIds.getServiceInstanceId());
82 return StringUtils.defaultString(workflowResourceIds.getVnfId());
84 return StringUtils.defaultString(workflowResourceIds.getPnfId());
86 return StringUtils.defaultString(workflowResourceIds.getVfModuleId());
88 return StringUtils.defaultString(workflowResourceIds.getVolumeGroupId());
90 return StringUtils.defaultString(workflowResourceIds.getNetworkId());
91 case NETWORKCOLLECTION:
92 return StringUtils.defaultString(workflowResourceIds.getNetworkCollectionId());
94 return StringUtils.defaultString(workflowResourceIds.getConfigurationId());
96 return StringUtils.defaultString(workflowResourceIds.getInstanceGroupId());
103 public static WorkflowResourceIds getWorkflowResourceIdsFromExecution(DelegateExecution execution) {
104 WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
105 workflowResourceIds.setServiceInstanceId((String) execution.getVariable("serviceInstanceId"));
106 workflowResourceIds.setNetworkId((String) execution.getVariable("networkId"));
107 workflowResourceIds.setVfModuleId((String) execution.getVariable("vfModuleId"));
108 workflowResourceIds.setVnfId((String) execution.getVariable("vnfId"));
109 workflowResourceIds.setVolumeGroupId((String) execution.getVariable("volumeGroupId"));
110 workflowResourceIds.setInstanceGroupId((String) execution.getVariable("instanceGroupId"));
111 workflowResourceIds.setVnfInstanceName((String) execution.getVariable("vnfInstanceName"));
112 workflowResourceIds.setVfModuleInstanceName((String) execution.getVariable("vfModuleInstanceName"));
113 return workflowResourceIds;