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 private String externalName;
47 * The default constructor initializing limits of the occurrences
49 public CapabilityDataDefinition() {
50 this.setMinOccurrences(MIN_OCCURRENCES);
51 this.setMaxOccurrences(MAX_OCCURRENCES);
52 this.setLeftOccurrences(MAX_OCCURRENCES);
56 * Deep copy constructor.
58 * @param other the capability data definition to copy
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());
68 if (other.getValidSourceTypes() == null) {
69 this.setValidSourceTypes(Lists.newArrayList());
71 this.setValidSourceTypes(Lists.newArrayList(other.getValidSourceTypes()));
74 if (other.getCapabilitySources() == null) {
75 this.setCapabilitySources(Lists.newArrayList());
77 this.setCapabilitySources(Lists.newArrayList(other.getCapabilitySources()));
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());
87 if (other.getPath() == null) {
88 this.setPath(Lists.newArrayList());
90 this.setPath(Lists.newArrayList(other.getPath()));
93 this.setSource(other.getSource());
94 this.setOwnerType(other.getOwnerType());
95 this.setExternal(other.isExternal());
96 this.setExternalName(other.getExternalName());
99 public CapabilityDataDefinition(CapabilityTypeDataDefinition other) {
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());
108 this.setValidSourceTypes(Lists.newArrayList(other.getValidSourceTypes()));
110 this.setOwnerId(other.getOwnerId());
114 public String getOwnerId() {
115 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
119 public void setOwnerId(String ownerId) {
120 setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
123 public String getOwnerName() {
124 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
127 public void setOwnerName(String ownerName) {
128 setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
131 public OwnerType getOwnerType() {
132 return OwnerType.getByValue((String) getToscaPresentationValue(JsonPresentationFields.OWNER_TYPE));
135 public void setOwnerType(OwnerType ownerType) {
136 if (ownerType != null) {
137 setToscaPresentationValue(JsonPresentationFields.OWNER_TYPE, ownerType.getValue());
141 public String getMinOccurrences() {
142 return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
145 public void setMinOccurrences(String minOccurrences) {
146 setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
149 public String getMaxOccurrences() {
150 return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
153 public void setMaxOccurrences(String maxOccurrences) {
154 setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
157 public String getLeftOccurrences() {
158 return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
161 public void setLeftOccurrences(String leftOccurrences) {
162 setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
165 public String getUniqueId() {
166 return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
169 public void setUniqueId(String uniqueId) {
170 setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
173 public String getDescription() {
174 return (String) getToscaPresentationValue(JsonPresentationFields.DESCRIPTION);
177 public void setDescription(String description) {
178 setToscaPresentationValue(JsonPresentationFields.DESCRIPTION, description);
181 public String getName() {
182 return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
185 public void setName(String name) {
186 setToscaPresentationValue(JsonPresentationFields.NAME, name);
189 public String getParentName() {
190 return (String) getToscaPresentationValue(JsonPresentationFields.PARENT_NAME);
193 public void setParentName(String parentName) {
194 setToscaPresentationValue(JsonPresentationFields.PARENT_NAME, parentName);
197 public String getPreviousName() {
198 return (String) getToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME);
201 public void setPreviousName(String previousName) {
202 setToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME, previousName);
205 public String getType() {
206 return (String) getToscaPresentationValue(JsonPresentationFields.TYPE);
209 public void setType(String type) {
210 setToscaPresentationValue(JsonPresentationFields.TYPE, type);
213 @SuppressWarnings("unchecked")
214 public List<String> getValidSourceTypes() {
215 return (List<String>) getToscaPresentationValue(JsonPresentationFields.VALID_SOURCE_TYPE);
218 public void setValidSourceTypes(List<String> validSourceTypes) {
219 setToscaPresentationValue(JsonPresentationFields.VALID_SOURCE_TYPE, validSourceTypes);
222 @SuppressWarnings("unchecked")
223 public List<String> getCapabilitySources() {
224 return (List<String>) getToscaPresentationValue(JsonPresentationFields.CAPABILITY_SOURCES);
227 public void setCapabilitySources(List<String> capabilitySources) {
228 setToscaPresentationValue(JsonPresentationFields.CAPABILITY_SOURCES, capabilitySources);
231 public void setPath(List<String> path) {
232 setToscaPresentationValue(JsonPresentationFields.PATH, path);
235 @SuppressWarnings("unchecked")
236 public List<String> getPath() {
237 return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
240 public void setSource(String source) {
241 setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
244 public String getSource() {
245 return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
249 * Adds the element to the path avoiding duplication
251 * @param elementInPath
253 public void addToPath(String elementInPath) {
254 List<String> path = getPath();
256 path = new ArrayList<>();
258 if (!path.contains(elementInPath)) {
259 path.add(elementInPath);
266 public int hashCode() {
267 final int prime = 31;
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();
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();
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());
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());
303 public boolean equals(Object obj) {
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();
325 if (getClass() != obj.getClass()) {
328 CapabilityDataDefinition other = (CapabilityDataDefinition) obj;
329 if (capabilitySources == null) {
330 if (other.getCapabilitySources() != null) {
333 } else if (!capabilitySources.equals(other.getCapabilitySources())) {
336 if (description == null) {
337 if (other.getDescription() != null) {
340 } else if (!description.equals(other.getDescription())) {
343 if (maxOccurrences == null) {
344 if (other.getMaxOccurrences() != null) {
347 } else if (!maxOccurrences.equals(other.getMaxOccurrences())) {
350 if (minOccurrences == null) {
351 if (other.getMinOccurrences() != null) {
354 } else if (!minOccurrences.equals(other.getMinOccurrences())) {
358 if (other.getName() != null) {
361 } else if (!name.equals(other.getName())) {
364 if (ownerId == null) {
365 if (other.getOwnerId() != null) {
368 } else if (!ownerId.equals(other.getOwnerId())) {
371 if (ownerName == null) {
372 if (other.getOwnerName() != null) {
375 } else if (!ownerName.equals(other.getOwnerName())) {
379 if (other.getType() != null) {
382 } else if (!type.equals(other.getType())) {
385 if (uniqueId == null) {
386 if (other.getUniqueId() != null) {
389 } else if (!uniqueId.equals(other.getUniqueId())) {
392 if (validSourceTypes == null) {
393 if (other.getValidSourceTypes() != null) {
396 } else if (!validSourceTypes.equals(other.getValidSourceTypes())) {
399 if (leftOccurrences == null) {
400 if (other.getLeftOccurrences() != null) {
403 } else if (!leftOccurrences.equals(other.getLeftOccurrences())) {
407 if (other.getPath() != null) {
410 } else if (!path.equals(other.getPath())) {
413 if (source == null) {
414 return other.getSource() == null;
416 return source.equals(other.getSource());
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();
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 + "]";
442 public enum OwnerType {
444 COMPONENT_INSTANCE("component instance"),
445 RESOURCE("resource");
447 private String value;
449 OwnerType(String value) {
453 public String getValue() {
457 public static OwnerType getByValue(String value) {
458 for (OwnerType type : values()) {
459 if (type.getValue().equals(value)) {