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