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 static org.apache.commons.collections.CollectionUtils.isNotEmpty;
25 import java.util.ArrayList;
26 import java.util.HashSet;
27 import java.util.List;
29 import java.util.Objects;
31 import org.apache.commons.collections.CollectionUtils;
32 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
33 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
35 public class PropertyDataDefinition extends ToscaDataDefinition {
37 private String uniqueId;
39 // "boolean", "string", "float", "integer", "version" })
42 private Boolean required = Boolean.FALSE;
44 protected boolean definition = false;
46 private String defaultValue;
48 private String description;
50 private SchemaDefinition schema;
52 private boolean password;
59 protected Boolean hidden = Boolean.FALSE;
60 private Boolean immutable = Boolean.FALSE;
62 private String inputPath;
63 private String status;
64 private String inputId;
65 private String instanceUniqueId;
66 private String propertyId;
67 private String parentPropertyType;
68 private String subPropertyInputPath;
70 private List<Annotation> annotations;
72 * The resource id which this property belongs to
74 private String parentUniqueId;
76 private List<GetInputValueDataDefinition> getInputValues;
78 private Boolean isDeclaredListInput = Boolean.FALSE;
80 private List<GetPolicyValueDataDefinition> getPolicyValues;
82 public PropertyDataDefinition() {
86 public PropertyDataDefinition(Map<String, Object> pr) {
91 public PropertyDataDefinition(PropertyDataDefinition propertyDataDefinition) {
93 this.setUniqueId(propertyDataDefinition.getUniqueId());
94 this.setRequired(propertyDataDefinition.isRequired());
95 this.setDefaultValue(propertyDataDefinition.getDefaultValue());
96 this.setDescription(propertyDataDefinition.getDescription());
97 this.setSchema(propertyDataDefinition.getSchema());
98 this.setPassword(propertyDataDefinition.isPassword());
99 this.setType(propertyDataDefinition.getType());
100 this.setName(propertyDataDefinition.getName());
101 this.setValue(propertyDataDefinition.getValue());
102 this.setRequired(propertyDataDefinition.isRequired());
103 this.setHidden(propertyDataDefinition.isHidden());
104 this.setLabel(propertyDataDefinition.getLabel());
105 this.setImmutable(propertyDataDefinition.isImmutable());
106 this.setParentUniqueId(propertyDataDefinition.getParentUniqueId());
107 this.setOwnerId(propertyDataDefinition.getOwnerId());
108 this.setGetInputValues(propertyDataDefinition.getGetInputValues());
109 this.setGetPolicyValues(propertyDataDefinition.getGetPolicyValues());
110 this.setInputPath(propertyDataDefinition.getInputPath());
111 this.setStatus(propertyDataDefinition.getStatus());
112 this.setInputId(propertyDataDefinition.getInputId());
113 this.setInstanceUniqueId(propertyDataDefinition.getInstanceUniqueId());
114 this.setPropertyId(propertyDataDefinition.getPropertyId());
115 this.parentPropertyType = propertyDataDefinition.getParentPropertyType();
116 this.subPropertyInputPath = propertyDataDefinition.getSubPropertyInputPath();
117 if(isNotEmpty(propertyDataDefinition.annotations)){
118 this.setAnnotations(propertyDataDefinition.annotations);
120 this.setIsDeclaredListInput(propertyDataDefinition.getIsDeclaredListInput());
123 public String getParentPropertyType() {
124 return parentPropertyType;
127 public void setParentPropertyType(String parentPropertyType) {
128 this.parentPropertyType = parentPropertyType;
131 public String getSubPropertyInputPath() {
132 return subPropertyInputPath;
135 public void setSubPropertyInputPath(String subPropertyInputPath) {
136 this.subPropertyInputPath = subPropertyInputPath;
139 public String getInputPath() {
143 public void setInputPath(String inputPath) {
144 this.inputPath = inputPath;
147 public String getName() {
151 public void setName(String name) {
155 public String getValue() {
159 public void setValue(String value) {
164 public boolean isDefinition() {
168 public void setDefinition(boolean definition) {
169 this.definition = definition;
172 public String getType() {
176 public String getDefaultValue() {
180 public void setDefaultValue(String defaultValue) {
181 this.defaultValue = defaultValue;
184 public void setType(String type) {
188 public Boolean isRequired() {
192 public void setRequired(Boolean required) {
193 this.required = required;
196 public String getDescription() {
200 public void setDescription(String description) {
201 this.description = description;
204 public boolean isPassword() {
208 public void setPassword(boolean password) {
209 this.password = password;
212 public String getUniqueId() {
216 public void setUniqueId(String uniqueId) {
217 this.uniqueId = uniqueId;
220 public SchemaDefinition getSchema() {
224 public void setSchema(SchemaDefinition entrySchema) {
225 this.schema = entrySchema;
228 public String getSchemaType() {
229 if (schema != null && schema.getProperty() != null) {
230 return schema.getProperty().getType();
235 public PropertyDataDefinition getSchemaProperty() {
236 if (schema != null) {
237 return schema.getProperty();
243 public String getLabel() {
247 public void setLabel(String label) {
251 public Boolean isHidden() {
255 public void setHidden(Boolean hidden) {
256 this.hidden = hidden;
259 public Boolean isImmutable() {
263 public void setImmutable(Boolean immutable) {
264 this.immutable = immutable;
267 public String getParentUniqueId() {
271 public void setParentUniqueId(String parentUniqueId) {
272 setOwnerId(parentUniqueId);
275 public List<GetInputValueDataDefinition> getGetInputValues() {
276 return getInputValues;
279 public void setGetInputValues(List<GetInputValueDataDefinition> getInputValues) {
280 this.getInputValues = getInputValues;
283 public List<GetPolicyValueDataDefinition> safeGetGetPolicyValues() {
284 return CollectionUtils.isEmpty(getPolicyValues) ? new ArrayList<>() : getPolicyValues;
287 public List<GetPolicyValueDataDefinition> getGetPolicyValues() {
288 return getPolicyValues;
291 public void setGetPolicyValues(List<GetPolicyValueDataDefinition> getPolicyValues) {
292 this.getPolicyValues = getPolicyValues;
295 public String getStatus() {
299 public void setStatus(String status) {
300 this.status = status;
303 public String getInputId() {
307 public void setInputId(String inputId) {
308 this.inputId = inputId;
311 public String getInstanceUniqueId() {
312 return instanceUniqueId;
315 public void setInstanceUniqueId(String instanceUniqueId) {
316 this.instanceUniqueId = instanceUniqueId;
319 public String getPropertyId() {
323 public void setPropertyId(String propertyId) {
324 this.propertyId = propertyId;
327 public Boolean getIsDeclaredListInput() {
328 return isDeclaredListInput;
331 public void setIsDeclaredListInput(Boolean isDeclaredListInput) {
332 this.isDeclaredListInput = isDeclaredListInput;
336 public String toString() {
337 return "PropertyDataDefinition [uniqueId=" + uniqueId + ", type=" + type + ", required=" + required + ", definition=" + definition + ", defaultValue=" + defaultValue + ", description=" + description + ", schema=" + schema + ", password="
338 + password + ", name=" + name + ", value=" + value + ", label=" + label + ", hidden=" + hidden + ", immutable=" + immutable + ", inputPath=" + inputPath + ", status=" + status + ", inputId=" + inputId + ", instanceUniqueId="
339 + instanceUniqueId + ", propertyId=" + propertyId + ", parentUniqueId=" + parentUniqueId + ", getInputValues=" + getInputValues + ", isDeclaredListInput=" + isDeclaredListInput
340 + ", parentPropertyType=" + parentPropertyType
341 + ", subPropertyInputPath=" + subPropertyInputPath +"]";
345 public int hashCode() {
346 final int prime = 31;
348 result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
349 result = prime * result + (definition ? 1231 : 1237);
350 result = prime * result + ((description == null) ? 0 : description.hashCode());
351 result = prime * result + (password ? 1231 : 1237);
352 result = prime * result + ((required == null) ? 0 : required.hashCode());
353 result = prime * result + ((schema == null) ? 0 : schema.hashCode());
354 result = prime * result + ((type == null) ? 0 : type.hashCode());
355 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
356 result = prime * result + ((parentUniqueId == null) ? 0 : parentUniqueId.hashCode());
357 result = prime * result + ((status == null) ? 0 : status.hashCode());
358 result = prime * result + ((isDeclaredListInput == null) ? 0 : isDeclaredListInput.hashCode());
362 public boolean typeEquals(Object obj) {
369 if (getClass() != obj.getClass()) {
372 PropertyDataDefinition other = (PropertyDataDefinition) obj;
373 if (this.getType() == null) {
374 return other.getType() == null;
376 if (!this.type.equals(other.type)) {
379 String thisSchemaType = this.getSchemaType();
380 String otherSchemaType = other.getSchemaType();
381 if (thisSchemaType == null) {
382 return otherSchemaType == null;
384 return thisSchemaType.equals(otherSchemaType);
388 public boolean equals(Object obj) {
395 if (getClass() != obj.getClass()) {
398 PropertyDataDefinition other = (PropertyDataDefinition) obj;
399 if (defaultValue == null) {
400 if (other.defaultValue != null) {
403 } else if (!defaultValue.equals(other.defaultValue)) {
406 if (definition != other.definition) {
409 if (description == null) {
410 if (other.description != null) {
413 } else if (!description.equals(other.description)) {
416 if (password != other.password) {
419 if (required == null) {
420 if (other.required != null) {
423 } else if (!required.equals(other.required)) {
426 if (schema == null) {
427 if (other.schema != null) {
430 } else if (!schema.equals(other.schema)) {
434 if (other.type != null) {
437 } else if (!type.equals(other.type)) {
440 if (parentUniqueId == null) {
441 if (other.parentUniqueId != null) {
444 } else if (!parentUniqueId.equals(other.parentUniqueId)) {
447 if (uniqueId == null) {
448 if (other.uniqueId != null) {
451 } else if (!uniqueId.equals(other.uniqueId)) {
454 if (status == null) {
455 if (other.status != null) {
458 } else if (!status.equals(other.status)) {
461 if (isDeclaredListInput == null) {
462 if (other.isDeclaredListInput != null) {
465 } else if (!isDeclaredListInput.equals(other.isDeclaredListInput)) {
472 public Object getToscaPresentationValue(JsonPresentationFields field) {
489 return super.getToscaPresentationValue(field);
494 public void setToscaPresentationValue(JsonPresentationFields name, Object value) {
497 setName((String)value);
500 setUniqueId((String)value);
503 setPassword((Boolean)value);
506 setType((String)value);
509 setDefinition((Boolean)value);
512 setValue((String)value);
515 setDefaultValue((String)value);
518 super.setToscaPresentationValue(name, value);
523 private <T extends ToscaDataDefinition> boolean compareSchemaType(T other) {
524 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType().equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
528 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
529 if (this.getType() != null &&
530 this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE)) &&
531 compareSchemaType(other)) {
532 other.setOwnerId(getOwnerId());
533 if (allowDefaultValueOverride && getDefaultValue() != null && !getDefaultValue().isEmpty()) {
534 other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());
541 public void convertPropertyDataToInstancePropertyData() {
543 defaultValue = value;
547 public boolean isGetInputProperty() {
548 return this.getGetInputValues() != null && !this.getGetInputValues().isEmpty();
551 public void setAnnotations(List<Annotation> newAnnotations) {
552 Set<Annotation> annotationSet = isNotEmpty(newAnnotations) ? new HashSet<>(newAnnotations) : new HashSet<>();
553 //We would to prioritize the new valid annotations over the old ones if the same one existed.
554 if(this.annotations != null){
555 for(Annotation oldInputAnnotation : this.annotations)
556 annotationSet.add(oldInputAnnotation);
559 this.annotations = new ArrayList<>(annotationSet);
560 setToscaPresentationValue(JsonPresentationFields.ANNOTATIONS, this.annotations);
563 public List<Annotation> getAnnotations() {
564 return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);