Sync Integ to Master
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / elements / RequirementDataDefinition.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  * Represents the requirement of the component or component instance
32  */
33 public class RequirementDataDefinition extends ToscaDataDefinition implements Serializable {
34         /**
35          * 
36          */
37         public static final String MIN_OCCURRENCES = "1";
38         public static final String MAX_OCCURRENCES = "UNBOUNDED";
39         public static final String MAX_DEFAULT_OCCURRENCES = "1";
40
41         private static final long serialVersionUID = -8840549489409274532L;
42         /**
43          * The default constructor initializing limits of the occurrences
44          */
45         public RequirementDataDefinition() {
46                 super();
47                 this.setMinOccurrences(  MIN_OCCURRENCES );
48                 this.setMaxOccurrences(  MAX_OCCURRENCES);
49                 this.setLeftOccurrences(  MAX_OCCURRENCES);
50         }
51         /**
52          * Deep copy constructor
53          * @param other
54          */
55         public RequirementDataDefinition(RequirementDataDefinition other) {
56                 this.setUniqueId(other.getUniqueId());
57                 this.setName(other.getName());
58                 this.setParentName(other.getParentName());
59                 this.setCapability(other.getCapability());
60                 this.setNode(other.getNode());
61                 this.setRelationship(other.getRelationship());
62                 this.setOwnerId(other.getOwnerId());
63                 this.setOwnerName(other.getOwnerName());
64                 this.setMinOccurrences(other.getMinOccurrences());
65                 this.setMaxOccurrences(other.getMaxOccurrences());
66                 this.setLeftOccurrences(other.getLeftOccurrences());
67                 if(other.getPath() == null)
68                         this.setPath(Lists.newArrayList());
69                 else
70                         this.setPath(Lists.newArrayList(other.getPath()));
71                 this.setSource(other.getSource());
72         }
73
74         /**
75          * Unique id of the requirement
76          */
77         public String getUniqueId() {
78                 return (String) getToscaPresentationValue(JsonPresentationFields.UNIQUE_ID);
79         }
80
81         public void setUniqueId(String uniqueId) {
82                 setToscaPresentationValue(JsonPresentationFields.UNIQUE_ID, uniqueId);
83         }
84
85         public String getName() {
86                 return (String) getToscaPresentationValue(JsonPresentationFields.NAME);
87         }
88
89         public void setName(String name) {
90                 setToscaPresentationValue(JsonPresentationFields.NAME, name);
91         }
92         
93         public String getParentName() {
94                 return (String) getToscaPresentationValue(JsonPresentationFields.PARENT_NAME);
95         }
96         
97         public void setParentName(String parentName) {
98                 setToscaPresentationValue(JsonPresentationFields.PARENT_NAME, parentName);
99         }
100
101         /**
102          * specify the capability type
103          */
104
105         public String getCapability() {
106                 return (String) getToscaPresentationValue(JsonPresentationFields.CAPAPILITY);
107         }
108
109         public void setCapability(String capability) {
110                 setToscaPresentationValue(JsonPresentationFields.CAPAPILITY, capability);
111         }
112
113         /**
114          * specify the node type(Optional by tosca)
115          */
116         public String getNode() {
117                 return (String) getToscaPresentationValue(JsonPresentationFields.NODE);
118         }
119
120         public void setNode(String node) {
121                 setToscaPresentationValue(JsonPresentationFields.NODE, node);
122         }
123
124         /**
125          * specify the relationship type(Optional by tosca)
126          */
127         public String getRelationship() {
128                 return (String) getToscaPresentationValue(JsonPresentationFields.RELATIONSHIP);
129         }
130
131         public void setRelationship(String relationship) {
132                 setToscaPresentationValue(JsonPresentationFields.RELATIONSHIP, relationship);
133         }
134
135         /**
136          *  specifies the resource instance holding this requirement
137          */
138         @Override
139         public String getOwnerId() {
140                 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_ID);
141         }
142         
143         @Override
144         public void setOwnerId(String ownerId) {
145                 setToscaPresentationValue(JsonPresentationFields.OWNER_ID, ownerId);
146         }
147
148         public String getOwnerName() {
149                 return (String) getToscaPresentationValue(JsonPresentationFields.OWNER_NAME);
150         }
151
152         public void setOwnerName(String ownerName) {
153                 setToscaPresentationValue(JsonPresentationFields.OWNER_NAME, ownerName);
154         }
155
156         public String getMinOccurrences() {
157                 return (String) getToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES);
158         }
159
160         public void setMinOccurrences(String minOccurrences) {
161                 setToscaPresentationValue(JsonPresentationFields.MIN_OCCURRENCES, minOccurrences);
162         }
163
164         public String getLeftOccurrences() {
165                 return (String) getToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES);
166         }
167
168         public void setLeftOccurrences(String leftOccurrences) {
169                 setToscaPresentationValue(JsonPresentationFields.LEFT_OCCURRENCES, leftOccurrences);
170         }
171
172         public String getMaxOccurrences() {
173                 return (String) getToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES);
174         }
175
176         public void setMaxOccurrences(String maxOccurrences) {
177                 setToscaPresentationValue(JsonPresentationFields.MAX_OCCURRENCES, maxOccurrences);
178         }
179
180         public void setPath(List<String> path) {
181                 setToscaPresentationValue(JsonPresentationFields.PATH, path);
182         }
183
184         @SuppressWarnings({ "unchecked" })
185         public List<String> getPath() {
186                 return (List<String>) getToscaPresentationValue(JsonPresentationFields.PATH);
187         }
188
189         public void setSource(String source) {
190                 setToscaPresentationValue(JsonPresentationFields.SOURCE, source);
191         }
192
193         public String getSource() {
194                 return (String) getToscaPresentationValue(JsonPresentationFields.SOURCE);
195         }
196
197         /**
198          * Adds the element to the path avoiding duplication
199          * @param elementInPath
200          */
201         public void addToPath(String elementInPath) {
202                 List<String> path = getPath();
203                 if (path == null) {
204                         path = new ArrayList<>();
205                 }
206                 if(!path.contains(elementInPath)){
207                         path.add(elementInPath);
208                 }
209                 setPath(path);
210         }
211
212         @Override
213         public int hashCode() {
214                 final int prime = 31;
215                 int result = 1;
216                 String name = getName();
217                 String uniqueId = getUniqueId();
218                 String capability = getCapability();
219                 String node = getNode();
220                 String relationship = getRelationship();
221                 String ownerId = getOwnerId();
222                 String ownerName = getOwnerName();
223                 String minOccurrences = getMinOccurrences();
224                 String maxOccurrences = getMaxOccurrences();
225                 String leftOccurrences = getLeftOccurrences();
226
227                 List<String> path = this.getPath();
228                 String source = getSource();
229
230                 result = prime * result + ((capability == null) ? 0 : capability.hashCode());
231                 result = prime * result + ((name == null) ? 0 : name.hashCode());
232                 result = prime * result + ((node == null) ? 0 : node.hashCode());
233                 result = prime * result + ((ownerId == null) ? 0 : ownerId.hashCode());
234                 result = prime * result + ((ownerName == null) ? 0 : ownerName.hashCode());
235                 result = prime * result + ((relationship == null) ? 0 : relationship.hashCode());
236                 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
237                 result = prime * result + ((minOccurrences == null) ? 0 : minOccurrences.hashCode());
238                 result = prime * result + ((maxOccurrences == null) ? 0 : maxOccurrences.hashCode());
239                 result = prime * result + ((leftOccurrences == null) ? 0 : leftOccurrences.hashCode());
240                 result = prime * result + ((path == null) ? 0 : path.hashCode());
241                 result = prime * result + ((source == null) ? 0 : source.hashCode());
242                 return result;
243         }
244
245         @Override
246         public boolean equals(Object obj) {
247                 if (this == obj)
248                         return true;
249                 if (obj == null)
250                         return false;
251                 if (getClass() != obj.getClass())
252                         return false;
253                 RequirementDataDefinition other = (RequirementDataDefinition) obj;
254
255                 String name = getName();
256                 String uniqueId = getUniqueId();
257                 String capability = getCapability();
258                 String node = getNode();
259                 String relationship = getRelationship();
260                 String ownerId = getOwnerId();
261                 String ownerName = getOwnerName();
262                 String minOccurrences = getMinOccurrences();
263                 String maxOccurrences = getMaxOccurrences();
264                 String leftOccurrences = getLeftOccurrences();
265                 List<String> path = this.getPath();
266                 String source = getSource();
267
268                 if (capability == null) {
269                         if (other.getCapability() != null)
270                                 return false;
271                 } else if (!capability.equals(other.getCapability()))
272                         return false;
273                 if (name == null) {
274                         if (other.getName() != null)
275                                 return false;
276                 } else if (!name.equals(other.getName()))
277                         return false;
278                 if (node == null) {
279                         if (other.getNode() != null)
280                                 return false;
281                 } else if (!node.equals(other.getNode()))
282                         return false;
283                 if (ownerId == null) {
284                         if (other.getOwnerId() != null)
285                                 return false;
286                 } else if (!ownerId.equals(other.getOwnerId()))
287                         return false;
288                 if (ownerName == null) {
289                         if (other.getOwnerName() != null)
290                                 return false;
291                 } else if (!ownerName.equals(other.getOwnerName()))
292                         return false;
293                 if (relationship == null) {
294                         if (other.getRelationship() != null)
295                                 return false;
296                 } else if (!relationship.equals(other.getRelationship()))
297                         return false;
298                 if (uniqueId == null) {
299                         if (other.getUniqueId() != null)
300                                 return false;
301                 } else if (!uniqueId.equals(other.getUniqueId()))
302                         return false;
303                 if (minOccurrences == null) {
304                         if (other.getMinOccurrences() != null)
305                                 return false;
306                 } else if (!minOccurrences.equals(other.getMinOccurrences()))
307                         return false;
308                 if (maxOccurrences == null) {
309                         if (other.getMaxOccurrences() != null)
310                                 return false;
311                 } else if (!maxOccurrences.equals(other.getMaxOccurrences()))
312                         return false;
313                 if (leftOccurrences == null) {
314                         if (other.getLeftOccurrences() != null)
315                                 return false;
316                 } else if (!leftOccurrences.equals(other.getLeftOccurrences()))
317                         return false;
318                 if (path == null) {
319                         if (other.getPath() != null)
320                                 return false;
321                 } else if (!path.equals(other.getPath()))
322                         return false;
323                 if (source == null) {
324                         if (other.getSource() != null)
325                                 return false;
326                 } else if (!source.equals(other.getSource()))
327                         return false;
328                 return true;
329         }
330
331         @Override
332         public String toString() {
333                 String name = getName();
334                 String uniqueId = getUniqueId();
335                 String capability = getCapability();
336                 String node = getNode();
337                 String relationship = getRelationship();
338                 String ownerId = getOwnerId();
339                 String ownerName = getOwnerName();
340                 String minOccurrences = getMinOccurrences();
341                 String maxOccurrences = getMaxOccurrences();
342                 String leftOccurrences = getLeftOccurrences();
343                 List<String> path = this.getPath();
344                 String source = getSource();
345
346                 return "RequirementDefinition [uniqueId=" + uniqueId + ", name=" + name + ", capability=" + capability + ", node=" + node + ", relationship=" + relationship + ", ownerId=" + ownerId + ", ownerName=" + ownerName + ", minOccurrences="
347                                 + minOccurrences + ", maxOccurrences=" + maxOccurrences + ",leftOccurrences=" + leftOccurrences + ", path=" + path + ", source=" + source + "]";
348         }
349
350 }