Import VSP top. template handling non SDC model
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / elements / CapabilityDataDefinition.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2017 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
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.openecomp.sdc.be.datatypes.elements;
22
23 import com.google.common.collect.Lists;
24 import lombok.Getter;
25 import lombok.Setter;
26 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
27 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
28
29 import java.util.ArrayList;
30 import java.util.List;
31
32 /**
33  * Represents the capability of the component or component instance
34  */
35 public class CapabilityDataDefinition extends ToscaDataDefinition {
36
37     public static final String MIN_OCCURRENCES = "0";
38     public static final String MAX_OCCURRENCES = "UNBOUNDED";
39
40     @Getter
41     @Setter
42     private boolean external = false;
43     @Getter
44     @Setter
45     private String externalName;
46     /**
47      * The default constructor initializing limits of the occurrences
48      */
49     public CapabilityDataDefinition() {
50         this.setMinOccurrences(MIN_OCCURRENCES);
51         this.setMaxOccurrences(MAX_OCCURRENCES);
52         this.setLeftOccurrences(MAX_OCCURRENCES);
53     }
54
55     /**
56      * Deep copy constructor.
57      *
58      * @param other the capability data definition to copy
59      */
60     public CapabilityDataDefinition(final CapabilityDataDefinition other) {
61         this.setUniqueId(other.getUniqueId());
62         this.setType(other.getType());
63         this.setDescription(other.getDescription());
64         this.setName(other.getName());
65         this.setParentName(other.getParentName());
66         this.setPreviousName(other.getPreviousName());
67
68         if (other.getValidSourceTypes() == null) {
69             this.setValidSourceTypes(Lists.newArrayList());
70         } else {
71             this.setValidSourceTypes(Lists.newArrayList(other.getValidSourceTypes()));
72         }
73
74         if (other.getCapabilitySources() == null) {
75             this.setCapabilitySources(Lists.newArrayList());
76         } else {
77             this.setCapabilitySources(Lists.newArrayList(other.getCapabilitySources()));
78         }
79
80         this.setOwnerId(other.getOwnerId());
81         this.setOwnerName(other.getOwnerName());
82         this.setOwnerType(other.getOwnerType());
83         this.setMinOccurrences(other.getMinOccurrences());
84         this.setMaxOccurrences(other.getMaxOccurrences());
85         this.setLeftOccurrences(other.getLeftOccurrences());
86
87         if (other.getPath() == null) {
88             this.setPath(Lists.newArrayList());
89         } else {
90             this.setPath(Lists.newArrayList(other.getPath()));
91         }
92
93         this.setSource(other.getSource());
94         this.setOwnerType(other.getOwnerType());
95         this.setExternal(other.isExternal());
96         this.setExternalName(other.getExternalName());
97     }
98
99     public CapabilityDataDefinition(CapabilityTypeDataDefinition other) {
100         super();
101         this.setUniqueId(other.getUniqueId());
102         this.setType(other.getType());
103         this.setDescription(other.getDescription());
104         this.setOwnerId(other.getOwnerId());
105         if (other.getValidSourceTypes() == null) {
106             this.setValidSourceTypes(Lists.newArrayList());
107         } else {
108             this.setValidSourceTypes(Lists.newArrayList(other.getValidSourceTypes()));
109         }
110         this.setOwnerId(other.getOwnerId());
111     }
112
113     @Override
114     public String getOwnerId() {
115         return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
116     }
117
118     @Override
119     public void setOwnerId(String ownerId) {
120         setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
121     }
122
123     public String getOwnerName() {
124         return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
125     }
126
127     public void setOwnerName(String ownerName) {
128         setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
129     }
130
131     public OwnerType getOwnerType() {
132         return OwnerType.getByValue((String) getToscaPresentationValue(JsonPresentationFields.OWNER_TYPE));
133     }
134
135     public void setOwnerType(OwnerType ownerType) {
136         if (ownerType != null) {
137             setToscaPresentationValue(JsonPresentationFields.OWNER_TYPE, ownerType.getValue());
138         }
139     }
140
141     public String getMinOccurrences() {
142         return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
143     }
144
145     public void setMinOccurrences(String minOccurrences) {
146         setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
147     }
148
149     public String getMaxOccurrences() {
150         return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
151     }
152
153     public void setMaxOccurrences(String maxOccurrences) {
154         setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
155     }
156
157     public String getLeftOccurrences() {
158         return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
159     }
160
161     public void setLeftOccurrences(String leftOccurrences) {
162         setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
163     }
164
165     public String getUniqueId() {
166         return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
167     }
168
169     public void setUniqueId(String uniqueId) {
170         setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
171     }
172
173     public String getDescription() {
174         return (String) getToscaPresentationValue(JsonPresentationFields.DESCRIPTION);
175     }
176
177     public void setDescription(String description) {
178         setToscaPresentationValue(JsonPresentationFields.DESCRIPTION, description);
179     }
180
181     public String getName() {
182         return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
183     }
184
185     public void setName(String name) {
186         setToscaPresentationValue(JsonPresentationFields.NAME, name);
187     }
188
189     public String getParentName() {
190         return (String) getToscaPresentationValue(JsonPresentationFields.PARENT_NAME);
191     }
192
193     public void setParentName(String parentName) {
194         setToscaPresentationValue(JsonPresentationFields.PARENT_NAME, parentName);
195     }
196
197     public String getPreviousName() {
198         return (String) getToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME);
199     }
200
201     public void setPreviousName(String previousName) {
202         setToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME, previousName);
203     }
204
205     public String getType() {
206         return (String) getToscaPresentationValue(JsonPresentationFields.TYPE);
207     }
208
209     public void setType(String type) {
210         setToscaPresentationValue(JsonPresentationFields.TYPE, type);
211     }
212
213     @SuppressWarnings("unchecked")
214     public List<String> getValidSourceTypes() {
215         return (List<String>) getToscaPresentationValue(JsonPresentationFields.VALID_SOURCE_TYPE);
216     }
217
218     public void setValidSourceTypes(List<String> validSourceTypes) {
219         setToscaPresentationValue(JsonPresentationFields.VALID_SOURCE_TYPE, validSourceTypes);
220     }
221
222     @SuppressWarnings("unchecked")
223     public List<String> getCapabilitySources() {
224         return (List<String>) getToscaPresentationValue(JsonPresentationFields.CAPABILITY_SOURCES);
225     }
226
227     public void setCapabilitySources(List<String> capabilitySources) {
228         setToscaPresentationValue(JsonPresentationFields.CAPABILITY_SOURCES, capabilitySources);
229     }
230
231     public void setPath(List<String> path) {
232         setToscaPresentationValue(JsonPresentationFields.PATH, path);
233     }
234
235     @SuppressWarnings("unchecked")
236     public List<String> getPath() {
237         return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
238     }
239
240     public void setSource(String source) {
241         setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
242     }
243
244     public String getSource() {
245         return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
246     }
247
248     /**
249      * Adds the element to the path avoiding duplication
250      *
251      * @param elementInPath
252      */
253     public void addToPath(String elementInPath) {
254         List<String> path = getPath();
255         if (path == null) {
256             path = new ArrayList<>();
257         }
258         if (!path.contains(elementInPath)) {
259             path.add(elementInPath);
260         }
261         setPath(path);
262     }
263
264
265     @Override
266     public int hashCode() {
267         final int prime = 31;
268         int result = 1;
269
270         String uniqueId = this.getUniqueId();
271         String description = this.getDescription();
272         String name = this.getName();
273         String type = this.getType();
274         List<String> validSourceTypes = this.getValidSourceTypes();
275         List<String> capabilitySources = this.getCapabilitySources();
276         List<String> path = this.getPath();
277
278         String ownerId = this.getOwnerId();
279         String ownerName = this.getOwnerName();
280         String minOccurrences = this.getMinOccurrences();
281         String maxOccurrences = this.getMaxOccurrences();
282         String leftOccurrences = getLeftOccurrences();
283         String source = getSource();
284
285         result = prime * result + ((capabilitySources == null) ? 0 : capabilitySources.hashCode());
286         result = prime * result + ((description == null) ? 0 : description.hashCode());
287         result = prime * result + ((maxOccurrences == null) ? 0 : maxOccurrences.hashCode());
288         result = prime * result + ((minOccurrences == null) ? 0 : minOccurrences.hashCode());
289         result = prime * result + ((name == null) ? 0 : name.hashCode());
290         result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode());
291         result = prime * result + ((ownerName == null) ? 0 : ownerName.hashCode());
292
293         result = prime * result + ((type == null) ? 0 : type.hashCode());
294         result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
295         result = prime * result + ((validSourceTypes == null) ? 0 : validSourceTypes.hashCode());
296         result = prime * result + ((leftOccurrences == null) ? 0 : leftOccurrences.hashCode());
297         result = prime * result + ((path == null) ? 0 : path.hashCode());
298         result = prime * result + ((source == null) ? 0 : source.hashCode());
299         return result;
300     }
301
302     @Override
303     public boolean equals(Object obj) {
304
305         String uniqueId = this.getUniqueId();
306         String description = this.getDescription();
307         String name = this.getName();
308         String type = this.getType();
309         List<String> validSourceTypes = this.getValidSourceTypes();
310         List<String> capabilitySources = this.getCapabilitySources();
311         String ownerId = this.getOwnerId();
312         String ownerName = this.getOwnerName();
313         String minOccurrences = this.getMinOccurrences();
314         String maxOccurrences = this.getMaxOccurrences();
315         String leftOccurrences = getLeftOccurrences();
316         List<String> path = this.getPath();
317         String source = getSource();
318
319         if (this == obj) {
320             return true;
321         }
322         if (obj == null) {
323             return false;
324         }
325         if (getClass() != obj.getClass()) {
326             return false;
327         }
328         CapabilityDataDefinition other = (CapabilityDataDefinition) obj;
329         if (capabilitySources == null) {
330             if (other.getCapabilitySources() != null) {
331                 return false;
332             }
333         } else if (!capabilitySources.equals(other.getCapabilitySources())) {
334             return false;
335         }
336         if (description == null) {
337             if (other.getDescription() != null) {
338                 return false;
339             }
340         } else if (!description.equals(other.getDescription())) {
341             return false;
342         }
343         if (maxOccurrences == null) {
344             if (other.getMaxOccurrences() != null) {
345                 return false;
346             }
347         } else if (!maxOccurrences.equals(other.getMaxOccurrences())) {
348             return false;
349         }
350         if (minOccurrences == null) {
351             if (other.getMinOccurrences() != null) {
352                 return false;
353             }
354         } else if (!minOccurrences.equals(other.getMinOccurrences())) {
355             return false;
356         }
357         if (name == null) {
358             if (other.getName() != null) {
359                 return false;
360             }
361         } else if (!name.equals(other.getName())) {
362             return false;
363         }
364         if (ownerId == null) {
365             if (other.getOwnerId() != null) {
366                 return false;
367             }
368         } else if (!ownerId.equals(other.getOwnerId())) {
369             return false;
370         }
371         if (ownerName == null) {
372             if (other.getOwnerName() != null) {
373                 return false;
374             }
375         } else if (!ownerName.equals(other.getOwnerName())) {
376             return false;
377         }
378         if (type == null) {
379             if (other.getType() != null) {
380                 return false;
381             }
382         } else if (!type.equals(other.getType())) {
383             return false;
384         }
385         if (uniqueId == null) {
386             if (other.getUniqueId() != null) {
387                 return false;
388             }
389         } else if (!uniqueId.equals(other.getUniqueId())) {
390             return false;
391         }
392         if (validSourceTypes == null) {
393             if (other.getValidSourceTypes() != null) {
394                 return false;
395             }
396         } else if (!validSourceTypes.equals(other.getValidSourceTypes())) {
397             return false;
398         }
399         if (leftOccurrences == null) {
400             if (other.getLeftOccurrences() != null) {
401                 return false;
402             }
403         } else if (!leftOccurrences.equals(other.getLeftOccurrences())) {
404             return false;
405         }
406         if (path == null) {
407             if (other.getPath() != null) {
408                 return false;
409             }
410         } else if (!path.equals(other.getPath())) {
411             return false;
412         }
413         if (source == null) {
414             return other.getSource() == null;
415         } else {
416             return source.equals(other.getSource());
417         }
418     }
419
420     @Override
421     public String toString() {
422         String uniqueId = this.getUniqueId();
423         String description = this.getDescription();
424         String name = this.getName();
425         String type = this.getType();
426         List<String> validSourceTypes = this.getValidSourceTypes();
427         List<String> capabilitySources = this.getCapabilitySources();
428         List<String> path = this.getPath();
429         String ownerId = this.getOwnerId();
430         String ownerName = this.getOwnerName();
431         String minOccurrences = this.getMinOccurrences();
432         String maxOccurrences = this.getMaxOccurrences();
433         String source = this.getSource();
434
435         return "CapabilityDefinition [uniqueId=" + uniqueId + ", description=" + description + ", name=" + name
436             + ", type=" + type + ", validSourceTypes=" + validSourceTypes + ", capabilitySources="
437             + capabilitySources + ", ownerId=" + ownerId + ", ownerName=" + ownerName
438             + ", minOccurrences=" + minOccurrences + ", maxOccurrences=" + maxOccurrences + ", path=" + path + ", source=" + source
439             + ", external=" + external + "]";
440     }
441
442     public enum OwnerType {
443         GROUP("group"),
444         COMPONENT_INSTANCE("component instance"),
445         RESOURCE("resource");
446
447         private String value;
448
449         OwnerType(String value) {
450             this.value = value;
451         }
452
453         public String getValue() {
454             return value;
455         }
456
457         public static OwnerType getByValue(String value) {
458             for (OwnerType type : values()) {
459                 if (type.getValue().equals(value)) {
460                     return type;
461                 }
462             }
463             return null;
464         }
465
466     }
467
468 }