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 private String uniqueId;
45 // "boolean", "string", "float", "integer", "version" })
48 private Boolean required = Boolean.FALSE;
50 protected boolean definition = false;
52 private String defaultValue;
54 private String description;
56 private SchemaDefinition schema;
58 private boolean password;
65 protected Boolean hidden = Boolean.FALSE;
66 private Boolean immutable = Boolean.FALSE;
68 private String inputPath;
69 private String status;
70 private String inputId;
71 private String instanceUniqueId;
72 private String propertyId;
73 private String parentPropertyType;
74 private String subPropertyInputPath;
76 private List<Annotation> annotations;
78 * The resource id which this property belongs to
80 private String parentUniqueId;
82 private List<GetInputValueDataDefinition> getInputValues;
84 private Boolean isDeclaredListInput = Boolean.FALSE;
86 private List<GetPolicyValueDataDefinition> getPolicyValues;
88 private List<String> propertyConstraints;
90 private Map<String, String> metadata;
92 public PropertyDataDefinition() {
96 public PropertyDataDefinition(Map<String, Object> pr) {
100 public PropertyDataDefinition(PropertyDataDefinition propertyDataDefinition) {
102 this.setUniqueId(propertyDataDefinition.getUniqueId());
103 this.setRequired(propertyDataDefinition.isRequired());
104 this.setDefaultValue(propertyDataDefinition.getDefaultValue());
105 this.setDefinition(propertyDataDefinition.getDefinition());
106 this.setDescription(propertyDataDefinition.getDescription());
107 this.setSchema(propertyDataDefinition.getSchema());
108 this.setPassword(propertyDataDefinition.isPassword());
109 this.setType(propertyDataDefinition.getType());
110 this.setName(propertyDataDefinition.getName());
111 this.setValue(propertyDataDefinition.getValue());
112 this.setRequired(propertyDataDefinition.isRequired());
113 this.setHidden(propertyDataDefinition.isHidden());
114 this.setLabel(propertyDataDefinition.getLabel());
115 this.setImmutable(propertyDataDefinition.isImmutable());
116 this.setParentUniqueId(propertyDataDefinition.getParentUniqueId());
117 this.setOwnerId(propertyDataDefinition.getOwnerId());
118 this.setGetInputValues(propertyDataDefinition.getGetInputValues());
119 this.setGetPolicyValues(propertyDataDefinition.getGetPolicyValues());
120 this.setInputPath(propertyDataDefinition.getInputPath());
121 this.setStatus(propertyDataDefinition.getStatus());
122 this.setInputId(propertyDataDefinition.getInputId());
123 this.setInstanceUniqueId(propertyDataDefinition.getInstanceUniqueId());
124 this.setPropertyId(propertyDataDefinition.getPropertyId());
125 this.parentPropertyType = propertyDataDefinition.getParentPropertyType();
126 this.subPropertyInputPath = propertyDataDefinition.getSubPropertyInputPath();
127 if (isNotEmpty(propertyDataDefinition.annotations)) {
128 this.setAnnotations(propertyDataDefinition.annotations);
130 if (MapUtils.isNotEmpty(propertyDataDefinition.getMetadata())) {
131 setMetadata(new HashMap<>(propertyDataDefinition.getMetadata()));
133 if(isNotEmpty(propertyDataDefinition.getPropertyConstraints())){
134 setPropertyConstraints(new ArrayList<>(propertyDataDefinition.getPropertyConstraints()));
136 this.setIsDeclaredListInput(propertyDataDefinition.getIsDeclaredListInput());
140 public boolean isDefinition() {
144 public boolean getDefinition() {
148 public Boolean isRequired() {
152 public void setSchemaType(String schemaType) {
153 if (schema != null && schema.getProperty() != null) {
154 schema.getProperty().setType(schemaType);
158 public String getSchemaType() {
159 if (schema != null && schema.getProperty() != null) {
160 return schema.getProperty().getType();
165 public PropertyDataDefinition getSchemaProperty() {
166 if (schema != null) {
167 return schema.getProperty();
173 public Boolean isHidden() {
177 public Boolean isImmutable() {
181 public String getParentUniqueId() {
185 public void setParentUniqueId(String parentUniqueId) {
186 setOwnerId(parentUniqueId);
189 public List<GetPolicyValueDataDefinition> safeGetGetPolicyValues() {
190 return CollectionUtils.isEmpty(getPolicyValues) ? new ArrayList<>() : getPolicyValues;
193 public boolean typeEquals(Object obj) {
200 if (getClass() != obj.getClass()) {
203 PropertyDataDefinition other = (PropertyDataDefinition) obj;
204 if (this.getType() == null) {
205 return other.getType() == null;
207 if (!this.type.equals(other.type)) {
210 String thisSchemaType = this.getSchemaType();
211 String otherSchemaType = other.getSchemaType();
212 if (thisSchemaType == null) {
213 return otherSchemaType == null;
215 return thisSchemaType.equals(otherSchemaType);
219 public Object getToscaPresentationValue(JsonPresentationFields field) {
236 return super.getToscaPresentationValue(field);
241 public void setToscaPresentationValue(JsonPresentationFields name, Object value) {
244 setName((String) value);
247 setUniqueId((String) value);
250 setPassword((Boolean) value);
253 setType((String) value);
256 setDefinition((Boolean) value);
259 setValue((String) value);
262 setDefaultValue((String) value);
265 super.setToscaPresentationValue(name, value);
270 private <T extends ToscaDataDefinition> boolean compareSchemaType(T other) {
271 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType().equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
275 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
276 if (this.getType() != null
277 && this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE))
278 && compareSchemaType(other)) {
279 other.setOwnerId(getOwnerId());
280 if (allowDefaultValueOverride
281 && getDefaultValue() != null
282 && !getDefaultValue().isEmpty()) {
283 other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());
290 public void convertPropertyDataToInstancePropertyData() {
292 defaultValue = value;
296 public boolean isGetInputProperty() {
297 return this.getGetInputValues() != null && !this.getGetInputValues().isEmpty();
300 public void setAnnotations(List<Annotation> newAnnotations) {
301 Set<Annotation> annotationSet = isNotEmpty(newAnnotations) ? new HashSet<>(newAnnotations) : new HashSet<>();
302 //We would to prioritize the new valid annotations over the old ones if the same one existed.
303 if (this.annotations != null) {
304 annotationSet.addAll(this.annotations);
307 this.annotations = new ArrayList<>(annotationSet);
308 setToscaPresentationValue(JsonPresentationFields.ANNOTATIONS, this.annotations);
311 public List<Annotation> getAnnotations() {
312 return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);