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.io.Serializable;
28 import java.util.ArrayList;
29 import java.util.List;
32 * Represents the capability of the component or component instance
34 public class CapabilityDataDefinition extends ToscaDataDefinition implements Serializable {
39 private static final long serialVersionUID = 7544984873506188920L;
40 public static final String MIN_OCCURRENCES = "1";
41 public static final String MAX_OCCURRENCES = "UNBOUNDED";
44 * The default constructor initializing limits of the occurrences
46 public CapabilityDataDefinition() {
48 this.setMinOccurrences( MIN_OCCURRENCES );
49 this.setMaxOccurrences( MAX_OCCURRENCES);
50 this.setLeftOccurrences( MAX_OCCURRENCES);
53 * Deep copy constructor
56 public CapabilityDataDefinition(CapabilityDataDefinition other) {
58 this.setUniqueId(other.getUniqueId());
59 this.setType(other.getType());
60 this.setDescription ( other.getDescription());
61 this.setName( other.getName());
62 this.setParentName( other.getParentName());
64 if(other.getValidSourceTypes() == null)
65 this.setValidSourceTypes(Lists.newArrayList());
67 this.setValidSourceTypes(Lists.newArrayList(other.getValidSourceTypes()));
69 if(other.getCapabilitySources() == null)
70 this.setCapabilitySources(Lists.newArrayList());
72 this.setCapabilitySources(Lists.newArrayList(other.getCapabilitySources()));
74 this.setOwnerId( other.getOwnerId());
75 this.setOwnerName( other.getOwnerName());
76 this.setMinOccurrences( other.getMinOccurrences());
77 this.setMaxOccurrences( other.getMaxOccurrences());
78 this.setLeftOccurrences(other.getLeftOccurrences());
80 if(other.getPath() == null)
81 this.setPath(Lists.newArrayList());
83 this.setPath(Lists.newArrayList(other.getPath()));
85 this.setSource(other.getSource());
90 public String getOwnerId() {
91 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
95 public void setOwnerId(String ownerId) {
96 setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
99 public String getOwnerName() {
100 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
103 public void setOwnerName(String ownerName) {
104 setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
107 public String getMinOccurrences() {
108 return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
111 public void setMinOccurrences(String minOccurrences) {
112 setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
115 public String getMaxOccurrences() {
116 return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
119 public void setMaxOccurrences(String maxOccurrences) {
120 setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
122 public String getLeftOccurrences() {
123 return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
126 public void setLeftOccurrences(String leftOccurrences) {
127 setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
130 public String getUniqueId() {
131 return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
134 public void setUniqueId(String uniqueId) {
135 setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
138 public String getDescription() {
139 return (String) getToscaPresentationValue(JsonPresentationFields.DESCRIPTION);
142 public void setDescription(String description) {
143 setToscaPresentationValue(JsonPresentationFields.DESCRIPTION, description);
146 public String getName() {
147 return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
150 public void setName(String name) {
151 setToscaPresentationValue(JsonPresentationFields.NAME, name);
154 public String getParentName() {
155 return (String) getToscaPresentationValue(JsonPresentationFields.PARENT_NAME);
158 public void setParentName(String parentName) {
159 setToscaPresentationValue(JsonPresentationFields.PARENT_NAME, parentName);
162 public String getType() {
163 return (String) getToscaPresentationValue(JsonPresentationFields.TYPE);
166 public void setType(String type) {
167 setToscaPresentationValue(JsonPresentationFields.TYPE, type);
170 @SuppressWarnings("unchecked")
171 public List<String> getValidSourceTypes() {
172 return (List<String>) getToscaPresentationValue(JsonPresentationFields.VALID_SOURCE_TYPE);
175 public void setValidSourceTypes(List<String> validSourceTypes) {
176 setToscaPresentationValue(JsonPresentationFields.VALID_SOURCE_TYPE, validSourceTypes);
179 @SuppressWarnings("unchecked")
180 public List<String> getCapabilitySources() {
181 return (List<String>) getToscaPresentationValue(JsonPresentationFields.CAPABILITY_SOURCES);
184 public void setCapabilitySources(List<String> capabilitySources) {
185 setToscaPresentationValue(JsonPresentationFields.CAPABILITY_SOURCES, capabilitySources);
188 public void setPath(List<String> path){
189 setToscaPresentationValue(JsonPresentationFields.PATH, path);
191 @SuppressWarnings("unchecked")
192 public List<String> getPath() {
193 return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
195 public void setSource(String source){
196 setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
198 public String getSource() {
199 return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
203 * Adds the element to the path avoiding duplication
204 * @param elementInPath
206 public void addToPath(String elementInPath){
207 List<String> path = getPath();
209 path = new ArrayList<>();
211 if(!path.contains(elementInPath)){
212 path.add(elementInPath);
220 public int hashCode() {
221 final int prime = 31;
224 String uniqueId = this.getUniqueId();
225 String description = this.getDescription();
226 String name = this.getName();
227 String type = this.getType();
228 List<String> validSourceTypes = this.getValidSourceTypes();
229 List<String> capabilitySources = this.getCapabilitySources();
230 List<String> path = this.getPath();
232 String ownerId = this.getOwnerId();
233 String ownerName = this.getOwnerName();
234 String minOccurrences = this.getMinOccurrences();
235 String maxOccurrences = this.getMaxOccurrences();
236 String leftOccurrences = getLeftOccurrences();
237 String source = getSource();
239 result = prime * result + ((capabilitySources == null) ? 0 : capabilitySources.hashCode());
240 result = prime * result + ((description == null) ? 0 : description.hashCode());
241 result = prime * result + ((maxOccurrences == null) ? 0 : maxOccurrences.hashCode());
242 result = prime * result + ((minOccurrences == null) ? 0 : minOccurrences.hashCode());
243 result = prime * result + ((name == null) ? 0 : name.hashCode());
244 result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode());
245 result = prime * result + ((ownerName == null) ? 0 : ownerName.hashCode());
247 result = prime * result + ((type == null) ? 0 : type.hashCode());
248 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
249 result = prime * result + ((validSourceTypes == null) ? 0 : validSourceTypes.hashCode());
250 result = prime * result + ((leftOccurrences == null) ? 0 : leftOccurrences.hashCode());
251 result = prime * result + ((path == null) ? 0 : path.hashCode());
252 result = prime * result + ((source == null) ? 0 : source.hashCode());
257 public boolean equals(Object obj) {
259 String uniqueId = this.getUniqueId();
260 String description = this.getDescription();
261 String name = this.getName();
262 String type = this.getType();
263 List<String> validSourceTypes = this.getValidSourceTypes();
264 List<String> capabilitySources = this.getCapabilitySources();
265 String ownerId = this.getOwnerId();
266 String ownerName = this.getOwnerName();
267 String minOccurrences = this.getMinOccurrences();
268 String maxOccurrences = this.getMaxOccurrences();
269 String leftOccurrences = getLeftOccurrences();
270 List<String> path = this.getPath();
271 String source = getSource();
277 if (getClass() != obj.getClass())
279 CapabilityDataDefinition other = (CapabilityDataDefinition) obj;
280 if (capabilitySources == null) {
281 if (other.getCapabilitySources() != null)
283 } else if (!capabilitySources.equals(other.getCapabilitySources()))
285 if (description == null) {
286 if (other.getDescription() != null)
288 } else if (!description.equals(other.getDescription()))
290 if (maxOccurrences == null) {
291 if (other.getMaxOccurrences() != null)
293 } else if (!maxOccurrences.equals(other.getMaxOccurrences()))
295 if (minOccurrences == null) {
296 if (other.getMinOccurrences() != null)
298 } else if (!minOccurrences.equals(other.getMinOccurrences()))
301 if (other.getName() != null)
303 } else if (!name.equals(other.getName()))
305 if (ownerId == null) {
306 if (other.getOwnerId() != null)
308 } else if (!ownerId.equals(other.getOwnerId()))
310 if (ownerName == null) {
311 if (other.getOwnerName() != null)
313 } else if (!ownerName.equals(other.getOwnerName()))
316 if (other.getType() != null)
318 } else if (!type.equals(other.getType()))
320 if (uniqueId == null) {
321 if (other.getUniqueId() != null)
323 } else if (!uniqueId.equals(other.getUniqueId()))
325 if (validSourceTypes == null) {
326 if (other.getValidSourceTypes() != null)
328 } else if (!validSourceTypes.equals(other.getValidSourceTypes()))
330 if (leftOccurrences == null) {
331 if (other.getLeftOccurrences() != null)
333 } else if (!leftOccurrences.equals(other.getLeftOccurrences()))
336 if (other.getPath() != null)
338 } else if (!path.equals(other.getPath()))
340 if (source == null) {
341 if (other.getSource() != null)
343 } else if (!source.equals(other.getSource()))
349 public String toString() {
350 String uniqueId = this.getUniqueId();
351 String description = this.getDescription();
352 String name = this.getName();
353 String type = this.getType();
354 List<String> validSourceTypes = this.getValidSourceTypes();
355 List<String> capabilitySources = this.getCapabilitySources();
356 List<String> path = this.getPath();
357 String ownerId = this.getOwnerId();
358 String ownerName = this.getOwnerName();
359 String minOccurrences = this.getMinOccurrences();
360 String maxOccurrences = this.getMaxOccurrences();
361 String source = this.getSource();
364 return "CapabilityDefinition [uniqueId=" + uniqueId + ", description=" + description + ", name=" + name
365 + ", type=" + type + ", validSourceTypes=" + validSourceTypes + ", capabilitySources="
366 + capabilitySources + ", ownerId=" + ownerId + ", ownerName=" + ownerName
367 + ", minOccurrences=" + minOccurrences + ", maxOccurrences=" + maxOccurrences + ", path=" + path+ ", source=" + source + "]";