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;
24 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
25 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
27 import java.util.ArrayList;
28 import java.util.List;
31 * Represents the capability of the component or component instance
33 public class CapabilityDataDefinition extends ToscaDataDefinition {
35 public static final String MIN_OCCURRENCES = "1";
36 public static final String MAX_OCCURRENCES = "UNBOUNDED";
39 * The default constructor initializing limits of the occurrences
41 public CapabilityDataDefinition() {
42 this.setMinOccurrences(MIN_OCCURRENCES);
43 this.setMaxOccurrences(MAX_OCCURRENCES);
44 this.setLeftOccurrences(MAX_OCCURRENCES);
48 * Deep copy constructor
52 public CapabilityDataDefinition(CapabilityDataDefinition other) {
53 this.setUniqueId(other.getUniqueId());
54 this.setType(other.getType());
55 this.setDescription(other.getDescription());
56 this.setName(other.getName());
57 this.setParentName(other.getParentName());
58 this.setPreviousName(other.getPreviousName());
60 if (other.getValidSourceTypes() == null) {
61 this.setValidSourceTypes(Lists.newArrayList());
64 this.setValidSourceTypes(Lists.newArrayList(other.getValidSourceTypes()));
67 if (other.getCapabilitySources() == null) {
68 this.setCapabilitySources(Lists.newArrayList());
71 this.setCapabilitySources(Lists.newArrayList(other.getCapabilitySources()));
74 this.setOwnerId(other.getOwnerId());
75 this.setOwnerName(other.getOwnerName());
76 this.setOwnerType(other.getOwnerType());
77 this.setMinOccurrences(other.getMinOccurrences());
78 this.setMaxOccurrences(other.getMaxOccurrences());
79 this.setLeftOccurrences(other.getLeftOccurrences());
81 if (other.getPath() == null) {
82 this.setPath(Lists.newArrayList());
85 this.setPath(Lists.newArrayList(other.getPath()));
88 this.setSource(other.getSource());
89 this.setOwnerType(other.getOwnerType());
92 public CapabilityDataDefinition(CapabilityTypeDataDefinition other) {
94 this.setUniqueId(other.getUniqueId());
95 this.setType(other.getType());
96 this.setDescription(other.getDescription());
97 this.setOwnerId(other.getOwnerId());
98 if(other.getValidSourceTypes() == null)
99 this.setValidSourceTypes(Lists.newArrayList());
101 this.setValidSourceTypes(Lists.newArrayList(other.getValidSourceTypes()));
102 this.setOwnerId(other.getOwnerId());
106 public String getOwnerId() {
107 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
111 public void setOwnerId(String ownerId) {
112 setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
115 public String getOwnerName() {
116 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
119 public void setOwnerName(String ownerName) {
120 setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
123 public OwnerType getOwnerType() {
124 return OwnerType.getByValue((String) getToscaPresentationValue(JsonPresentationFields.OWNER_TYPE));
127 public void setOwnerType(OwnerType ownerType) {
128 if(ownerType != null)
129 setToscaPresentationValue(JsonPresentationFields.OWNER_TYPE, ownerType.getValue());
132 public String getMinOccurrences() {
133 return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
136 public void setMinOccurrences(String minOccurrences) {
137 setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
140 public String getMaxOccurrences() {
141 return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
144 public void setMaxOccurrences(String maxOccurrences) {
145 setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
148 public String getLeftOccurrences() {
149 return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
152 public void setLeftOccurrences(String leftOccurrences) {
153 setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
156 public String getUniqueId() {
157 return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
160 public void setUniqueId(String uniqueId) {
161 setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
164 public String getDescription() {
165 return (String) getToscaPresentationValue(JsonPresentationFields.DESCRIPTION);
168 public void setDescription(String description) {
169 setToscaPresentationValue(JsonPresentationFields.DESCRIPTION, description);
172 public String getName() {
173 return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
176 public void setName(String name) {
177 setToscaPresentationValue(JsonPresentationFields.NAME, name);
180 public String getParentName() {
181 return (String) getToscaPresentationValue(JsonPresentationFields.PARENT_NAME);
184 public void setParentName(String parentName) {
185 setToscaPresentationValue(JsonPresentationFields.PARENT_NAME, parentName);
188 public String getPreviousName() {
189 return (String) getToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME);
192 public void setPreviousName(String previousName) {
193 setToscaPresentationValue(JsonPresentationFields.PREVIOUS_NAME, previousName);
196 public String getType() {
197 return (String) getToscaPresentationValue(JsonPresentationFields.TYPE);
200 public void setType(String type) {
201 setToscaPresentationValue(JsonPresentationFields.TYPE, type);
204 @SuppressWarnings("unchecked")
205 public List<String> getValidSourceTypes() {
206 return (List<String>) getToscaPresentationValue(JsonPresentationFields.VALID_SOURCE_TYPE);
209 public void setValidSourceTypes(List<String> validSourceTypes) {
210 setToscaPresentationValue(JsonPresentationFields.VALID_SOURCE_TYPE, validSourceTypes);
213 @SuppressWarnings("unchecked")
214 public List<String> getCapabilitySources() {
215 return (List<String>) getToscaPresentationValue(JsonPresentationFields.CAPABILITY_SOURCES);
218 public void setCapabilitySources(List<String> capabilitySources) {
219 setToscaPresentationValue(JsonPresentationFields.CAPABILITY_SOURCES, capabilitySources);
222 public void setPath(List<String> path) {
223 setToscaPresentationValue(JsonPresentationFields.PATH, path);
226 @SuppressWarnings("unchecked")
227 public List<String> getPath() {
228 return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
231 public void setSource(String source) {
232 setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
235 public String getSource() {
236 return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
240 * Adds the element to the path avoiding duplication
242 * @param elementInPath
244 public void addToPath(String elementInPath) {
245 List<String> path = getPath();
247 path = new ArrayList<>();
249 if (!path.contains(elementInPath)) {
250 path.add(elementInPath);
257 public int hashCode() {
258 final int prime = 31;
261 String uniqueId = this.getUniqueId();
262 String description = this.getDescription();
263 String name = this.getName();
264 String type = this.getType();
265 List<String> validSourceTypes = this.getValidSourceTypes();
266 List<String> capabilitySources = this.getCapabilitySources();
267 List<String> path = this.getPath();
269 String ownerId = this.getOwnerId();
270 String ownerName = this.getOwnerName();
271 String minOccurrences = this.getMinOccurrences();
272 String maxOccurrences = this.getMaxOccurrences();
273 String leftOccurrences = getLeftOccurrences();
274 String source = getSource();
276 result = prime * result + ((capabilitySources == null) ? 0 : capabilitySources.hashCode());
277 result = prime * result + ((description == null) ? 0 : description.hashCode());
278 result = prime * result + ((maxOccurrences == null) ? 0 : maxOccurrences.hashCode());
279 result = prime * result + ((minOccurrences == null) ? 0 : minOccurrences.hashCode());
280 result = prime * result + ((name == null) ? 0 : name.hashCode());
281 result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode());
282 result = prime * result + ((ownerName == null) ? 0 : ownerName.hashCode());
284 result = prime * result + ((type == null) ? 0 : type.hashCode());
285 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
286 result = prime * result + ((validSourceTypes == null) ? 0 : validSourceTypes.hashCode());
287 result = prime * result + ((leftOccurrences == null) ? 0 : leftOccurrences.hashCode());
288 result = prime * result + ((path == null) ? 0 : path.hashCode());
289 result = prime * result + ((source == null) ? 0 : source.hashCode());
294 public boolean equals(Object obj) {
296 String uniqueId = this.getUniqueId();
297 String description = this.getDescription();
298 String name = this.getName();
299 String type = this.getType();
300 List<String> validSourceTypes = this.getValidSourceTypes();
301 List<String> capabilitySources = this.getCapabilitySources();
302 String ownerId = this.getOwnerId();
303 String ownerName = this.getOwnerName();
304 String minOccurrences = this.getMinOccurrences();
305 String maxOccurrences = this.getMaxOccurrences();
306 String leftOccurrences = getLeftOccurrences();
307 List<String> path = this.getPath();
308 String source = getSource();
316 if (getClass() != obj.getClass()) {
319 CapabilityDataDefinition other = (CapabilityDataDefinition) obj;
320 if (capabilitySources == null) {
321 if (other.getCapabilitySources() != null) {
325 else if (!capabilitySources.equals(other.getCapabilitySources())) {
328 if (description == null) {
329 if (other.getDescription() != null) {
333 else if (!description.equals(other.getDescription())) {
336 if (maxOccurrences == null) {
337 if (other.getMaxOccurrences() != null) {
341 else if (!maxOccurrences.equals(other.getMaxOccurrences())) {
344 if (minOccurrences == null) {
345 if (other.getMinOccurrences() != null) {
349 else if (!minOccurrences.equals(other.getMinOccurrences())) {
353 if (other.getName() != null) {
357 else if (!name.equals(other.getName())) {
360 if (ownerId == null) {
361 if (other.getOwnerId() != null) {
365 else if (!ownerId.equals(other.getOwnerId())) {
368 if (ownerName == null) {
369 if (other.getOwnerName() != null) {
373 else if (!ownerName.equals(other.getOwnerName())) {
377 if (other.getType() != null) {
381 else if (!type.equals(other.getType())) {
384 if (uniqueId == null) {
385 if (other.getUniqueId() != null) {
389 else if (!uniqueId.equals(other.getUniqueId())) {
392 if (validSourceTypes == null) {
393 if (other.getValidSourceTypes() != null) {
397 else if (!validSourceTypes.equals(other.getValidSourceTypes())) {
400 if (leftOccurrences == null) {
401 if (other.getLeftOccurrences() != null) {
405 else if (!leftOccurrences.equals(other.getLeftOccurrences())) {
409 if (other.getPath() != null) {
413 else if (!path.equals(other.getPath())) {
416 if (source == null) {
417 if (other.getSource() != null) {
421 else if (!source.equals(other.getSource())) {
428 public String toString() {
429 String uniqueId = this.getUniqueId();
430 String description = this.getDescription();
431 String name = this.getName();
432 String type = this.getType();
433 List<String> validSourceTypes = this.getValidSourceTypes();
434 List<String> capabilitySources = this.getCapabilitySources();
435 List<String> path = this.getPath();
436 String ownerId = this.getOwnerId();
437 String ownerName = this.getOwnerName();
438 String minOccurrences = this.getMinOccurrences();
439 String maxOccurrences = this.getMaxOccurrences();
440 String source = this.getSource();
443 return "CapabilityDefinition [uniqueId=" + uniqueId + ", description=" + description + ", name=" + name
444 + ", type=" + type + ", validSourceTypes=" + validSourceTypes + ", capabilitySources="
445 + capabilitySources + ", ownerId=" + ownerId + ", ownerName=" + ownerName
446 + ", minOccurrences=" + minOccurrences + ", maxOccurrences=" + maxOccurrences + ", path=" + path + ", source=" + source + "]";
449 public enum OwnerType{
451 COMPONENT_INSTANCE("component instance"),
452 RESOURCE("resource");
454 private String value;
456 private OwnerType(String value) {
460 public String getValue() {
464 public static OwnerType getByValue(String value){
465 for(OwnerType type : values())
466 if(type.getValue().equals(value))