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.Collection;
28 import java.util.HashMap;
29 import java.util.HashSet;
30 import java.util.List;
34 import lombok.EqualsAndHashCode;
35 import org.apache.commons.collections.CollectionUtils;
36 import org.apache.commons.collections.MapUtils;
37 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
38 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
39 import org.openecomp.sdc.be.datatypes.tosca.ToscaGetFunctionType;
41 @EqualsAndHashCode(callSuper = false)
43 public class PropertyDataDefinition extends ToscaDataDefinition {
45 private boolean definition = false;
46 private Boolean hidden = Boolean.FALSE;
47 private String uniqueId;
48 // "boolean", "string", "float", "integer", "version" })
50 private Boolean required = Boolean.FALSE;
51 private String defaultValue;
52 private String description;
53 private SchemaDefinition schema;
54 private boolean password;
58 private Boolean immutable = Boolean.FALSE;
59 private Boolean mappedToComponentProperty = Boolean.TRUE;
61 * @deprecated use {@link #toscaFunction} instead
64 private ToscaGetFunctionType toscaGetFunctionType;
66 * @deprecated use {@link #toscaFunction} instead
69 private ToscaGetFunctionDataDefinition toscaGetFunction;
70 private ToscaFunction toscaFunction;
71 private Collection<SubPropertyToscaFunction> subPropertyToscaFunctions;
73 private String inputPath;
74 private String status;
75 private String inputId;
76 private String instanceUniqueId;
78 private String propertyId;
79 private String parentPropertyType;
80 private String subPropertyInputPath;
81 private List<Annotation> annotations;
82 private List<GetInputValueDataDefinition> getInputValues;
83 private Boolean isDeclaredListInput = Boolean.FALSE;
84 private List<GetPolicyValueDataDefinition> getPolicyValues;
85 private List<String> propertyConstraints;
86 private Map<String, String> metadata;
87 private boolean userCreated;
89 public PropertyDataDefinition() {
93 public PropertyDataDefinition(Map<String, Object> pr) {
97 public PropertyDataDefinition(final PropertyDataDefinition propertyDataDefinition) {
99 this.setUniqueId(propertyDataDefinition.getUniqueId());
100 this.setRequired(propertyDataDefinition.isRequired());
101 this.setDefaultValue(propertyDataDefinition.getDefaultValue());
102 this.setDefinition(propertyDataDefinition.getDefinition());
103 this.setDescription(propertyDataDefinition.getDescription());
104 if (propertyDataDefinition.getSchema() != null) {
105 this.setSchema(new SchemaDefinition(propertyDataDefinition.getSchema()));
107 this.setPassword(propertyDataDefinition.isPassword());
108 this.setType(propertyDataDefinition.getType());
109 this.setName(propertyDataDefinition.getName());
110 this.setValue(propertyDataDefinition.getValue());
111 this.setHidden(propertyDataDefinition.isHidden());
112 this.setLabel(propertyDataDefinition.getLabel());
113 this.setImmutable(propertyDataDefinition.isImmutable());
114 this.setMappedToComponentProperty(propertyDataDefinition.isMappedToComponentProperty());
115 this.setParentUniqueId(propertyDataDefinition.getParentUniqueId());
116 this.setOwnerId(propertyDataDefinition.getOwnerId());
117 this.setGetInputValues(propertyDataDefinition.getGetInputValues());
118 this.setGetPolicyValues(propertyDataDefinition.getGetPolicyValues());
119 this.setInputPath(propertyDataDefinition.getInputPath());
120 this.setStatus(propertyDataDefinition.getStatus());
121 this.setInputId(propertyDataDefinition.getInputId());
122 this.setInstanceUniqueId(propertyDataDefinition.getInstanceUniqueId());
123 this.setModel(propertyDataDefinition.getModel());
124 this.setPropertyId(propertyDataDefinition.getPropertyId());
125 this.setToscaGetFunction(propertyDataDefinition.getToscaGetFunction());
126 this.setToscaGetFunctionType(propertyDataDefinition.getToscaGetFunctionType());
127 this.setToscaFunction(propertyDataDefinition.getToscaFunction());
128 this.parentPropertyType = propertyDataDefinition.getParentPropertyType();
129 this.subPropertyInputPath = propertyDataDefinition.getSubPropertyInputPath();
130 this.subPropertyToscaFunctions = propertyDataDefinition.getSubPropertyToscaFunctions();
131 if (isNotEmpty(propertyDataDefinition.annotations)) {
132 this.setAnnotations(propertyDataDefinition.annotations);
134 if (MapUtils.isNotEmpty(propertyDataDefinition.getMetadata())) {
135 setMetadata(new HashMap<>(propertyDataDefinition.getMetadata()));
137 if (isNotEmpty(propertyDataDefinition.getPropertyConstraints())) {
138 setPropertyConstraints(new ArrayList<>(propertyDataDefinition.getPropertyConstraints()));
140 this.setIsDeclaredListInput(propertyDataDefinition.getIsDeclaredListInput());
141 this.setUserCreated(propertyDataDefinition.isUserCreated());
144 public boolean isDefinition() {
148 public boolean getDefinition() {
152 public Boolean isRequired() {
156 public void setSchemaType(String schemaType) {
157 if (schema != null && schema.getProperty() != null) {
158 schema.getProperty().setType(schemaType);
162 public String getSchemaType() {
163 if (schema != null && schema.getProperty() != null) {
164 return schema.getProperty().getType();
169 public PropertyDataDefinition getSchemaProperty() {
170 if (schema != null) {
171 return schema.getProperty();
176 public ToscaGetFunctionType getToscaGetFunctionType() {
177 if (isToscaGetFunction() && toscaFunction != null) {
178 return ((ToscaGetFunctionDataDefinition) toscaFunction).getFunctionType();
184 public Boolean isHidden() {
188 public Boolean isImmutable() {
192 public Boolean isMappedToComponentProperty() {
193 return mappedToComponentProperty;
197 * The resource id which this property belongs to
199 public String getParentUniqueId() {
203 public void setParentUniqueId(String parentUniqueId) {
204 setOwnerId(parentUniqueId);
207 public List<GetPolicyValueDataDefinition> safeGetGetPolicyValues() {
208 return CollectionUtils.isEmpty(getPolicyValues) ? new ArrayList<>() : getPolicyValues;
211 public boolean typeEquals(Object obj) {
218 if (getClass() != obj.getClass()) {
221 PropertyDataDefinition other = (PropertyDataDefinition) obj;
222 if (this.getType() == null) {
223 return other.getType() == null;
225 if (!this.type.equals(other.type)) {
228 String thisSchemaType = this.getSchemaType();
229 String otherSchemaType = other.getSchemaType();
230 if (thisSchemaType == null) {
231 return otherSchemaType == null;
233 return thisSchemaType.equals(otherSchemaType);
237 public Object getToscaPresentationValue(JsonPresentationFields field) {
254 return super.getToscaPresentationValue(field);
259 public void setToscaPresentationValue(JsonPresentationFields name, Object value) {
262 setName((String) value);
265 setUniqueId((String) value);
268 setPassword((Boolean) value);
271 setType((String) value);
274 setDefinition((Boolean) value);
277 setValue((String) value);
280 setDefaultValue((String) value);
283 super.setToscaPresentationValue(name, value);
288 private <T extends ToscaDataDefinition> boolean compareSchemaType(T other) {
289 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType()
290 .equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
294 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
295 if (this.getType() != null && this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE)) && compareSchemaType(
297 other.setOwnerId(getOwnerId());
298 if (allowDefaultValueOverride && getDefaultValue() != null && !getDefaultValue().isEmpty()) {
299 other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());
306 public void convertPropertyDataToInstancePropertyData() {
308 defaultValue = value;
312 public boolean isGetInputProperty() {
313 return this.getGetInputValues() != null && !this.getGetInputValues().isEmpty();
316 public void setAnnotations(List<Annotation> newAnnotations) {
317 Set<Annotation> annotationSet = isNotEmpty(newAnnotations) ? new HashSet<>(newAnnotations) : new HashSet<>();
318 //We would to prioritize the new valid annotations over the old ones if the same one existed.
319 if (this.annotations != null) {
320 annotationSet.addAll(this.annotations);
322 this.annotations = new ArrayList<>(annotationSet);
323 setToscaPresentationValue(JsonPresentationFields.ANNOTATIONS, this.annotations);
326 public List<Annotation> getAnnotations() {
327 return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);
330 @JsonIgnoreProperties
331 public boolean isToscaFunction() {
332 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;