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