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