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.HashMap;
27 import java.util.HashSet;
28 import java.util.List;
32 import lombok.EqualsAndHashCode;
33 import org.apache.commons.collections.CollectionUtils;
34 import org.apache.commons.collections.MapUtils;
35 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
36 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
37 import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
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;
59 * @deprecated use {@link #toscaGetFunction#functionType} instead
62 private ToscaGetFunctionType toscaGetFunctionType;
63 private ToscaGetFunctionDataDefinition toscaGetFunction;
65 private String inputPath;
66 private String status;
67 private String inputId;
68 private String instanceUniqueId;
70 private String propertyId;
71 private String parentPropertyType;
72 private String subPropertyInputPath;
73 private List<Annotation> annotations;
75 * The resource id which this property belongs to
77 private String parentUniqueId;
78 private List<GetInputValueDataDefinition> getInputValues;
79 private Boolean isDeclaredListInput = Boolean.FALSE;
80 private List<GetPolicyValueDataDefinition> getPolicyValues;
81 private List<String> propertyConstraints;
82 private Map<String, String> metadata;
84 public PropertyDataDefinition() {
88 public PropertyDataDefinition(Map<String, Object> pr) {
92 public PropertyDataDefinition(final 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 if (propertyDataDefinition.getSchema() != null) {
100 this.setSchema(new SchemaDefinition(propertyDataDefinition.getSchema()));
102 this.setPassword(propertyDataDefinition.isPassword());
103 this.setType(propertyDataDefinition.getType());
104 this.setName(propertyDataDefinition.getName());
105 this.setValue(propertyDataDefinition.getValue());
106 this.setRequired(propertyDataDefinition.isRequired());
107 this.setHidden(propertyDataDefinition.isHidden());
108 this.setLabel(propertyDataDefinition.getLabel());
109 this.setImmutable(propertyDataDefinition.isImmutable());
110 this.setMappedToComponentProperty(propertyDataDefinition.isMappedToComponentProperty());
111 this.setParentUniqueId(propertyDataDefinition.getParentUniqueId());
112 this.setOwnerId(propertyDataDefinition.getOwnerId());
113 this.setGetInputValues(propertyDataDefinition.getGetInputValues());
114 this.setGetPolicyValues(propertyDataDefinition.getGetPolicyValues());
115 this.setInputPath(propertyDataDefinition.getInputPath());
116 this.setStatus(propertyDataDefinition.getStatus());
117 this.setInputId(propertyDataDefinition.getInputId());
118 this.setInstanceUniqueId(propertyDataDefinition.getInstanceUniqueId());
119 this.setModel(propertyDataDefinition.getModel());
120 this.setPropertyId(propertyDataDefinition.getPropertyId());
121 this.setToscaGetFunctionType(propertyDataDefinition.getToscaGetFunctionType());
122 this.setToscaGetFunction(propertyDataDefinition.getToscaGetFunction());
123 this.parentPropertyType = propertyDataDefinition.getParentPropertyType();
124 this.subPropertyInputPath = propertyDataDefinition.getSubPropertyInputPath();
125 if (isNotEmpty(propertyDataDefinition.annotations)) {
126 this.setAnnotations(propertyDataDefinition.annotations);
128 if (MapUtils.isNotEmpty(propertyDataDefinition.getMetadata())) {
129 setMetadata(new HashMap<>(propertyDataDefinition.getMetadata()));
131 if (isNotEmpty(propertyDataDefinition.getPropertyConstraints())) {
132 setPropertyConstraints(new ArrayList<>(propertyDataDefinition.getPropertyConstraints()));
134 this.setIsDeclaredListInput(propertyDataDefinition.getIsDeclaredListInput());
138 public boolean isDefinition() {
142 public boolean getDefinition() {
146 public Boolean isRequired() {
150 public void setSchemaType(String schemaType) {
151 if (schema != null && schema.getProperty() != null) {
152 schema.getProperty().setType(schemaType);
156 public String getSchemaType() {
157 if (schema != null && schema.getProperty() != null) {
158 return schema.getProperty().getType();
163 public PropertyDataDefinition getSchemaProperty() {
164 if (schema != null) {
165 return schema.getProperty();
170 public ToscaGetFunctionType getToscaGetFunctionType() {
171 if (toscaGetFunction != null) {
172 return toscaGetFunction.getFunctionType();
174 return toscaGetFunctionType;
177 public Boolean isHidden() {
181 public Boolean isImmutable() {
185 public Boolean isMappedToComponentProperty() {
186 return mappedToComponentProperty;
189 public String getParentUniqueId() {
193 public void setParentUniqueId(String parentUniqueId) {
194 setOwnerId(parentUniqueId);
197 public List<GetPolicyValueDataDefinition> safeGetGetPolicyValues() {
198 return CollectionUtils.isEmpty(getPolicyValues) ? new ArrayList<>() : getPolicyValues;
201 public boolean typeEquals(Object obj) {
208 if (getClass() != obj.getClass()) {
211 PropertyDataDefinition other = (PropertyDataDefinition) obj;
212 if (this.getType() == null) {
213 return other.getType() == null;
215 if (!this.type.equals(other.type)) {
218 String thisSchemaType = this.getSchemaType();
219 String otherSchemaType = other.getSchemaType();
220 if (thisSchemaType == null) {
221 return otherSchemaType == null;
223 return thisSchemaType.equals(otherSchemaType);
227 public Object getToscaPresentationValue(JsonPresentationFields field) {
244 return super.getToscaPresentationValue(field);
249 public void setToscaPresentationValue(JsonPresentationFields name, Object value) {
252 setName((String) value);
255 setUniqueId((String) value);
258 setPassword((Boolean) value);
261 setType((String) value);
264 setDefinition((Boolean) value);
267 setValue((String) value);
270 setDefaultValue((String) value);
273 super.setToscaPresentationValue(name, value);
278 private <T extends ToscaDataDefinition> boolean compareSchemaType(T other) {
279 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType()
280 .equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
284 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
285 if (this.getType() != null && this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE)) && compareSchemaType(
287 other.setOwnerId(getOwnerId());
288 if (allowDefaultValueOverride && getDefaultValue() != null && !getDefaultValue().isEmpty()) {
289 other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());
296 public void convertPropertyDataToInstancePropertyData() {
298 defaultValue = value;
302 public boolean isGetInputProperty() {
303 return this.getGetInputValues() != null && !this.getGetInputValues().isEmpty();
306 public void setAnnotations(List<Annotation> newAnnotations) {
307 Set<Annotation> annotationSet = isNotEmpty(newAnnotations) ? new HashSet<>(newAnnotations) : new HashSet<>();
308 //We would to prioritize the new valid annotations over the old ones if the same one existed.
309 if (this.annotations != null) {
310 annotationSet.addAll(this.annotations);
312 this.annotations = new ArrayList<>(annotationSet);
313 setToscaPresentationValue(JsonPresentationFields.ANNOTATIONS, this.annotations);
316 public List<Annotation> getAnnotations() {
317 return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);
320 public boolean isGetFunction() {
321 return this.toscaGetFunctionType != null || this.toscaGetFunction != null;
324 public boolean hasGetFunction() {
325 return this.toscaGetFunction != null;