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 java.io.Serializable;
24 import java.util.ArrayList;
25 import java.util.List;
27 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
28 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
30 import com.google.common.collect.Lists;
33 * Represents the capability of the component or component instance
35 public class CapabilityDataDefinition extends ToscaDataDefinition implements Serializable {
40 private static final long serialVersionUID = 7544984873506188920L;
41 public static final String MIN_OCCURRENCES = "1";
42 public static final String MAX_OCCURRENCES = "UNBOUNDED";
45 * The default constructor initializing limits of the occurrences
47 public CapabilityDataDefinition() {
49 this.setMinOccurrences( MIN_OCCURRENCES );
50 this.setMaxOccurrences( MAX_OCCURRENCES);
51 this.setLeftOccurrences( MAX_OCCURRENCES);
54 * Deep copy constructor
57 public CapabilityDataDefinition(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());
65 if(other.getValidSourceTypes() == null)
66 this.setValidSourceTypes(Lists.newArrayList());
68 this.setValidSourceTypes(Lists.newArrayList(other.getValidSourceTypes()));
70 if(other.getCapabilitySources() == null)
71 this.setCapabilitySources(Lists.newArrayList());
73 this.setCapabilitySources(Lists.newArrayList(other.getCapabilitySources()));
75 this.setOwnerId( other.getOwnerId());
76 this.setOwnerName( other.getOwnerName());
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());
84 this.setPath(Lists.newArrayList(other.getPath()));
86 this.setSource(other.getSource());
91 public String getOwnerId() {
92 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
96 public void setOwnerId(String ownerId) {
97 setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
100 public String getOwnerName() {
101 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
104 public void setOwnerName(String ownerName) {
105 setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
108 public String getMinOccurrences() {
109 return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
112 public void setMinOccurrences(String minOccurrences) {
113 setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
116 public String getMaxOccurrences() {
117 return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
120 public void setMaxOccurrences(String maxOccurrences) {
121 setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
123 public String getLeftOccurrences() {
124 return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
127 public void setLeftOccurrences(String leftOccurrences) {
128 setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
131 public String getUniqueId() {
132 return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
135 public void setUniqueId(String uniqueId) {
136 setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
139 public String getDescription() {
140 return (String) getToscaPresentationValue(JsonPresentationFields.DESCRIPTION);
143 public void setDescription(String description) {
144 setToscaPresentationValue(JsonPresentationFields.DESCRIPTION, description);
147 public String getName() {
148 return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
151 public void setName(String name) {
152 setToscaPresentationValue(JsonPresentationFields.NAME, name);
155 public String getParentName() {
156 return (String) getToscaPresentationValue(JsonPresentationFields.PARENT_NAME);
159 public void setParentName(String parentName) {
160 setToscaPresentationValue(JsonPresentationFields.PARENT_NAME, parentName);
163 public String getType() {
164 return (String) getToscaPresentationValue(JsonPresentationFields.TYPE);
167 public void setType(String type) {
168 setToscaPresentationValue(JsonPresentationFields.TYPE, type);
171 @SuppressWarnings("unchecked")
172 public List<String> getValidSourceTypes() {
173 return (List<String>) getToscaPresentationValue(JsonPresentationFields.VALID_SOURCE_TYPE);
176 public void setValidSourceTypes(List<String> validSourceTypes) {
177 setToscaPresentationValue(JsonPresentationFields.VALID_SOURCE_TYPE, validSourceTypes);
180 @SuppressWarnings("unchecked")
181 public List<String> getCapabilitySources() {
182 return (List<String>) getToscaPresentationValue(JsonPresentationFields.CAPABILITY_SOURCES);
185 public void setCapabilitySources(List<String> capabilitySources) {
186 setToscaPresentationValue(JsonPresentationFields.CAPABILITY_SOURCES, capabilitySources);
189 public void setPath(List<String> path){
190 setToscaPresentationValue(JsonPresentationFields.PATH, path);
192 @SuppressWarnings("unchecked")
193 public List<String> getPath() {
194 return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
196 public void setSource(String source){
197 setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
199 public String getSource() {
200 return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
204 * Adds the element to the path avoiding duplication
205 * @param elementInPath
207 public void addToPath(String elementInPath){
208 List<String> path = getPath();
210 path = new ArrayList<>();
212 if(!path.contains(elementInPath)){
213 path.add(elementInPath);
221 public int hashCode() {
222 final int prime = 31;
225 String uniqueId = this.getUniqueId();
226 String description = this.getDescription();
227 String name = this.getName();
228 String type = this.getType();
229 List<String> validSourceTypes = this.getValidSourceTypes();
230 List<String> capabilitySources = this.getCapabilitySources();
231 List<String> path = this.getPath();
233 String ownerId = this.getOwnerId();
234 String ownerName = this.getOwnerName();
235 String minOccurrences = this.getMinOccurrences();
236 String maxOccurrences = this.getMaxOccurrences();
237 String leftOccurrences = getLeftOccurrences();
238 String source = getSource();
240 result = prime * result + ((capabilitySources == null) ? 0 : capabilitySources.hashCode());
241 result = prime * result + ((description == null) ? 0 : description.hashCode());
242 result = prime * result + ((maxOccurrences == null) ? 0 : maxOccurrences.hashCode());
243 result = prime * result + ((minOccurrences == null) ? 0 : minOccurrences.hashCode());
244 result = prime * result + ((name == null) ? 0 : name.hashCode());
245 result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode());
246 result = prime * result + ((ownerName == null) ? 0 : ownerName.hashCode());
248 result = prime * result + ((type == null) ? 0 : type.hashCode());
249 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
250 result = prime * result + ((validSourceTypes == null) ? 0 : validSourceTypes.hashCode());
251 result = prime * result + ((leftOccurrences == null) ? 0 : leftOccurrences.hashCode());
252 result = prime * result + ((path == null) ? 0 : path.hashCode());
253 result = prime * result + ((source == null) ? 0 : source.hashCode());
258 public boolean equals(Object obj) {
260 String uniqueId = this.getUniqueId();
261 String description = this.getDescription();
262 String name = this.getName();
263 String type = this.getType();
264 List<String> validSourceTypes = this.getValidSourceTypes();
265 List<String> capabilitySources = this.getCapabilitySources();
266 String ownerId = this.getOwnerId();
267 String ownerName = this.getOwnerName();
268 String minOccurrences = this.getMinOccurrences();
269 String maxOccurrences = this.getMaxOccurrences();
270 String leftOccurrences = getLeftOccurrences();
271 List<String> path = this.getPath();
272 String source = getSource();
278 if (getClass() != obj.getClass())
280 CapabilityDataDefinition other = (CapabilityDataDefinition) obj;
281 if (capabilitySources == null) {
282 if (other.getCapabilitySources() != null)
284 } else if (!capabilitySources.equals(other.getCapabilitySources()))
286 if (description == null) {
287 if (other.getDescription() != null)
289 } else if (!description.equals(other.getDescription()))
291 if (maxOccurrences == null) {
292 if (other.getMaxOccurrences() != null)
294 } else if (!maxOccurrences.equals(other.getMaxOccurrences()))
296 if (minOccurrences == null) {
297 if (other.getMinOccurrences() != null)
299 } else if (!minOccurrences.equals(other.getMinOccurrences()))
302 if (other.getName() != null)
304 } else if (!name.equals(other.getName()))
306 if (ownerId == null) {
307 if (other.getOwnerId() != null)
309 } else if (!ownerId.equals(other.getOwnerId()))
311 if (ownerName == null) {
312 if (other.getOwnerName() != null)
314 } else if (!ownerName.equals(other.getOwnerName()))
317 if (other.getType() != null)
319 } else if (!type.equals(other.getType()))
321 if (uniqueId == null) {
322 if (other.getUniqueId() != null)
324 } else if (!uniqueId.equals(other.getUniqueId()))
326 if (validSourceTypes == null) {
327 if (other.getValidSourceTypes() != null)
329 } else if (!validSourceTypes.equals(other.getValidSourceTypes()))
331 if (leftOccurrences == null) {
332 if (other.getLeftOccurrences() != null)
334 } else if (!leftOccurrences.equals(other.getLeftOccurrences()))
337 if (other.getPath() != null)
339 } else if (!path.equals(other.getPath()))
341 if (source == null) {
342 if (other.getSource() != null)
344 } else if (!source.equals(other.getSource()))
350 public String toString() {
351 String uniqueId = this.getUniqueId();
352 String description = this.getDescription();
353 String name = this.getName();
354 String type = this.getType();
355 List<String> validSourceTypes = this.getValidSourceTypes();
356 List<String> capabilitySources = this.getCapabilitySources();
357 List<String> path = this.getPath();
358 String ownerId = this.getOwnerId();
359 String ownerName = this.getOwnerName();
360 String minOccurrences = this.getMinOccurrences();
361 String maxOccurrences = this.getMaxOccurrences();
362 String source = this.getSource();
365 return "CapabilityDefinition [uniqueId=" + uniqueId + ", description=" + description + ", name=" + name
366 + ", type=" + type + ", validSourceTypes=" + validSourceTypes + ", capabilitySources="
367 + capabilitySources + ", ownerId=" + ownerId + ", ownerName=" + ownerName
368 + ", minOccurrences=" + minOccurrences + ", maxOccurrences=" + maxOccurrences + ", path=" + path+ ", source=" + source + "]";