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 private boolean definition = false;
44 private 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;
74 private List<GetInputValueDataDefinition> getInputValues;
75 private Boolean isDeclaredListInput = Boolean.FALSE;
76 private List<GetPolicyValueDataDefinition> getPolicyValues;
77 private List<String> propertyConstraints;
78 private Map<String, String> metadata;
79 private boolean userCreated;
81 public PropertyDataDefinition() {
85 public PropertyDataDefinition(Map<String, Object> pr) {
89 public PropertyDataDefinition(final PropertyDataDefinition propertyDataDefinition) {
91 this.setUniqueId(propertyDataDefinition.getUniqueId());
92 this.setRequired(propertyDataDefinition.isRequired());
93 this.setDefaultValue(propertyDataDefinition.getDefaultValue());
94 this.setDefinition(propertyDataDefinition.getDefinition());
95 this.setDescription(propertyDataDefinition.getDescription());
96 if (propertyDataDefinition.getSchema() != null) {
97 this.setSchema(new SchemaDefinition(propertyDataDefinition.getSchema()));
99 this.setPassword(propertyDataDefinition.isPassword());
100 this.setType(propertyDataDefinition.getType());
101 this.setName(propertyDataDefinition.getName());
102 this.setValue(propertyDataDefinition.getValue());
103 this.setRequired(propertyDataDefinition.isRequired());
104 this.setHidden(propertyDataDefinition.isHidden());
105 this.setLabel(propertyDataDefinition.getLabel());
106 this.setImmutable(propertyDataDefinition.isImmutable());
107 this.setMappedToComponentProperty(propertyDataDefinition.isMappedToComponentProperty());
108 this.setParentUniqueId(propertyDataDefinition.getParentUniqueId());
109 this.setOwnerId(propertyDataDefinition.getOwnerId());
110 this.setGetInputValues(propertyDataDefinition.getGetInputValues());
111 this.setGetPolicyValues(propertyDataDefinition.getGetPolicyValues());
112 this.setInputPath(propertyDataDefinition.getInputPath());
113 this.setStatus(propertyDataDefinition.getStatus());
114 this.setInputId(propertyDataDefinition.getInputId());
115 this.setInstanceUniqueId(propertyDataDefinition.getInstanceUniqueId());
116 this.setModel(propertyDataDefinition.getModel());
117 this.setPropertyId(propertyDataDefinition.getPropertyId());
118 this.setToscaGetFunctionType(propertyDataDefinition.getToscaGetFunctionType());
119 this.setToscaGetFunction(propertyDataDefinition.getToscaGetFunction());
120 this.parentPropertyType = propertyDataDefinition.getParentPropertyType();
121 this.subPropertyInputPath = propertyDataDefinition.getSubPropertyInputPath();
122 if (isNotEmpty(propertyDataDefinition.annotations)) {
123 this.setAnnotations(propertyDataDefinition.annotations);
125 if (MapUtils.isNotEmpty(propertyDataDefinition.getMetadata())) {
126 setMetadata(new HashMap<>(propertyDataDefinition.getMetadata()));
128 if (isNotEmpty(propertyDataDefinition.getPropertyConstraints())) {
129 setPropertyConstraints(new ArrayList<>(propertyDataDefinition.getPropertyConstraints()));
131 this.setIsDeclaredListInput(propertyDataDefinition.getIsDeclaredListInput());
132 this.setUserCreated(propertyDataDefinition.isUserCreated());
136 public boolean isDefinition() {
140 public boolean getDefinition() {
144 public Boolean isRequired() {
148 public void setSchemaType(String schemaType) {
149 if (schema != null && schema.getProperty() != null) {
150 schema.getProperty().setType(schemaType);
154 public String getSchemaType() {
155 if (schema != null && schema.getProperty() != null) {
156 return schema.getProperty().getType();
161 public PropertyDataDefinition getSchemaProperty() {
162 if (schema != null) {
163 return schema.getProperty();
168 public ToscaGetFunctionType getToscaGetFunctionType() {
169 if (toscaGetFunction != null) {
170 return toscaGetFunction.getFunctionType();
172 return toscaGetFunctionType;
175 public Boolean isHidden() {
179 public Boolean isImmutable() {
183 public Boolean isMappedToComponentProperty() {
184 return mappedToComponentProperty;
188 * The resource id which this property belongs to
190 public String getParentUniqueId() {
194 public void setParentUniqueId(String parentUniqueId) {
195 setOwnerId(parentUniqueId);
198 public List<GetPolicyValueDataDefinition> safeGetGetPolicyValues() {
199 return CollectionUtils.isEmpty(getPolicyValues) ? new ArrayList<>() : getPolicyValues;
202 public boolean typeEquals(Object obj) {
209 if (getClass() != obj.getClass()) {
212 PropertyDataDefinition other = (PropertyDataDefinition) obj;
213 if (this.getType() == null) {
214 return other.getType() == null;
216 if (!this.type.equals(other.type)) {
219 String thisSchemaType = this.getSchemaType();
220 String otherSchemaType = other.getSchemaType();
221 if (thisSchemaType == null) {
222 return otherSchemaType == null;
224 return thisSchemaType.equals(otherSchemaType);
228 public Object getToscaPresentationValue(JsonPresentationFields field) {
245 return super.getToscaPresentationValue(field);
250 public void setToscaPresentationValue(JsonPresentationFields name, Object value) {
253 setName((String) value);
256 setUniqueId((String) value);
259 setPassword((Boolean) value);
262 setType((String) value);
265 setDefinition((Boolean) value);
268 setValue((String) value);
271 setDefaultValue((String) value);
274 super.setToscaPresentationValue(name, value);
279 private <T extends ToscaDataDefinition> boolean compareSchemaType(T other) {
280 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType()
281 .equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
285 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
286 if (this.getType() != null && this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE)) && compareSchemaType(
288 other.setOwnerId(getOwnerId());
289 if (allowDefaultValueOverride && getDefaultValue() != null && !getDefaultValue().isEmpty()) {
290 other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());
297 public void convertPropertyDataToInstancePropertyData() {
299 defaultValue = value;
303 public boolean isGetInputProperty() {
304 return this.getGetInputValues() != null && !this.getGetInputValues().isEmpty();
307 public void setAnnotations(List<Annotation> newAnnotations) {
308 Set<Annotation> annotationSet = isNotEmpty(newAnnotations) ? new HashSet<>(newAnnotations) : new HashSet<>();
309 //We would to prioritize the new valid annotations over the old ones if the same one existed.
310 if (this.annotations != null) {
311 annotationSet.addAll(this.annotations);
313 this.annotations = new ArrayList<>(annotationSet);
314 setToscaPresentationValue(JsonPresentationFields.ANNOTATIONS, this.annotations);
317 public List<Annotation> getAnnotations() {
318 return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);
321 public boolean isGetFunction() {
322 return this.toscaGetFunctionType != null || this.toscaGetFunction != null;
325 public boolean hasGetFunction() {
326 return this.toscaGetFunction != null;