Sync Integ to Master
[sdc.git] / common-be / src / main / java / org / openecomp / sdc / be / datatypes / elements / PropertyDataDefinition.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 org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
24 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
25
26 import java.io.Serializable;
27 import java.util.List;
28 import java.util.Map;
29
30 public class PropertyDataDefinition extends ToscaDataDefinition implements Serializable {
31
32         /**
33          * 
34          */
35         private static final long serialVersionUID = 5798685557528432389L;
36
37         private String uniqueId;
38
39         // "boolean", "string", "float", "integer", "version" })
40         private String type;
41
42         private Boolean required = Boolean.FALSE;
43
44         protected boolean definition = false;
45
46         private String defaultValue;
47
48         private String description;
49
50         private SchemaDefinition schema;
51
52         private boolean password;
53
54         private String name;
55
56         private String value;
57
58         private String label;
59         protected Boolean hidden = Boolean.FALSE;
60         private Boolean immutable = Boolean.FALSE;
61
62         private String inputPath;
63         private String status;
64         private String inputId;
65         private String instanceUniqueId;
66         private String propertyId;
67         /**
68          * The resource id which this property belongs to
69          */
70         private String parentUniqueId;
71
72         private List<GetInputValueDataDefinition> getInputValues;
73
74         public PropertyDataDefinition() {
75                 super();
76         }
77
78         public PropertyDataDefinition(Map<String, Object> pr) {
79                 super(pr);
80
81         }
82
83         public PropertyDataDefinition(PropertyDataDefinition p) {
84                 super();
85                 this.setUniqueId(p.getUniqueId());
86                 this.setRequired(p.isRequired());
87                 this.setDefaultValue(p.getDefaultValue());
88                 this.setDescription(p.getDescription());
89                 this.setSchema(p.getSchema());
90                 this.setPassword(p.isPassword());
91                 this.setType(p.getType());
92                 this.setName(p.getName());
93                 this.setValue(p.getValue());
94                 this.setRequired(p.isRequired());
95                 this.setHidden(p.isHidden());
96                 this.setLabel(p.getLabel());
97                 this.setImmutable(p.isImmutable());
98                 this.setParentUniqueId(p.getParentUniqueId());
99                 this.setOwnerId(p.getOwnerId());
100                 this.setGetInputValues(p.getInputValues);
101                 this.setInputPath(p.getInputPath());
102                 this.setStatus(p.getStatus());
103                 this.setInputId(p.getInputId());
104                 this.setInstanceUniqueId(p.getInstanceUniqueId());
105                 this.setPropertyId(p.getPropertyId());
106         }
107
108         public String getInputPath() {
109                 return inputPath;
110         }
111
112         public void setInputPath(String inputPath) {
113                 this.inputPath = inputPath;
114         }
115
116         public String getName() {
117                 return name;
118         }
119
120         public void setName(String name) {
121                 this.name = name;
122         }
123
124         public String getValue() {
125                 return value;
126         }
127
128         public void setValue(String value) {
129                 this.value = value;
130         }
131
132         // @Override
133         public boolean isDefinition() {
134                 return true;
135         }
136
137         public void setDefinition(boolean definition) {
138                 this.definition = definition;
139         }
140
141         public String getType() {
142                 return type;
143         }
144
145         public String getDefaultValue() {
146                 return defaultValue;
147         }
148
149         public void setDefaultValue(String defaultValue) {
150                 this.defaultValue = defaultValue;
151         }
152
153         public void setType(String type) {
154                 this.type = type;
155         }
156
157         public Boolean isRequired() {
158                 return required;
159         }
160
161         public void setRequired(Boolean required) {
162                 this.required = required;
163         }
164
165         public String getDescription() {
166                 return description;
167         }
168
169         public void setDescription(String description) {
170                 this.description = description;
171         }
172
173         public boolean isPassword() {
174                 return password;
175         }
176
177         public void setPassword(boolean password) {
178                 this.password = password;
179         }
180
181         public String getUniqueId() {
182                 return uniqueId;
183         }
184
185         public void setUniqueId(String uniqueId) {
186                 this.uniqueId = uniqueId;
187         }
188
189         public SchemaDefinition getSchema() {
190                 return schema;
191         }
192
193         public void setSchema(SchemaDefinition entrySchema) {
194                 this.schema = entrySchema;
195         }
196
197         public String getSchemaType() {
198                 if (schema != null && schema.getProperty() != null) {
199                         return schema.getProperty().getType();
200                 }
201                 return null;
202         }
203
204         public String getLabel() {
205                 return label;
206         }
207
208         public void setLabel(String label) {
209                 this.label = label;
210         }
211
212         public Boolean isHidden() {
213                 return hidden;
214         }
215
216         public void setHidden(Boolean hidden) {
217                 this.hidden = hidden;
218         }
219
220         public Boolean isImmutable() {
221                 return immutable;
222         }
223
224         public void setImmutable(Boolean immutable) {
225                 this.immutable = immutable;
226         }
227
228         public String getParentUniqueId() {
229                 return getOwnerId();
230         }
231
232         public void setParentUniqueId(String parentUniqueId) {
233                 setOwnerId(parentUniqueId);
234         }
235
236         public List<GetInputValueDataDefinition> getGetInputValues() {
237                 return getInputValues;
238         }
239
240         public void setGetInputValues(List<GetInputValueDataDefinition> getInputValues) {
241                 this.getInputValues = getInputValues;
242         }
243
244         public String getStatus() {
245                 return status;
246         }
247
248         public void setStatus(String status) {
249                 this.status = status;
250         }
251
252         public String getInputId() {
253                 return inputId;
254         }
255
256         public void setInputId(String inputId) {
257                 this.inputId = inputId;
258         }
259
260         public String getInstanceUniqueId() {
261                 return instanceUniqueId;
262         }
263
264         public void setInstanceUniqueId(String instanceUniqueId) {
265                 this.instanceUniqueId = instanceUniqueId;
266         }
267
268         public String getPropertyId() {
269                 return propertyId;
270         }
271
272         public void setPropertyId(String propertyId) {
273                 this.propertyId = propertyId;
274         }
275
276         @Override
277         public String toString() {
278                 return "PropertyDataDefinition [uniqueId=" + uniqueId + ", type=" + type + ", required=" + required + ", definition=" + definition + ", defaultValue=" + defaultValue + ", description=" + description + ", schema=" + schema + ", password="
279                                 + password + ", name=" + name + ", value=" + value + ", label=" + label + ", hidden=" + hidden + ", immutable=" + immutable + ", inputPath=" + inputPath + ", status=" + status + ", inputId=" + inputId + ", instanceUniqueId="
280                                 + instanceUniqueId + ", propertyId=" + propertyId + ", parentUniqueId=" + parentUniqueId + ", getInputValues=" + getInputValues + "]";
281         }
282
283         @Override
284         public int hashCode() {
285                 final int prime = 31;
286                 int result = 1;
287                 result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
288                 result = prime * result + (definition ? 1231 : 1237);
289                 result = prime * result + ((description == null) ? 0 : description.hashCode());
290                 result = prime * result + (password ? 1231 : 1237);
291                 result = prime * result + ((required == null) ? 0 : required.hashCode());
292                 result = prime * result + ((schema == null) ? 0 : schema.hashCode());
293                 result = prime * result + ((type == null) ? 0 : type.hashCode());
294                 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
295                 result = prime * result + ((parentUniqueId == null) ? 0 : parentUniqueId.hashCode());
296                 result = prime * result + ((status == null) ? 0 : status.hashCode());
297                 return result;
298         }
299
300         public boolean typeEquals(Object obj) {
301                 if (this == obj)
302                         return true;
303                 if (obj == null)
304                         return false;
305                 if (getClass() != obj.getClass())
306                         return false;
307                 PropertyDataDefinition other = (PropertyDataDefinition) obj;
308                 if (this.getType() == null)
309                         return other.getType() == null;
310                 if (!this.type.equals(other.type)) {
311                         return false;
312                 }
313                 String thisSchemaType = this.getSchemaType();
314                 String otherSchemaType = other.getSchemaType();
315                 if (thisSchemaType == null) {
316                         return otherSchemaType == null;
317                 }
318                 return thisSchemaType.equals(otherSchemaType);
319         }
320
321         @Override
322         public boolean equals(Object obj) {
323                 if (this == obj)
324                         return true;
325                 if (obj == null)
326                         return false;
327                 if (getClass() != obj.getClass())
328                         return false;
329                 PropertyDataDefinition other = (PropertyDataDefinition) obj;
330                 if (defaultValue == null) {
331                         if (other.defaultValue != null)
332                                 return false;
333                 } else if (!defaultValue.equals(other.defaultValue))
334                         return false;
335                 if (definition != other.definition)
336                         return false;
337                 if (description == null) {
338                         if (other.description != null)
339                                 return false;
340                 } else if (!description.equals(other.description))
341                         return false;
342                 if (password != other.password)
343                         return false;
344                 if (required == null) {
345                         if (other.required != null)
346                                 return false;
347                 } else if (!required.equals(other.required))
348                         return false;
349                 if (schema == null) {
350                         if (other.schema != null)
351                                 return false;
352                 } else if (!schema.equals(other.schema))
353                         return false;
354                 if (type == null) {
355                         if (other.type != null)
356                                 return false;
357                 } else if (!type.equals(other.type))
358                         return false;
359                 if (parentUniqueId == null) {
360                         if (other.parentUniqueId != null)
361                                 return false;
362                 } else if (!parentUniqueId.equals(other.parentUniqueId))
363                         return false;
364                 if (uniqueId == null) {
365                         if (other.uniqueId != null)
366                                 return false;
367                 } else if (!uniqueId.equals(other.uniqueId))
368                         return false;
369                 if (status == null) {
370                         if (other.status != null)
371                                 return false;
372                 } else if (!status.equals(other.status))
373                         return false;
374                 return true;
375         }
376
377         @Override
378         public Object getToscaPresentationValue(JsonPresentationFields field) {
379                 switch (field) {
380                 case NAME:
381                         return name;
382                 case UNIQUE_ID:
383                         return uniqueId;
384                 case PASSWORD:
385                         return password;
386                 case TYPE:
387                         return type;
388                 case DEFINITION:
389                         return definition;
390                 case VALUE:
391                         return value;
392                 case DEFAULT_VALUE:
393                         return defaultValue;
394                 default:
395                         return super.getToscaPresentationValue(field);
396                 }
397         }
398
399         private <T extends ToscaDataDefinition> boolean compareSchemaType(T other) {
400                 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType().equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
401         }
402
403         @Override
404         public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
405                 if (this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE)) && compareSchemaType(other)) {
406                         other.setOwnerId(getOwnerId());
407                         if (allowDefaultValueOverride) {
408                                 if (getDefaultValue() != null && !getDefaultValue().isEmpty()) {
409                                         other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());
410                                 }
411                         }
412                         return other;
413                 }
414                 return null;
415         }
416
417         public void convertPropertyDataToInstancePropertyData() {
418                 if (null != value)
419                         defaultValue = value;
420         }
421
422         public boolean isGetInputProperty() {
423                 return this.getGetInputValues() != null && !this.getGetInputValues().isEmpty();
424         }
425
426 }