2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.datatypes.elements;
23 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
24 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
28 import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
30 public class PropertyDataDefinition extends ToscaDataDefinition {
32 private String uniqueId;
34 // "boolean", "string", "float", "integer", "version" })
37 private Boolean required = Boolean.FALSE;
39 protected boolean definition = false;
41 private String defaultValue;
43 private String description;
45 private SchemaDefinition schema;
47 private boolean password;
54 protected Boolean hidden = Boolean.FALSE;
55 private Boolean immutable = Boolean.FALSE;
57 private String inputPath;
58 private String status;
59 private String inputId;
60 private String instanceUniqueId;
61 private String propertyId;
63 private List<Annotation> annotations;
65 * The resource id which this property belongs to
67 private String parentUniqueId;
69 private List<GetInputValueDataDefinition> getInputValues;
71 public PropertyDataDefinition() {
75 public PropertyDataDefinition(Map<String, Object> pr) {
80 public PropertyDataDefinition(PropertyDataDefinition p) {
82 this.setUniqueId(p.getUniqueId());
83 this.setRequired(p.isRequired());
84 this.setDefaultValue(p.getDefaultValue());
85 this.setDescription(p.getDescription());
86 this.setSchema(p.getSchema());
87 this.setPassword(p.isPassword());
88 this.setType(p.getType());
89 this.setName(p.getName());
90 this.setValue(p.getValue());
91 this.setRequired(p.isRequired());
92 this.setHidden(p.isHidden());
93 this.setLabel(p.getLabel());
94 this.setImmutable(p.isImmutable());
95 this.setParentUniqueId(p.getParentUniqueId());
96 this.setOwnerId(p.getOwnerId());
97 this.setGetInputValues(p.getGetInputValues());
98 this.setInputPath(p.getInputPath());
99 this.setStatus(p.getStatus());
100 this.setInputId(p.getInputId());
101 this.setInstanceUniqueId(p.getInstanceUniqueId());
102 this.setPropertyId(p.getPropertyId());
103 if(isNotEmpty(p.annotations)){
104 this.setAnnotations(p.annotations);
108 public String getInputPath() {
112 public void setInputPath(String inputPath) {
113 this.inputPath = inputPath;
116 public String getName() {
120 public void setName(String name) {
124 public String getValue() {
128 public void setValue(String value) {
133 public boolean isDefinition() {
137 public void setDefinition(boolean definition) {
138 this.definition = definition;
141 public String getType() {
145 public String getDefaultValue() {
149 public void setDefaultValue(String defaultValue) {
150 this.defaultValue = defaultValue;
153 public void setType(String type) {
157 public Boolean isRequired() {
161 public void setRequired(Boolean required) {
162 this.required = required;
165 public String getDescription() {
169 public void setDescription(String description) {
170 this.description = description;
173 public boolean isPassword() {
177 public void setPassword(boolean password) {
178 this.password = password;
181 public String getUniqueId() {
185 public void setUniqueId(String uniqueId) {
186 this.uniqueId = uniqueId;
189 public SchemaDefinition getSchema() {
193 public void setSchema(SchemaDefinition entrySchema) {
194 this.schema = entrySchema;
197 public String getSchemaType() {
198 if (schema != null && schema.getProperty() != null) {
199 return schema.getProperty().getType();
204 public PropertyDataDefinition getSchemaProperty() {
205 if (schema != null) {
206 return schema.getProperty();
212 public String getLabel() {
216 public void setLabel(String label) {
220 public Boolean isHidden() {
224 public void setHidden(Boolean hidden) {
225 this.hidden = hidden;
228 public Boolean isImmutable() {
232 public void setImmutable(Boolean immutable) {
233 this.immutable = immutable;
236 public String getParentUniqueId() {
240 public void setParentUniqueId(String parentUniqueId) {
241 setOwnerId(parentUniqueId);
244 public List<GetInputValueDataDefinition> getGetInputValues() {
245 return getInputValues;
248 public void setGetInputValues(List<GetInputValueDataDefinition> getInputValues) {
249 this.getInputValues = getInputValues;
252 public String getStatus() {
256 public void setStatus(String status) {
257 this.status = status;
260 public String getInputId() {
264 public void setInputId(String inputId) {
265 this.inputId = inputId;
268 public String getInstanceUniqueId() {
269 return instanceUniqueId;
272 public void setInstanceUniqueId(String instanceUniqueId) {
273 this.instanceUniqueId = instanceUniqueId;
276 public String getPropertyId() {
280 public void setPropertyId(String propertyId) {
281 this.propertyId = propertyId;
285 public String toString() {
286 return "PropertyDataDefinition [uniqueId=" + uniqueId + ", type=" + type + ", required=" + required + ", definition=" + definition + ", defaultValue=" + defaultValue + ", description=" + description + ", schema=" + schema + ", password="
287 + password + ", name=" + name + ", value=" + value + ", label=" + label + ", hidden=" + hidden + ", immutable=" + immutable + ", inputPath=" + inputPath + ", status=" + status + ", inputId=" + inputId + ", instanceUniqueId="
288 + instanceUniqueId + ", propertyId=" + propertyId + ", parentUniqueId=" + parentUniqueId + ", getInputValues=" + getInputValues + "]";
292 public int hashCode() {
293 final int prime = 31;
295 result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
296 result = prime * result + (definition ? 1231 : 1237);
297 result = prime * result + ((description == null) ? 0 : description.hashCode());
298 result = prime * result + (password ? 1231 : 1237);
299 result = prime * result + ((required == null) ? 0 : required.hashCode());
300 result = prime * result + ((schema == null) ? 0 : schema.hashCode());
301 result = prime * result + ((type == null) ? 0 : type.hashCode());
302 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
303 result = prime * result + ((parentUniqueId == null) ? 0 : parentUniqueId.hashCode());
304 result = prime * result + ((status == null) ? 0 : status.hashCode());
308 public boolean typeEquals(Object obj) {
315 if (getClass() != obj.getClass()) {
318 PropertyDataDefinition other = (PropertyDataDefinition) obj;
319 if (this.getType() == null) {
320 return other.getType() == null;
322 if (!this.type.equals(other.type)) {
325 String thisSchemaType = this.getSchemaType();
326 String otherSchemaType = other.getSchemaType();
327 if (thisSchemaType == null) {
328 return otherSchemaType == null;
330 return thisSchemaType.equals(otherSchemaType);
334 public boolean equals(Object obj) {
341 if (getClass() != obj.getClass()) {
344 PropertyDataDefinition other = (PropertyDataDefinition) obj;
345 if (defaultValue == null) {
346 if (other.defaultValue != null) {
349 } else if (!defaultValue.equals(other.defaultValue)) {
352 if (definition != other.definition) {
355 if (description == null) {
356 if (other.description != null) {
359 } else if (!description.equals(other.description)) {
362 if (password != other.password) {
365 if (required == null) {
366 if (other.required != null) {
369 } else if (!required.equals(other.required)) {
372 if (schema == null) {
373 if (other.schema != null) {
376 } else if (!schema.equals(other.schema)) {
380 if (other.type != null) {
383 } else if (!type.equals(other.type)) {
386 if (parentUniqueId == null) {
387 if (other.parentUniqueId != null) {
390 } else if (!parentUniqueId.equals(other.parentUniqueId)) {
393 if (uniqueId == null) {
394 if (other.uniqueId != null) {
397 } else if (!uniqueId.equals(other.uniqueId)) {
400 if (status == null) {
401 if (other.status != null) {
404 } else if (!status.equals(other.status)) {
411 public Object getToscaPresentationValue(JsonPresentationFields field) {
428 return super.getToscaPresentationValue(field);
433 public void setToscaPresentationValue(JsonPresentationFields name, Object value) {
436 setName((String)value);
439 setUniqueId((String)value);
442 setPassword((Boolean)value);
445 setType((String)value);
448 setDefinition((Boolean)value);
451 setValue((String)value);
454 setDefaultValue((String)value);
457 super.setToscaPresentationValue(name, value);
462 private <T extends ToscaDataDefinition> boolean compareSchemaType(T other) {
463 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType().equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
467 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
468 if (this.getType() != null &&
469 this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE)) &&
470 compareSchemaType(other)) {
471 other.setOwnerId(getOwnerId());
472 if (allowDefaultValueOverride && getDefaultValue() != null && !getDefaultValue().isEmpty()) {
473 other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());
480 public void convertPropertyDataToInstancePropertyData() {
482 defaultValue = value;
486 public boolean isGetInputProperty() {
487 return this.getGetInputValues() != null && !this.getGetInputValues().isEmpty();
490 public void setAnnotations(List<Annotation> newAnnotations) {
491 Set<Annotation> annotationSet = isNotEmpty(newAnnotations) ? new HashSet<>(newAnnotations) : new HashSet<>();
492 //We would to prioritize the new valid annotations over the old ones if the same one existed.
493 if(this.annotations != null){
494 for(Annotation oldInputAnnotation : this.annotations)
495 annotationSet.add(oldInputAnnotation);
498 this.annotations = new ArrayList<>(annotationSet);
499 setToscaPresentationValue(JsonPresentationFields.ANNOTATIONS, this.annotations);
502 public List<Annotation> getAnnotations() {
503 return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);