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;
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;
83 private boolean userCreated;
85 public PropertyDataDefinition() {
89 public PropertyDataDefinition(Map<String, Object> pr) {
93 public PropertyDataDefinition(final PropertyDataDefinition propertyDataDefinition) {
95 this.setUniqueId(propertyDataDefinition.getUniqueId());
96 this.setRequired(propertyDataDefinition.isRequired());
97 this.setDefaultValue(propertyDataDefinition.getDefaultValue());
98 this.setDefinition(propertyDataDefinition.getDefinition());
99 this.setDescription(propertyDataDefinition.getDescription());
100 if (propertyDataDefinition.getSchema() != null) {
101 this.setSchema(new SchemaDefinition(propertyDataDefinition.getSchema()));
103 this.setPassword(propertyDataDefinition.isPassword());
104 this.setType(propertyDataDefinition.getType());
105 this.setName(propertyDataDefinition.getName());
106 this.setValue(propertyDataDefinition.getValue());
107 this.setRequired(propertyDataDefinition.isRequired());
108 this.setHidden(propertyDataDefinition.isHidden());
109 this.setLabel(propertyDataDefinition.getLabel());
110 this.setImmutable(propertyDataDefinition.isImmutable());
111 this.setMappedToComponentProperty(propertyDataDefinition.isMappedToComponentProperty());
112 this.setParentUniqueId(propertyDataDefinition.getParentUniqueId());
113 this.setOwnerId(propertyDataDefinition.getOwnerId());
114 this.setGetInputValues(propertyDataDefinition.getGetInputValues());
115 this.setGetPolicyValues(propertyDataDefinition.getGetPolicyValues());
116 this.setInputPath(propertyDataDefinition.getInputPath());
117 this.setStatus(propertyDataDefinition.getStatus());
118 this.setInputId(propertyDataDefinition.getInputId());
119 this.setInstanceUniqueId(propertyDataDefinition.getInstanceUniqueId());
120 this.setModel(propertyDataDefinition.getModel());
121 this.setPropertyId(propertyDataDefinition.getPropertyId());
122 this.setToscaGetFunctionType(propertyDataDefinition.getToscaGetFunctionType());
123 this.setToscaGetFunction(propertyDataDefinition.getToscaGetFunction());
124 this.parentPropertyType = propertyDataDefinition.getParentPropertyType();
125 this.subPropertyInputPath = propertyDataDefinition.getSubPropertyInputPath();
126 if (isNotEmpty(propertyDataDefinition.annotations)) {
127 this.setAnnotations(propertyDataDefinition.annotations);
129 if (MapUtils.isNotEmpty(propertyDataDefinition.getMetadata())) {
130 setMetadata(new HashMap<>(propertyDataDefinition.getMetadata()));
132 if (isNotEmpty(propertyDataDefinition.getPropertyConstraints())) {
133 setPropertyConstraints(new ArrayList<>(propertyDataDefinition.getPropertyConstraints()));
135 this.setIsDeclaredListInput(propertyDataDefinition.getIsDeclaredListInput());
136 this.setUserCreated(propertyDataDefinition.isUserCreated());
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();
172 public ToscaGetFunctionType getToscaGetFunctionType() {
173 if (toscaGetFunction != null) {
174 return toscaGetFunction.getFunctionType();
176 return toscaGetFunctionType;
179 public Boolean isHidden() {
183 public Boolean isImmutable() {
187 public Boolean isMappedToComponentProperty() {
188 return mappedToComponentProperty;
191 public String getParentUniqueId() {
195 public void setParentUniqueId(String parentUniqueId) {
196 setOwnerId(parentUniqueId);
199 public List<GetPolicyValueDataDefinition> safeGetGetPolicyValues() {
200 return CollectionUtils.isEmpty(getPolicyValues) ? new ArrayList<>() : getPolicyValues;
203 public boolean typeEquals(Object obj) {
210 if (getClass() != obj.getClass()) {
213 PropertyDataDefinition other = (PropertyDataDefinition) obj;
214 if (this.getType() == null) {
215 return other.getType() == null;
217 if (!this.type.equals(other.type)) {
220 String thisSchemaType = this.getSchemaType();
221 String otherSchemaType = other.getSchemaType();
222 if (thisSchemaType == null) {
223 return otherSchemaType == null;
225 return thisSchemaType.equals(otherSchemaType);
229 public Object getToscaPresentationValue(JsonPresentationFields field) {
246 return super.getToscaPresentationValue(field);
251 public void setToscaPresentationValue(JsonPresentationFields name, Object value) {
254 setName((String) value);
257 setUniqueId((String) value);
260 setPassword((Boolean) value);
263 setType((String) value);
266 setDefinition((Boolean) value);
269 setValue((String) value);
272 setDefaultValue((String) value);
275 super.setToscaPresentationValue(name, value);
280 private <T extends ToscaDataDefinition> boolean compareSchemaType(T other) {
281 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType()
282 .equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
286 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
287 if (this.getType() != null && this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE)) && compareSchemaType(
289 other.setOwnerId(getOwnerId());
290 if (allowDefaultValueOverride && getDefaultValue() != null && !getDefaultValue().isEmpty()) {
291 other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());
298 public void convertPropertyDataToInstancePropertyData() {
300 defaultValue = value;
304 public boolean isGetInputProperty() {
305 return this.getGetInputValues() != null && !this.getGetInputValues().isEmpty();
308 public void setAnnotations(List<Annotation> newAnnotations) {
309 Set<Annotation> annotationSet = isNotEmpty(newAnnotations) ? new HashSet<>(newAnnotations) : new HashSet<>();
310 //We would to prioritize the new valid annotations over the old ones if the same one existed.
311 if (this.annotations != null) {
312 annotationSet.addAll(this.annotations);
314 this.annotations = new ArrayList<>(annotationSet);
315 setToscaPresentationValue(JsonPresentationFields.ANNOTATIONS, this.annotations);
318 public List<Annotation> getAnnotations() {
319 return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);
322 public boolean isGetFunction() {
323 return this.toscaGetFunctionType != null || this.toscaGetFunction != null;
326 public boolean hasGetFunction() {
327 return this.toscaGetFunction != null;