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.apache.commons.collections.CollectionUtils;
24 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
25 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
27 import java.util.ArrayList;
28 import java.util.HashSet;
29 import java.util.List;
33 import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
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 private List<String> propertyConstraints;
84 public PropertyDataDefinition() {
88 public PropertyDataDefinition(Map<String, Object> pr) {
92 public PropertyDataDefinition(PropertyDataDefinition propertyDataDefinition) {
94 this.setUniqueId(propertyDataDefinition.getUniqueId());
95 this.setRequired(propertyDataDefinition.isRequired());
96 this.setDefaultValue(propertyDataDefinition.getDefaultValue());
97 this.setDefinition(propertyDataDefinition.getDefinition());
98 this.setDescription(propertyDataDefinition.getDescription());
99 this.setSchema(propertyDataDefinition.getSchema());
100 this.setPassword(propertyDataDefinition.isPassword());
101 this.setType(propertyDataDefinition.getType());
102 this.setName(propertyDataDefinition.getName());
103 this.setValue(propertyDataDefinition.getValue());
104 this.setRequired(propertyDataDefinition.isRequired());
105 this.setHidden(propertyDataDefinition.isHidden());
106 this.setLabel(propertyDataDefinition.getLabel());
107 this.setImmutable(propertyDataDefinition.isImmutable());
108 this.setParentUniqueId(propertyDataDefinition.getParentUniqueId());
109 this.setOwnerId(propertyDataDefinition.getOwnerId());
110 this.setGetInputValues(propertyDataDefinition.getGetInputValues());
111 this.setGetPolicyValues(propertyDataDefinition.getGetPolicyValues());
112 this.setInputPath(propertyDataDefinition.getInputPath());
113 this.setStatus(propertyDataDefinition.getStatus());
114 this.setInputId(propertyDataDefinition.getInputId());
115 this.setInstanceUniqueId(propertyDataDefinition.getInstanceUniqueId());
116 this.setPropertyId(propertyDataDefinition.getPropertyId());
117 this.parentPropertyType = propertyDataDefinition.getParentPropertyType();
118 this.subPropertyInputPath = propertyDataDefinition.getSubPropertyInputPath();
119 if (isNotEmpty(propertyDataDefinition.annotations)) {
120 this.setAnnotations(propertyDataDefinition.annotations);
122 if(isNotEmpty(propertyDataDefinition.getPropertyConstraints())){
123 setPropertyConstraints(new ArrayList<>(propertyDataDefinition.getPropertyConstraints()));
125 this.setIsDeclaredListInput(propertyDataDefinition.getIsDeclaredListInput());
128 public String getParentPropertyType() {
129 return parentPropertyType;
132 public void setParentPropertyType(String parentPropertyType) {
133 this.parentPropertyType = parentPropertyType;
136 public String getSubPropertyInputPath() {
137 return subPropertyInputPath;
140 public void setSubPropertyInputPath(String subPropertyInputPath) {
141 this.subPropertyInputPath = subPropertyInputPath;
144 public String getInputPath() {
148 public void setInputPath(String inputPath) {
149 this.inputPath = inputPath;
152 public String getName() {
156 public void setName(String name) {
160 public String getValue() {
164 public void setValue(String value) {
169 public boolean isDefinition() {
173 public void setDefinition(boolean definition) {
174 this.definition = definition;
177 public boolean getDefinition() {
181 public String getType() {
185 public String getDefaultValue() {
189 public void setDefaultValue(String defaultValue) {
190 this.defaultValue = defaultValue;
193 public void setType(String type) {
197 public Boolean isRequired() {
201 public void setRequired(Boolean required) {
202 this.required = required;
205 public String getDescription() {
209 public void setDescription(String description) {
210 this.description = description;
213 public boolean isPassword() {
217 public void setPassword(boolean password) {
218 this.password = password;
221 public String getUniqueId() {
225 public void setUniqueId(String uniqueId) {
226 this.uniqueId = uniqueId;
229 public SchemaDefinition getSchema() {
233 public void setSchemaType(String schemaType) {
234 if (schema != null && schema.getProperty() != null) {
235 schema.getProperty().setType(schemaType);
239 public void setSchema(SchemaDefinition entrySchema) {
240 this.schema = entrySchema;
243 public String getSchemaType() {
244 if (schema != null && schema.getProperty() != null) {
245 return schema.getProperty().getType();
250 public PropertyDataDefinition getSchemaProperty() {
251 if (schema != null) {
252 return schema.getProperty();
258 public String getLabel() {
262 public void setLabel(String label) {
266 public Boolean isHidden() {
270 public void setHidden(Boolean hidden) {
271 this.hidden = hidden;
274 public Boolean isImmutable() {
278 public void setImmutable(Boolean immutable) {
279 this.immutable = immutable;
282 public String getParentUniqueId() {
286 public void setParentUniqueId(String parentUniqueId) {
287 setOwnerId(parentUniqueId);
290 public List<GetInputValueDataDefinition> getGetInputValues() {
291 return getInputValues;
294 public void setGetInputValues(List<GetInputValueDataDefinition> getInputValues) {
295 this.getInputValues = getInputValues;
298 public List<GetPolicyValueDataDefinition> safeGetGetPolicyValues() {
299 return CollectionUtils.isEmpty(getPolicyValues) ? new ArrayList<>() : getPolicyValues;
302 public List<GetPolicyValueDataDefinition> getGetPolicyValues() {
303 return getPolicyValues;
306 public void setGetPolicyValues(List<GetPolicyValueDataDefinition> getPolicyValues) {
307 this.getPolicyValues = getPolicyValues;
310 public String getStatus() {
314 public void setStatus(String status) {
315 this.status = status;
318 public String getInputId() {
322 public void setInputId(String inputId) {
323 this.inputId = inputId;
326 public String getInstanceUniqueId() {
327 return instanceUniqueId;
330 public void setInstanceUniqueId(String instanceUniqueId) {
331 this.instanceUniqueId = instanceUniqueId;
334 public String getPropertyId() {
338 public void setPropertyId(String propertyId) {
339 this.propertyId = propertyId;
342 public Boolean getIsDeclaredListInput() {
343 return isDeclaredListInput;
346 public void setIsDeclaredListInput(Boolean isDeclaredListInput) {
347 this.isDeclaredListInput = isDeclaredListInput;
351 public String toString() {
352 return "PropertyDataDefinition [uniqueId=" + uniqueId + ", type=" + type + ", required=" + required + ", definition=" + definition + ", defaultValue=" + defaultValue + ", description=" + description + ", schema=" + schema + ", password="
353 + password + ", name=" + name + ", value=" + value + ", label=" + label + ", hidden=" + hidden + ", immutable=" + immutable + ", inputPath=" + inputPath + ", status=" + status + ", inputId=" + inputId + ", instanceUniqueId="
354 + instanceUniqueId + ", propertyId=" + propertyId + ", parentUniqueId=" + parentUniqueId + ", getInputValues=" + getInputValues + ", isDeclaredListInput=" + isDeclaredListInput
355 + ", parentPropertyType=" + parentPropertyType
356 + ", subPropertyInputPath=" + subPropertyInputPath + "]";
360 public int hashCode() {
361 final int hashingValueDefinition = 1231;
362 final int hashingValueNoDefinition = 1237;
363 final int prime = 31;
365 result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
366 result = prime * result + (definition ? hashingValueDefinition : hashingValueNoDefinition);
367 result = prime * result + ((description == null) ? 0 : description.hashCode());
368 result = prime * result + (password ? hashingValueDefinition : hashingValueNoDefinition);
369 result = prime * result + ((required == null) ? 0 : required.hashCode());
370 result = prime * result + ((schema == null) ? 0 : schema.hashCode());
371 result = prime * result + ((type == null) ? 0 : type.hashCode());
372 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
373 result = prime * result + ((parentUniqueId == null) ? 0 : parentUniqueId.hashCode());
374 result = prime * result + ((status == null) ? 0 : status.hashCode());
375 result = prime * result + ((isDeclaredListInput == null) ? 0 : isDeclaredListInput.hashCode());
379 public boolean typeEquals(Object obj) {
386 if (getClass() != obj.getClass()) {
389 PropertyDataDefinition other = (PropertyDataDefinition) obj;
390 if (this.getType() == null) {
391 return other.getType() == null;
393 if (!this.type.equals(other.type)) {
396 String thisSchemaType = this.getSchemaType();
397 String otherSchemaType = other.getSchemaType();
398 if (thisSchemaType == null) {
399 return otherSchemaType == null;
401 return thisSchemaType.equals(otherSchemaType);
405 public boolean equals(Object obj) {
412 if (getClass() != obj.getClass()) {
415 PropertyDataDefinition other = (PropertyDataDefinition) obj;
416 if (defaultValue == null) {
417 if (other.defaultValue != null) {
420 } else if (!defaultValue.equals(other.defaultValue)) {
423 if (definition != other.definition) {
426 if (description == null) {
427 if (other.description != null) {
430 } else if (!description.equals(other.description)) {
433 if (password != other.password) {
436 if (required == null) {
437 if (other.required != null) {
440 } else if (!required.equals(other.required)) {
443 if (schema == null) {
444 if (other.schema != null) {
447 } else if (!schema.equals(other.schema)) {
451 if (other.type != null) {
454 } else if (!type.equals(other.type)) {
457 if (parentUniqueId == null) {
458 if (other.parentUniqueId != null) {
461 } else if (!parentUniqueId.equals(other.parentUniqueId)) {
464 if (uniqueId == null) {
465 if (other.uniqueId != null) {
468 } else if (!uniqueId.equals(other.uniqueId)) {
471 if (status == null) {
472 if (other.status != null) {
475 } else if (!status.equals(other.status)) {
478 if (isDeclaredListInput == null) {
479 if (other.isDeclaredListInput != null) {
482 } else if (!isDeclaredListInput.equals(other.isDeclaredListInput)) {
489 public Object getToscaPresentationValue(JsonPresentationFields field) {
506 return super.getToscaPresentationValue(field);
511 public void setToscaPresentationValue(JsonPresentationFields name, Object value) {
514 setName((String) value);
517 setUniqueId((String) value);
520 setPassword((Boolean) value);
523 setType((String) value);
526 setDefinition((Boolean) value);
529 setValue((String) value);
532 setDefaultValue((String) value);
535 super.setToscaPresentationValue(name, value);
540 private <T extends ToscaDataDefinition> boolean compareSchemaType(T other) {
541 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType().equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
545 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
546 if (this.getType() != null
547 && this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE))
548 && compareSchemaType(other)) {
549 other.setOwnerId(getOwnerId());
550 if (allowDefaultValueOverride
551 && getDefaultValue() != null
552 && !getDefaultValue().isEmpty()) {
553 other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());
560 public void convertPropertyDataToInstancePropertyData() {
562 defaultValue = value;
566 public boolean isGetInputProperty() {
567 return this.getGetInputValues() != null && !this.getGetInputValues().isEmpty();
570 public void setAnnotations(List<Annotation> newAnnotations) {
571 Set<Annotation> annotationSet = isNotEmpty(newAnnotations) ? new HashSet<>(newAnnotations) : new HashSet<>();
572 //We would to prioritize the new valid annotations over the old ones if the same one existed.
573 if (this.annotations != null) {
574 for (Annotation oldInputAnnotation : this.annotations) {
575 annotationSet.add(oldInputAnnotation);
579 this.annotations = new ArrayList<>(annotationSet);
580 setToscaPresentationValue(JsonPresentationFields.ANNOTATIONS, this.annotations);
583 public List<Annotation> getAnnotations() {
584 return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);
587 public List<String> getPropertyConstraints() {
588 return propertyConstraints;
591 public void setPropertyConstraints(List<String> constraints) {
592 this.propertyConstraints = constraints;