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