Multiple PNFs with same ModelInfo but different instance name not able to be instantiated
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / workflow / tasks / utils / WorkflowResourceIdsUtils.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20
21 package org.onap.so.bpmn.infrastructure.workflow.tasks.utils;
22
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;
27
28 public final class WorkflowResourceIdsUtils {
29
30     private WorkflowResourceIdsUtils() {
31         throw new IllegalStateException("Utility class");
32     }
33
34     public static void setResourceIdByWorkflowType(WorkflowResourceIds workflowResourceIds, WorkflowType resourceType,
35             String resourceId) {
36         switch (resourceType) {
37             case SERVICE:
38                 workflowResourceIds.setServiceInstanceId(resourceId);
39                 break;
40             case VNF:
41                 workflowResourceIds.setVnfId(resourceId);
42                 break;
43             case PNF:
44                 workflowResourceIds.setPnfId(resourceId);
45                 break;
46             case VFMODULE:
47                 workflowResourceIds.setVfModuleId(resourceId);
48                 break;
49             case VOLUMEGROUP:
50                 workflowResourceIds.setVolumeGroupId(resourceId);
51                 break;
52             case NETWORK:
53                 workflowResourceIds.setNetworkId(resourceId);
54                 break;
55             case NETWORKCOLLECTION:
56                 workflowResourceIds.setNetworkCollectionId(resourceId);
57                 break;
58             case CONFIGURATION:
59                 workflowResourceIds.setConfigurationId(resourceId);
60                 break;
61             case INSTANCE_GROUP:
62                 workflowResourceIds.setInstanceGroupId(resourceId);
63                 break;
64         }
65     }
66
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);
73         } else if (resourceType == WorkflowType.PNF) {
74             workflowResourceIds.setPnfInstanceName(instanceName);
75         }
76     }
77
78     public static String getResourceIdByWorkflowType(WorkflowResourceIds workflowResourceIds,
79             WorkflowType resourceType) {
80         switch (resourceType) {
81             case SERVICE:
82                 return StringUtils.defaultString(workflowResourceIds.getServiceInstanceId());
83             case VNF:
84                 return StringUtils.defaultString(workflowResourceIds.getVnfId());
85             case PNF:
86                 return StringUtils.defaultString(workflowResourceIds.getPnfId());
87             case VFMODULE:
88                 return StringUtils.defaultString(workflowResourceIds.getVfModuleId());
89             case VOLUMEGROUP:
90                 return StringUtils.defaultString(workflowResourceIds.getVolumeGroupId());
91             case NETWORK:
92                 return StringUtils.defaultString(workflowResourceIds.getNetworkId());
93             case NETWORKCOLLECTION:
94                 return StringUtils.defaultString(workflowResourceIds.getNetworkCollectionId());
95             case CONFIGURATION:
96                 return StringUtils.defaultString(workflowResourceIds.getConfigurationId());
97             case INSTANCE_GROUP:
98                 return StringUtils.defaultString(workflowResourceIds.getInstanceGroupId());
99             default:
100                 return "";
101         }
102     }
103
104
105     public static WorkflowResourceIds getWorkflowResourceIdsFromExecution(DelegateExecution execution) {
106         WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
107         workflowResourceIds.setServiceInstanceId((String) execution.getVariable("serviceInstanceId"));
108         workflowResourceIds.setNetworkId((String) execution.getVariable("networkId"));
109         workflowResourceIds.setVfModuleId((String) execution.getVariable("vfModuleId"));
110         workflowResourceIds.setVnfId((String) execution.getVariable("vnfId"));
111         workflowResourceIds.setVolumeGroupId((String) execution.getVariable("volumeGroupId"));
112         workflowResourceIds.setInstanceGroupId((String) execution.getVariable("instanceGroupId"));
113         workflowResourceIds.setVnfInstanceName((String) execution.getVariable("vnfInstanceName"));
114         workflowResourceIds.setVfModuleInstanceName((String) execution.getVariable("vfModuleInstanceName"));
115         workflowResourceIds.setPnfInstanceName((String) execution.getVariable("pnfInstanceName"));
116         return workflowResourceIds;
117     }
118
119 }