Sync Integ to Master
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / elements / CapabilityDataDefinition.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.datatypes.elements;
22
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;
26
27 import java.io.Serializable;
28 import java.util.ArrayList;
29 import java.util.List;
30
31 /**
32  * Represents the capability of the component or component instance
33  */
34 public class CapabilityDataDefinition extends ToscaDataDefinition implements Serializable {
35         
36         /**
37          * 
38          */
39         private static final long serialVersionUID = 7544984873506188920L;
40         public static final String MIN_OCCURRENCES = "1";
41         public static final String MAX_OCCURRENCES = "UNBOUNDED";
42
43         /**
44          * The default constructor initializing limits of the occurrences
45          */
46         public CapabilityDataDefinition() {
47                 super();
48                 this.setMinOccurrences(  MIN_OCCURRENCES );
49                 this.setMaxOccurrences(  MAX_OCCURRENCES);
50                 this.setLeftOccurrences(  MAX_OCCURRENCES);
51         }
52         /**
53          * Deep copy constructor
54          * @param other
55          */
56         public CapabilityDataDefinition(CapabilityDataDefinition other) {
57                 super();                
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());
63                 
64                 if(other.getValidSourceTypes() == null)
65                         this.setValidSourceTypes(Lists.newArrayList());
66                 else
67                         this.setValidSourceTypes(Lists.newArrayList(other.getValidSourceTypes()));
68                 
69                 if(other.getCapabilitySources() == null)
70                         this.setCapabilitySources(Lists.newArrayList());
71                 else
72                         this.setCapabilitySources(Lists.newArrayList(other.getCapabilitySources()));
73                 
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());
79                 
80                 if(other.getPath() == null)
81                         this.setPath(Lists.newArrayList());
82                 else
83                         this.setPath(Lists.newArrayList(other.getPath()));
84                 
85                 this.setSource(other.getSource());
86                 
87         }
88
89         @Override
90         public String getOwnerId() {
91                 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
92         }
93         
94         @Override
95         public void setOwnerId(String ownerId) {
96                 setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
97         }
98
99         public String getOwnerName() {
100                 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
101         }
102
103         public void setOwnerName(String ownerName) {
104                 setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
105         }
106
107         public String getMinOccurrences() {
108                 return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
109         }
110
111         public void setMinOccurrences(String minOccurrences) {
112                 setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
113         }
114
115         public String getMaxOccurrences() {
116                 return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
117         }
118
119         public void setMaxOccurrences(String maxOccurrences) {
120                 setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
121         }
122         public String getLeftOccurrences() {
123                 return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
124         }
125
126         public void setLeftOccurrences(String leftOccurrences) {
127                 setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
128         }
129         
130         public String getUniqueId() {
131                 return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
132         }
133
134         public void setUniqueId(String uniqueId) {
135                 setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
136         }
137
138         public String getDescription() {
139                 return (String) getToscaPresentationValue(JsonPresentationFields.DESCRIPTION);
140         }
141
142         public void setDescription(String description) {
143                 setToscaPresentationValue(JsonPresentationFields.DESCRIPTION, description);
144         }
145
146         public String getName() {
147                 return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
148         }
149
150         public void setName(String name) {
151                 setToscaPresentationValue(JsonPresentationFields.NAME, name);
152         }
153         
154         public String getParentName() {
155                 return (String) getToscaPresentationValue(JsonPresentationFields.PARENT_NAME);
156         }
157
158         public void setParentName(String parentName) {
159                 setToscaPresentationValue(JsonPresentationFields.PARENT_NAME, parentName);
160         }
161
162         public String getType() {
163                 return (String) getToscaPresentationValue(JsonPresentationFields.TYPE);
164         }
165
166         public void setType(String type) {
167                 setToscaPresentationValue(JsonPresentationFields.TYPE, type);
168         }
169
170         @SuppressWarnings("unchecked")
171         public List<String> getValidSourceTypes() {
172                 return (List<String>) getToscaPresentationValue(JsonPresentationFields.VALID_SOURCE_TYPE);
173         }
174
175         public void setValidSourceTypes(List<String> validSourceTypes) {
176                 setToscaPresentationValue(JsonPresentationFields.VALID_SOURCE_TYPE, validSourceTypes);
177         }
178
179         @SuppressWarnings("unchecked")
180         public List<String> getCapabilitySources() {
181                 return (List<String>) getToscaPresentationValue(JsonPresentationFields.CAPABILITY_SOURCES);
182         }
183         
184         public void setCapabilitySources(List<String> capabilitySources) {
185                 setToscaPresentationValue(JsonPresentationFields.CAPABILITY_SOURCES, capabilitySources);
186         }
187
188         public void setPath(List<String> path){
189                 setToscaPresentationValue(JsonPresentationFields.PATH, path);
190         }
191         @SuppressWarnings("unchecked")
192         public List<String> getPath() {
193                 return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
194         }
195         public void setSource(String source){
196                 setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
197         }
198         public String getSource() {
199                 return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
200         }
201         
202         /**
203          * Adds the element to the path avoiding duplication
204          * @param elementInPath
205          */
206         public void addToPath(String elementInPath){
207                 List<String> path = getPath();
208                 if ( path == null ){
209                         path = new ArrayList<>();
210                 }
211                 if(!path.contains(elementInPath)){
212                         path.add(elementInPath);
213                 }
214                 setPath(path);
215         }
216         
217
218         
219         @Override
220         public int hashCode() {
221                 final int prime = 31;
222                 int result = 1;
223                 
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();
231                 
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();
238                 
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());
246         
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());
253                 return result;
254         }
255
256         @Override
257         public boolean equals(Object obj) {
258                 
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();
272                 
273                 if (this == obj)
274                         return true;
275                 if (obj == null)
276                         return false;
277                 if (getClass() != obj.getClass())
278                         return false;
279                 CapabilityDataDefinition other = (CapabilityDataDefinition) obj;
280                 if (capabilitySources == null) {
281                         if (other.getCapabilitySources() != null)
282                                 return false;
283                 } else if (!capabilitySources.equals(other.getCapabilitySources()))
284                         return false;
285                 if (description == null) {
286                         if (other.getDescription() != null)
287                                 return false;
288                 } else if (!description.equals(other.getDescription()))
289                         return false;
290                 if (maxOccurrences == null) {
291                         if (other.getMaxOccurrences() != null)
292                                 return false;
293                 } else if (!maxOccurrences.equals(other.getMaxOccurrences()))
294                         return false;
295                 if (minOccurrences == null) {
296                         if (other.getMinOccurrences() != null)
297                                 return false;
298                 } else if (!minOccurrences.equals(other.getMinOccurrences()))
299                         return false;
300                 if (name == null) {
301                         if (other.getName() != null)
302                                 return false;
303                 } else if (!name.equals(other.getName()))
304                         return false;
305                 if (ownerId == null) {
306                         if (other.getOwnerId() != null)
307                                 return false;
308                 } else if (!ownerId.equals(other.getOwnerId()))
309                         return false;
310                 if (ownerName == null) {
311                         if (other.getOwnerName() != null)
312                                 return false;
313                 } else if (!ownerName.equals(other.getOwnerName()))
314                         return false;
315                 if (type == null) {
316                         if (other.getType() != null)
317                                 return false;
318                 } else if (!type.equals(other.getType()))
319                         return false;
320                 if (uniqueId == null) {
321                         if (other.getUniqueId() != null)
322                                 return false;
323                 } else if (!uniqueId.equals(other.getUniqueId()))
324                         return false;
325                 if (validSourceTypes == null) {
326                         if (other.getValidSourceTypes() != null)
327                                 return false;
328                 } else if (!validSourceTypes.equals(other.getValidSourceTypes()))
329                         return false;
330                 if (leftOccurrences == null) {
331                         if (other.getLeftOccurrences() != null)
332                                 return false;
333                 } else if (!leftOccurrences.equals(other.getLeftOccurrences()))
334                         return false;
335                 if (path == null) {
336                         if (other.getPath() != null)
337                                 return false;
338                 } else if (!path.equals(other.getPath()))
339                         return false;
340                 if (source == null) {
341                         if (other.getSource() != null)
342                                 return false;
343                 } else if (!source.equals(other.getSource()))
344                         return false;
345                 return true;
346         }
347
348         @Override
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();
362                 
363                 
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 + "]";
368         }
369
370 }