Merge "Add API for commit and abort OrchestrationTask"
[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.camunda.bpm.engine.delegate.DelegateExecution;
24 import org.onap.so.bpmn.infrastructure.workflow.tasks.WorkflowType;
25 import org.onap.so.bpmn.servicedecomposition.entities.WorkflowResourceIds;
26
27 public final class WorkflowResourceIdsUtils {
28
29     private WorkflowResourceIdsUtils() {
30         throw new IllegalStateException("Utility class");
31     }
32
33     public static void setResourceIdByWorkflowType(WorkflowResourceIds workflowResourceIds, WorkflowType resourceType,
34             String resourceId) {
35         switch (resourceType) {
36             case SERVICE:
37                 workflowResourceIds.setServiceInstanceId(resourceId);
38                 break;
39             case VNF:
40                 workflowResourceIds.setVnfId(resourceId);
41                 break;
42             case PNF:
43                 workflowResourceIds.setPnfId(resourceId);
44                 break;
45             case VFMODULE:
46                 workflowResourceIds.setVfModuleId(resourceId);
47                 break;
48             case VOLUMEGROUP:
49                 workflowResourceIds.setVolumeGroupId(resourceId);
50                 break;
51             case NETWORK:
52                 workflowResourceIds.setNetworkId(resourceId);
53                 break;
54             case NETWORKCOLLECTION:
55                 workflowResourceIds.setNetworkCollectionId(resourceId);
56                 break;
57             case CONFIGURATION:
58                 workflowResourceIds.setConfigurationId(resourceId);
59                 break;
60             case INSTANCE_GROUP:
61                 workflowResourceIds.setInstanceGroupId(resourceId);
62                 break;
63         }
64     }
65
66     public static WorkflowResourceIds getWorkflowResourceIdsFromExecution(DelegateExecution execution) {
67         WorkflowResourceIds workflowResourceIds = new WorkflowResourceIds();
68         workflowResourceIds.setServiceInstanceId((String) execution.getVariable("serviceInstanceId"));
69         workflowResourceIds.setNetworkId((String) execution.getVariable("networkId"));
70         workflowResourceIds.setVfModuleId((String) execution.getVariable("vfModuleId"));
71         workflowResourceIds.setVnfId((String) execution.getVariable("vnfId"));
72         workflowResourceIds.setVolumeGroupId((String) execution.getVariable("volumeGroupId"));
73         workflowResourceIds.setInstanceGroupId((String) execution.getVariable("instanceGroupId"));
74         return workflowResourceIds;
75     }
76
77 }