Merge branch 'recursive-orch'
[so.git] / bpmn / so-bpmn-tasks / src / main / java / org / onap / so / bpmn / infrastructure / workflow / tasks / Resource.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * ONAP - SO
4  * ================================================================================
5  * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved.
6  * ================================================================================
7  * Modifications Copyright (c) 2021 Orange
8  * ================================================================================
9  * Licensed under the Apache License, Version 2.0 (the "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  * 
13  *      http://www.apache.org/licenses/LICENSE-2.0
14  * 
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  * ============LICENSE_END=========================================================
21  */
22
23 package org.onap.so.bpmn.infrastructure.workflow.tasks;
24
25 import java.io.Serializable;
26 import java.util.ArrayList;
27 import java.util.Comparator;
28 import java.util.List;
29
30 public class Resource implements Serializable {
31
32     private static final long serialVersionUID = 4259534487473481127L;
33     private String resourceId;
34     private WorkflowType resourceType;
35     private boolean generated;
36     private boolean baseVfModule;
37     private String virtualLinkKey;
38     private String vnfCustomizationId;
39     private String vfModuleCustomizationId;
40     private String cvnfModuleCustomizationId;
41     private String instanceName;
42     private String modelInvariantId;
43     private String modelVersionId;
44     private String modelCustomizationId;
45     private int processingPriority;
46     private Resource parent;
47     private List<Resource> children;
48
49     public static final Comparator<Resource> sortByPriorityAsc =
50             Comparator.comparingInt(Resource::getProcessingPriority);
51     public static final Comparator<Resource> sortByPriorityDesc =
52             Comparator.comparingInt(x -> -x.getProcessingPriority());
53
54     public Resource(WorkflowType resourceType, String resourceId, boolean generated, Resource parent) {
55         this.resourceId = resourceId;
56         this.resourceType = resourceType;
57         this.generated = generated;
58         this.processingPriority = 0;
59         this.children = new ArrayList<>();
60         this.parent = parent;
61         if (parent != null)
62             this.parent.children.add(this);
63     }
64
65     public String getResourceId() {
66         return resourceId;
67     }
68
69     public void setResourceId(String resourceId) {
70         this.resourceId = resourceId;
71     }
72
73     public WorkflowType getResourceType() {
74         return resourceType;
75     }
76
77     public void setResourceType(WorkflowType resourceType) {
78         this.resourceType = resourceType;
79     }
80
81     public boolean isGenerated() {
82         return generated;
83     }
84
85     public void setGenerated(boolean generated) {
86         this.generated = generated;
87     }
88
89     public boolean isBaseVfModule() {
90         return baseVfModule;
91     }
92
93     public void setBaseVfModule(boolean baseVfModule) {
94         this.baseVfModule = baseVfModule;
95     }
96
97     public String getVirtualLinkKey() {
98         return virtualLinkKey;
99     }
100
101     public void setVirtualLinkKey(String virtualLinkKey) {
102         this.virtualLinkKey = virtualLinkKey;
103     }
104
105     public String getVnfCustomizationId() {
106         return vnfCustomizationId;
107     }
108
109     public void setVnfCustomizationId(String vnfCustomizationId) {
110         this.vnfCustomizationId = vnfCustomizationId;
111     }
112
113     public String getVfModuleCustomizationId() {
114         return vfModuleCustomizationId;
115     }
116
117     public void setVfModuleCustomizationId(String vfModuleCustomizationId) {
118         this.vfModuleCustomizationId = vfModuleCustomizationId;
119     }
120
121     public String getCvnfModuleCustomizationId() {
122         return cvnfModuleCustomizationId;
123     }
124
125     public void setCvnfModuleCustomizationId(String cvnfModuleCustomizationId) {
126         this.cvnfModuleCustomizationId = cvnfModuleCustomizationId;
127     }
128
129     public String getInstanceName() {
130         return instanceName;
131     }
132
133     public void setInstanceName(String instanceName) {
134         this.instanceName = instanceName;
135     }
136
137     public String getModelInvariantId() {
138         return modelInvariantId;
139     }
140
141     public void setModelInvariantId(String modelInvariantId) {
142         this.modelInvariantId = modelInvariantId;
143     }
144
145     public String getModelVersionId() {
146         return modelVersionId;
147     }
148
149     public void setModelVersionId(String modelVersionId) {
150         this.modelVersionId = modelVersionId;
151     }
152
153     public String getModelCustomizationId() {
154         return modelCustomizationId;
155     }
156
157     public void setModelCustomizationId(String modelCustomizationId) {
158         this.modelCustomizationId = modelCustomizationId;
159     }
160
161     public int getProcessingPriority() {
162         return processingPriority == 0 ? (isBaseVfModule() ? Integer.MIN_VALUE + 1 : 0) : processingPriority;
163     }
164
165     public void setProcessingPriority(int processingPriority) {
166         this.processingPriority = processingPriority;
167     }
168
169     public Resource getParent() {
170         return this.parent;
171     }
172
173     public List<Resource> getChildren() {
174         return this.children;
175     }
176
177     public Boolean hasParent() {
178         return parent != null;
179     }
180 }