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.HashMap;
29 import java.util.HashSet;
30 import java.util.List;
34 import lombok.EqualsAndHashCode;
36 import org.apache.commons.collections.MapUtils;
37 import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
39 @EqualsAndHashCode(callSuper = false)
41 public class PropertyDataDefinition extends ToscaDataDefinition {
43 protected boolean definition = false;
44 protected Boolean hidden = Boolean.FALSE;
45 private String uniqueId;
46 // "boolean", "string", "float", "integer", "version" })
48 private Boolean required = Boolean.FALSE;
49 private String defaultValue;
50 private String description;
51 private SchemaDefinition schema;
52 private boolean password;
56 private Boolean immutable = Boolean.FALSE;
57 private Boolean mappedToComponentProperty = Boolean.TRUE;
58 private String inputPath;
59 private String status;
60 private String inputId;
61 private String instanceUniqueId;
62 private String propertyId;
63 private String parentPropertyType;
64 private String subPropertyInputPath;
65 private List<Annotation> annotations;
67 * The resource id which this property belongs to
69 private String parentUniqueId;
70 private List<GetInputValueDataDefinition> getInputValues;
71 private Boolean isDeclaredListInput = Boolean.FALSE;
72 private List<GetPolicyValueDataDefinition> getPolicyValues;
73 private List<String> propertyConstraints;
74 private Map<String, String> metadata;
76 public PropertyDataDefinition() {
80 public PropertyDataDefinition(Map<String, Object> pr) {
84 public PropertyDataDefinition(PropertyDataDefinition propertyDataDefinition) {
86 this.setUniqueId(propertyDataDefinition.getUniqueId());
87 this.setRequired(propertyDataDefinition.isRequired());
88 this.setDefaultValue(propertyDataDefinition.getDefaultValue());
89 this.setDefinition(propertyDataDefinition.getDefinition());
90 this.setDescription(propertyDataDefinition.getDescription());
91 this.setSchema(propertyDataDefinition.getSchema());
92 this.setPassword(propertyDataDefinition.isPassword());
93 this.setType(propertyDataDefinition.getType());
94 this.setName(propertyDataDefinition.getName());
95 this.setValue(propertyDataDefinition.getValue());
96 this.setRequired(propertyDataDefinition.isRequired());
97 this.setHidden(propertyDataDefinition.isHidden());
98 this.setLabel(propertyDataDefinition.getLabel());
99 this.setImmutable(propertyDataDefinition.isImmutable());
100 this.setMappedToComponentProperty(propertyDataDefinition.isMappedToComponentProperty());
101 this.setParentUniqueId(propertyDataDefinition.getParentUniqueId());
102 this.setOwnerId(propertyDataDefinition.getOwnerId());
103 this.setGetInputValues(propertyDataDefinition.getGetInputValues());
104 this.setGetPolicyValues(propertyDataDefinition.getGetPolicyValues());
105 this.setInputPath(propertyDataDefinition.getInputPath());
106 this.setStatus(propertyDataDefinition.getStatus());
107 this.setInputId(propertyDataDefinition.getInputId());
108 this.setInstanceUniqueId(propertyDataDefinition.getInstanceUniqueId());
109 this.setPropertyId(propertyDataDefinition.getPropertyId());
110 this.parentPropertyType = propertyDataDefinition.getParentPropertyType();
111 this.subPropertyInputPath = propertyDataDefinition.getSubPropertyInputPath();
112 if (isNotEmpty(propertyDataDefinition.annotations)) {
113 this.setAnnotations(propertyDataDefinition.annotations);
115 if (MapUtils.isNotEmpty(propertyDataDefinition.getMetadata())) {
116 setMetadata(new HashMap<>(propertyDataDefinition.getMetadata()));
118 if (isNotEmpty(propertyDataDefinition.getPropertyConstraints())) {
119 setPropertyConstraints(new ArrayList<>(propertyDataDefinition.getPropertyConstraints()));
121 this.setIsDeclaredListInput(propertyDataDefinition.getIsDeclaredListInput());
125 public boolean isDefinition() {
129 public boolean getDefinition() {
133 public Boolean isRequired() {
137 public void setSchemaType(String schemaType) {
138 if (schema != null && schema.getProperty() != null) {
139 schema.getProperty().setType(schemaType);
143 public String getSchemaType() {
144 if (schema != null && schema.getProperty() != null) {
145 return schema.getProperty().getType();
150 public PropertyDataDefinition getSchemaProperty() {
151 if (schema != null) {
152 return schema.getProperty();
157 public Boolean isHidden() {
161 public Boolean isImmutable() {
165 public Boolean isMappedToComponentProperty() {
166 return mappedToComponentProperty;
169 public String getParentUniqueId() {
173 public void setParentUniqueId(String parentUniqueId) {
174 setOwnerId(parentUniqueId);
177 public List<GetPolicyValueDataDefinition> safeGetGetPolicyValues() {
178 return CollectionUtils.isEmpty(getPolicyValues) ? new ArrayList<>() : getPolicyValues;
181 public boolean typeEquals(Object obj) {
188 if (getClass() != obj.getClass()) {
191 PropertyDataDefinition other = (PropertyDataDefinition) obj;
192 if (this.getType() == null) {
193 return other.getType() == null;
195 if (!this.type.equals(other.type)) {
198 String thisSchemaType = this.getSchemaType();
199 String otherSchemaType = other.getSchemaType();
200 if (thisSchemaType == null) {
201 return otherSchemaType == null;
203 return thisSchemaType.equals(otherSchemaType);
207 public Object getToscaPresentationValue(JsonPresentationFields field) {
224 return super.getToscaPresentationValue(field);
229 public void setToscaPresentationValue(JsonPresentationFields name, Object value) {
232 setName((String) value);
235 setUniqueId((String) value);
238 setPassword((Boolean) value);
241 setType((String) value);
244 setDefinition((Boolean) value);
247 setValue((String) value);
250 setDefaultValue((String) value);
253 super.setToscaPresentationValue(name, value);
258 private <T extends ToscaDataDefinition> boolean compareSchemaType(T other) {
259 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType()
260 .equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
264 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
265 if (this.getType() != null && this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE)) && compareSchemaType(
267 other.setOwnerId(getOwnerId());
268 if (allowDefaultValueOverride && getDefaultValue() != null && !getDefaultValue().isEmpty()) {
269 other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());
276 public void convertPropertyDataToInstancePropertyData() {
278 defaultValue = value;
282 public boolean isGetInputProperty() {
283 return this.getGetInputValues() != null && !this.getGetInputValues().isEmpty();
286 public void setAnnotations(List<Annotation> newAnnotations) {
287 Set<Annotation> annotationSet = isNotEmpty(newAnnotations) ? new HashSet<>(newAnnotations) : new HashSet<>();
288 //We would to prioritize the new valid annotations over the old ones if the same one existed.
289 if (this.annotations != null) {
290 annotationSet.addAll(this.annotations);
292 this.annotations = new ArrayList<>(annotationSet);
293 setToscaPresentationValue(JsonPresentationFields.ANNOTATIONS, this.annotations);
296 public List<Annotation> getAnnotations() {
297 return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);