2 * ============LICENSE_START=======================================================
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
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.openecomp.sdc.be.datatypes.elements;
23 import com.google.common.collect.Lists;
26 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
27 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
29 import java.util.ArrayList;
30 import java.util.List;
33 * Represents the capability of the component or component instance
35 public class CapabilityDataDefinition extends ToscaDataDefinition {
37 public static final String MIN_OCCURRENCES = "0";
38 public static final String MAX_OCCURRENCES = "UNBOUNDED";
42 private boolean external = false;
45 * The default constructor initializing limits of the occurrences
47 public CapabilityDataDefinition() {
48 this.setMinOccurrences(MIN_OCCURRENCES);
49 this.setMaxOccurrences(MAX_OCCURRENCES);
50 this.setLeftOccurrences(MAX_OCCURRENCES);
54 * Deep copy constructor.
56 * @param other the capability data definition to copy
58 public CapabilityDataDefinition(final CapabilityDataDefinition other) {
59 this.setUniqueId(other.getUniqueId());
60 this.setType(other.getType());
61 this.setDescription(other.getDescription());
62 this.setName(other.getName());
63 this.setParentName(other.getParentName());
64 this.setPreviousName(other.getPreviousName());
66 if (other.getValidSourceTypes() == null) {
67 this.setValidSourceTypes(Lists.newArrayList());
69 this.setValidSourceTypes(Lists.newArrayList(other.getValidSourceTypes()));
72 if (other.getCapabilitySources() == null) {
73 this.setCapabilitySources(Lists.newArrayList());
75 this.setCapabilitySources(Lists.newArrayList(other.getCapabilitySources()));
78 this.setOwnerId(other.getOwnerId());
79 this.setOwnerName(other.getOwnerName());
80 this.setOwnerType(other.getOwnerType());
81 this.setMinOccurrences(other.getMinOccurrences());
82 this.setMaxOccurrences(other.getMaxOccurrences());
83 this.setLeftOccurrences(other.getLeftOccurrences());
85 if (other.getPath() == null) {
86 this.setPath(Lists.newArrayList());
88 this.setPath(Lists.newArrayList(other.getPath()));
91 this.setSource(other.getSource());
92 this.setOwnerType(other.getOwnerType());
93 this.setExternal(other.isExternal());
96 public CapabilityDataDefinition(CapabilityTypeDataDefinition other) {
98 this.setUniqueId(other.getUniqueId());
99 this.setType(other.getType());
100 this.setDescription(other.getDescription());
101 this.setOwnerId(other.getOwnerId());
102 if (other.getValidSourceTypes() == null) {
103 this.setValidSourceTypes(Lists.newArrayList());
105 this.setValidSourceTypes(Lists.newArrayList(other.getValidSourceTypes()));
107 this.setOwnerId(other.getOwnerId());
111 public String getOwnerId() {
112 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
116 public void setOwnerId(String ownerId) {
117 setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
120 public String getOwnerName() {
121 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
124 public void setOwnerName(String ownerName) {
125 setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
128 public OwnerType getOwnerType() {
129 return OwnerType.getByValue((String) getToscaPresentationValue(JsonPresentationFields.OWNER_TYPE));
132 public void setOwnerType(OwnerType ownerType) {
133 if (ownerType != null) {
134 setToscaPresentationValue(JsonPresentationFields.OWNER_TYPE, ownerType.getValue());
138 public String getMinOccurrences() {
139 return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
142 public void setMinOccurrences(String minOccurrences) {
143 setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
146 public String getMaxOccurrences() {
147 return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
150 public void setMaxOccurrences(String maxOccurrences) {
151 setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
154 public String getLeftOccurrences() {
155 return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
158 public void setLeftOccurrences(String leftOccurrences) {
159 setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
162 public String getUniqueId() {
163 return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
166 public void setUniqueId(String uniqueId) {
167 setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
170 public String getDescription() {
171 return (String) getToscaPresentationValue(JsonPresentationFields.DESCRIPTION);
174 public void setDescription(String description) {
175 setToscaPresentationValue(JsonPresentationFields.DESCRIPTION, description);
178 public String getName() {
179 return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
182 public void setName(String name) {
183 setToscaPresentationValue(JsonPresentationFields.NAME, name);
186 public String getParentName() {
187 return (String) getToscaPresentationValue(JsonPresentationFields.PARENT_NAME);
190 public void setParentName(String parentName) {
191 setToscaPresentationValue(JsonPresentationFields.PARENT_NAME, parentName);
194 public String getPreviousName() {
195 return (String) getToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME);
198 public void setPreviousName(String previousName) {
199 setToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME, previousName);
202 public String getType() {
203 return (String) getToscaPresentationValue(JsonPresentationFields.TYPE);
206 public void setType(String type) {
207 setToscaPresentationValue(JsonPresentationFields.TYPE, type);
210 @SuppressWarnings("unchecked")
211 public List<String> getValidSourceTypes() {
212 return (List<String>) getToscaPresentationValue(JsonPresentationFields.VALID_SOURCE_TYPE);
215 public void setValidSourceTypes(List<String> validSourceTypes) {
216 setToscaPresentationValue(JsonPresentationFields.VALID_SOURCE_TYPE, validSourceTypes);
219 @SuppressWarnings("unchecked")
220 public List<String> getCapabilitySources() {
221 return (List<String>) getToscaPresentationValue(JsonPresentationFields.CAPABILITY_SOURCES);
224 public void setCapabilitySources(List<String> capabilitySources) {
225 setToscaPresentationValue(JsonPresentationFields.CAPABILITY_SOURCES, capabilitySources);
228 public void setPath(List<String> path) {
229 setToscaPresentationValue(JsonPresentationFields.PATH, path);
232 @SuppressWarnings("unchecked")
233 public List<String> getPath() {
234 return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
237 public void setSource(String source) {
238 setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
241 public String getSource() {
242 return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
246 * Adds the element to the path avoiding duplication
248 * @param elementInPath
250 public void addToPath(String elementInPath) {
251 List<String> path = getPath();
253 path = new ArrayList<>();
255 if (!path.contains(elementInPath)) {
256 path.add(elementInPath);
263 public int hashCode() {
264 final int prime = 31;
267 String uniqueId = this.getUniqueId();
268 String description = this.getDescription();
269 String name = this.getName();
270 String type = this.getType();
271 List<String> validSourceTypes = this.getValidSourceTypes();
272 List<String> capabilitySources = this.getCapabilitySources();
273 List<String> path = this.getPath();
275 String ownerId = this.getOwnerId();
276 String ownerName = this.getOwnerName();
277 String minOccurrences = this.getMinOccurrences();
278 String maxOccurrences = this.getMaxOccurrences();
279 String leftOccurrences = getLeftOccurrences();
280 String source = getSource();
282 result = prime * result + ((capabilitySources == null) ? 0 : capabilitySources.hashCode());
283 result = prime * result + ((description == null) ? 0 : description.hashCode());
284 result = prime * result + ((maxOccurrences == null) ? 0 : maxOccurrences.hashCode());
285 result = prime * result + ((minOccurrences == null) ? 0 : minOccurrences.hashCode());
286 result = prime * result + ((name == null) ? 0 : name.hashCode());
287 result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode());
288 result = prime * result + ((ownerName == null) ? 0 : ownerName.hashCode());
290 result = prime * result + ((type == null) ? 0 : type.hashCode());
291 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
292 result = prime * result + ((validSourceTypes == null) ? 0 : validSourceTypes.hashCode());
293 result = prime * result + ((leftOccurrences == null) ? 0 : leftOccurrences.hashCode());
294 result = prime * result + ((path == null) ? 0 : path.hashCode());
295 result = prime * result + ((source == null) ? 0 : source.hashCode());
300 public boolean equals(Object obj) {
302 String uniqueId = this.getUniqueId();
303 String description = this.getDescription();
304 String name = this.getName();
305 String type = this.getType();
306 List<String> validSourceTypes = this.getValidSourceTypes();
307 List<String> capabilitySources = this.getCapabilitySources();
308 String ownerId = this.getOwnerId();
309 String ownerName = this.getOwnerName();
310 String minOccurrences = this.getMinOccurrences();
311 String maxOccurrences = this.getMaxOccurrences();
312 String leftOccurrences = getLeftOccurrences();
313 List<String> path = this.getPath();
314 String source = getSource();
322 if (getClass() != obj.getClass()) {
325 CapabilityDataDefinition other = (CapabilityDataDefinition) obj;
326 if (capabilitySources == null) {
327 if (other.getCapabilitySources() != null) {
330 } else if (!capabilitySources.equals(other.getCapabilitySources())) {
333 if (description == null) {
334 if (other.getDescription() != null) {
337 } else if (!description.equals(other.getDescription())) {
340 if (maxOccurrences == null) {
341 if (other.getMaxOccurrences() != null) {
344 } else if (!maxOccurrences.equals(other.getMaxOccurrences())) {
347 if (minOccurrences == null) {
348 if (other.getMinOccurrences() != null) {
351 } else if (!minOccurrences.equals(other.getMinOccurrences())) {
355 if (other.getName() != null) {
358 } else if (!name.equals(other.getName())) {
361 if (ownerId == null) {
362 if (other.getOwnerId() != null) {
365 } else if (!ownerId.equals(other.getOwnerId())) {
368 if (ownerName == null) {
369 if (other.getOwnerName() != null) {
372 } else if (!ownerName.equals(other.getOwnerName())) {
376 if (other.getType() != null) {
379 } else if (!type.equals(other.getType())) {
382 if (uniqueId == null) {
383 if (other.getUniqueId() != null) {
386 } else if (!uniqueId.equals(other.getUniqueId())) {
389 if (validSourceTypes == null) {
390 if (other.getValidSourceTypes() != null) {
393 } else if (!validSourceTypes.equals(other.getValidSourceTypes())) {
396 if (leftOccurrences == null) {
397 if (other.getLeftOccurrences() != null) {
400 } else if (!leftOccurrences.equals(other.getLeftOccurrences())) {
404 if (other.getPath() != null) {
407 } else if (!path.equals(other.getPath())) {
410 if (source == null) {
411 return other.getSource() == null;
413 return source.equals(other.getSource());
418 public String toString() {
419 String uniqueId = this.getUniqueId();
420 String description = this.getDescription();
421 String name = this.getName();
422 String type = this.getType();
423 List<String> validSourceTypes = this.getValidSourceTypes();
424 List<String> capabilitySources = this.getCapabilitySources();
425 List<String> path = this.getPath();
426 String ownerId = this.getOwnerId();
427 String ownerName = this.getOwnerName();
428 String minOccurrences = this.getMinOccurrences();
429 String maxOccurrences = this.getMaxOccurrences();
430 String source = this.getSource();
432 return "CapabilityDefinition [uniqueId=" + uniqueId + ", description=" + description + ", name=" + name
433 + ", type=" + type + ", validSourceTypes=" + validSourceTypes + ", capabilitySources="
434 + capabilitySources + ", ownerId=" + ownerId + ", ownerName=" + ownerName
435 + ", minOccurrences=" + minOccurrences + ", maxOccurrences=" + maxOccurrences + ", path=" + path + ", source=" + source
436 + ", external=" + external + "]";
439 public enum OwnerType {
441 COMPONENT_INSTANCE("component instance"),
442 RESOURCE("resource");
444 private String value;
446 OwnerType(String value) {
450 public String getValue() {
454 public static OwnerType getByValue(String value) {
455 for (OwnerType type : values()) {
456 if (type.getValue().equals(value)) {