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 com.fasterxml.jackson.annotation.JsonIgnoreProperties;
26 import java.util.ArrayList;
27 import java.util.HashMap;
28 import java.util.HashSet;
29 import java.util.List;
33 import lombok.EqualsAndHashCode;
34 import org.apache.commons.collections.CollectionUtils;
35 import org.apache.commons.collections.MapUtils;
36 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
37 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
38 import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
40 @EqualsAndHashCode(callSuper = false)
42 public class PropertyDataDefinition extends ToscaDataDefinition {
44 private boolean definition = false;
45 private Boolean hidden = Boolean.FALSE;
46 private String uniqueId;
47 // "boolean", "string", "float", "integer", "version" })
49 private Boolean required = Boolean.FALSE;
50 private String defaultValue;
51 private String description;
52 private SchemaDefinition schema;
53 private boolean password;
57 private Boolean immutable = Boolean.FALSE;
58 private Boolean mappedToComponentProperty = Boolean.TRUE;
60 * @deprecated use {@link #toscaFunction} instead
63 private ToscaGetFunctionType toscaGetFunctionType;
65 * @deprecated use {@link #toscaFunction} instead
68 private ToscaGetFunctionDataDefinition toscaGetFunction;
69 private ToscaFunction toscaFunction;
71 private String inputPath;
72 private String status;
73 private String inputId;
74 private String instanceUniqueId;
76 private String propertyId;
77 private String parentPropertyType;
78 private String subPropertyInputPath;
79 private List<Annotation> annotations;
80 private List<GetInputValueDataDefinition> getInputValues;
81 private Boolean isDeclaredListInput = Boolean.FALSE;
82 private List<GetPolicyValueDataDefinition> getPolicyValues;
83 private List<String> propertyConstraints;
84 private Map<String, String> metadata;
85 private boolean userCreated;
87 public PropertyDataDefinition() {
91 public PropertyDataDefinition(Map<String, Object> pr) {
95 public PropertyDataDefinition(final PropertyDataDefinition propertyDataDefinition) {
97 this.setUniqueId(propertyDataDefinition.getUniqueId());
98 this.setRequired(propertyDataDefinition.isRequired());
99 this.setDefaultValue(propertyDataDefinition.getDefaultValue());
100 this.setDefinition(propertyDataDefinition.getDefinition());
101 this.setDescription(propertyDataDefinition.getDescription());
102 if (propertyDataDefinition.getSchema() != null) {
103 this.setSchema(new SchemaDefinition(propertyDataDefinition.getSchema()));
105 this.setPassword(propertyDataDefinition.isPassword());
106 this.setType(propertyDataDefinition.getType());
107 this.setName(propertyDataDefinition.getName());
108 this.setValue(propertyDataDefinition.getValue());
109 this.setRequired(propertyDataDefinition.isRequired());
110 this.setHidden(propertyDataDefinition.isHidden());
111 this.setLabel(propertyDataDefinition.getLabel());
112 this.setImmutable(propertyDataDefinition.isImmutable());
113 this.setMappedToComponentProperty(propertyDataDefinition.isMappedToComponentProperty());
114 this.setParentUniqueId(propertyDataDefinition.getParentUniqueId());
115 this.setOwnerId(propertyDataDefinition.getOwnerId());
116 this.setGetInputValues(propertyDataDefinition.getGetInputValues());
117 this.setGetPolicyValues(propertyDataDefinition.getGetPolicyValues());
118 this.setInputPath(propertyDataDefinition.getInputPath());
119 this.setStatus(propertyDataDefinition.getStatus());
120 this.setInputId(propertyDataDefinition.getInputId());
121 this.setInstanceUniqueId(propertyDataDefinition.getInstanceUniqueId());
122 this.setModel(propertyDataDefinition.getModel());
123 this.setPropertyId(propertyDataDefinition.getPropertyId());
124 this.setToscaGetFunction(propertyDataDefinition.getToscaGetFunction());
125 this.setToscaGetFunctionType(propertyDataDefinition.getToscaGetFunctionType());
126 this.setToscaFunction(propertyDataDefinition.getToscaFunction());
127 this.parentPropertyType = propertyDataDefinition.getParentPropertyType();
128 this.subPropertyInputPath = propertyDataDefinition.getSubPropertyInputPath();
129 if (isNotEmpty(propertyDataDefinition.annotations)) {
130 this.setAnnotations(propertyDataDefinition.annotations);
132 if (MapUtils.isNotEmpty(propertyDataDefinition.getMetadata())) {
133 setMetadata(new HashMap<>(propertyDataDefinition.getMetadata()));
135 if (isNotEmpty(propertyDataDefinition.getPropertyConstraints())) {
136 setPropertyConstraints(new ArrayList<>(propertyDataDefinition.getPropertyConstraints()));
138 this.setIsDeclaredListInput(propertyDataDefinition.getIsDeclaredListInput());
139 this.setUserCreated(propertyDataDefinition.isUserCreated());
143 public boolean isDefinition() {
147 public boolean getDefinition() {
151 public Boolean isRequired() {
155 public void setSchemaType(String schemaType) {
156 if (schema != null && schema.getProperty() != null) {
157 schema.getProperty().setType(schemaType);
161 public String getSchemaType() {
162 if (schema != null && schema.getProperty() != null) {
163 return schema.getProperty().getType();
168 public PropertyDataDefinition getSchemaProperty() {
169 if (schema != null) {
170 return schema.getProperty();
175 public ToscaGetFunctionType getToscaGetFunctionType() {
176 if (isToscaGetFunction() && toscaFunction != null) {
177 return ((ToscaGetFunctionDataDefinition) toscaFunction).getFunctionType();
183 public Boolean isHidden() {
187 public Boolean isImmutable() {
191 public Boolean isMappedToComponentProperty() {
192 return mappedToComponentProperty;
196 * The resource id which this property belongs to
198 public String getParentUniqueId() {
202 public void setParentUniqueId(String parentUniqueId) {
203 setOwnerId(parentUniqueId);
206 public List<GetPolicyValueDataDefinition> safeGetGetPolicyValues() {
207 return CollectionUtils.isEmpty(getPolicyValues) ? new ArrayList<>() : getPolicyValues;
210 public boolean typeEquals(Object obj) {
217 if (getClass() != obj.getClass()) {
220 PropertyDataDefinition other = (PropertyDataDefinition) obj;
221 if (this.getType() == null) {
222 return other.getType() == null;
224 if (!this.type.equals(other.type)) {
227 String thisSchemaType = this.getSchemaType();
228 String otherSchemaType = other.getSchemaType();
229 if (thisSchemaType == null) {
230 return otherSchemaType == null;
232 return thisSchemaType.equals(otherSchemaType);
236 public Object getToscaPresentationValue(JsonPresentationFields field) {
253 return super.getToscaPresentationValue(field);
258 public void setToscaPresentationValue(JsonPresentationFields name, Object value) {
261 setName((String) value);
264 setUniqueId((String) value);
267 setPassword((Boolean) value);
270 setType((String) value);
273 setDefinition((Boolean) value);
276 setValue((String) value);
279 setDefaultValue((String) value);
282 super.setToscaPresentationValue(name, value);
287 private <T extends ToscaDataDefinition> boolean compareSchemaType(T other) {
288 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType()
289 .equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
293 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
294 if (this.getType() != null && this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE)) && compareSchemaType(
296 other.setOwnerId(getOwnerId());
297 if (allowDefaultValueOverride && getDefaultValue() != null && !getDefaultValue().isEmpty()) {
298 other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());
305 public void convertPropertyDataToInstancePropertyData() {
307 defaultValue = value;
311 public boolean isGetInputProperty() {
312 return this.getGetInputValues() != null && !this.getGetInputValues().isEmpty();
315 public void setAnnotations(List<Annotation> newAnnotations) {
316 Set<Annotation> annotationSet = isNotEmpty(newAnnotations) ? new HashSet<>(newAnnotations) : new HashSet<>();
317 //We would to prioritize the new valid annotations over the old ones if the same one existed.
318 if (this.annotations != null) {
319 annotationSet.addAll(this.annotations);
321 this.annotations = new ArrayList<>(annotationSet);
322 setToscaPresentationValue(JsonPresentationFields.ANNOTATIONS, this.annotations);
325 public List<Annotation> getAnnotations() {
326 return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);
329 @JsonIgnoreProperties
330 public boolean isToscaFunction() {
331 return this.toscaGetFunctionType != null || this.toscaFunction != null;
335 @JsonIgnoreProperties
336 public boolean isToscaGetFunction() {
337 return this.toscaFunction != null
338 && (this.toscaFunction.getType() == ToscaFunctionType.GET_ATTRIBUTE
339 || this.toscaFunction.getType() == ToscaFunctionType.GET_INPUT
340 || this.toscaFunction.getType() == ToscaFunctionType.GET_PROPERTY);
343 @JsonIgnoreProperties
344 public boolean hasToscaFunction() {
345 return this.toscaFunction != null;