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;
58 private ToscaGetFunctionType toscaGetFunctionType;
60 private String inputPath;
61 private String status;
62 private String inputId;
63 private String instanceUniqueId;
65 private String propertyId;
66 private String parentPropertyType;
67 private String subPropertyInputPath;
68 private List<Annotation> annotations;
70 * The resource id which this property belongs to
72 private String parentUniqueId;
73 private List<GetInputValueDataDefinition> getInputValues;
74 private Boolean isDeclaredListInput = Boolean.FALSE;
75 private List<GetPolicyValueDataDefinition> getPolicyValues;
76 private List<String> propertyConstraints;
77 private Map<String, String> metadata;
79 public PropertyDataDefinition() {
83 public PropertyDataDefinition(Map<String, Object> pr) {
87 public PropertyDataDefinition(PropertyDataDefinition propertyDataDefinition) {
89 this.setUniqueId(propertyDataDefinition.getUniqueId());
90 this.setRequired(propertyDataDefinition.isRequired());
91 this.setDefaultValue(propertyDataDefinition.getDefaultValue());
92 this.setDefinition(propertyDataDefinition.getDefinition());
93 this.setDescription(propertyDataDefinition.getDescription());
94 this.setSchema(propertyDataDefinition.getSchema());
95 this.setPassword(propertyDataDefinition.isPassword());
96 this.setType(propertyDataDefinition.getType());
97 this.setName(propertyDataDefinition.getName());
98 this.setValue(propertyDataDefinition.getValue());
99 this.setRequired(propertyDataDefinition.isRequired());
100 this.setHidden(propertyDataDefinition.isHidden());
101 this.setLabel(propertyDataDefinition.getLabel());
102 this.setImmutable(propertyDataDefinition.isImmutable());
103 this.setMappedToComponentProperty(propertyDataDefinition.isMappedToComponentProperty());
104 this.setParentUniqueId(propertyDataDefinition.getParentUniqueId());
105 this.setOwnerId(propertyDataDefinition.getOwnerId());
106 this.setGetInputValues(propertyDataDefinition.getGetInputValues());
107 this.setGetPolicyValues(propertyDataDefinition.getGetPolicyValues());
108 this.setInputPath(propertyDataDefinition.getInputPath());
109 this.setStatus(propertyDataDefinition.getStatus());
110 this.setInputId(propertyDataDefinition.getInputId());
111 this.setInstanceUniqueId(propertyDataDefinition.getInstanceUniqueId());
112 this.setModel(propertyDataDefinition.getModel());
113 this.setPropertyId(propertyDataDefinition.getPropertyId());
114 this.setToscaGetFunctionType(propertyDataDefinition.getToscaGetFunctionType());
115 this.parentPropertyType = propertyDataDefinition.getParentPropertyType();
116 this.subPropertyInputPath = propertyDataDefinition.getSubPropertyInputPath();
117 if (isNotEmpty(propertyDataDefinition.annotations)) {
118 this.setAnnotations(propertyDataDefinition.annotations);
120 if (MapUtils.isNotEmpty(propertyDataDefinition.getMetadata())) {
121 setMetadata(new HashMap<>(propertyDataDefinition.getMetadata()));
123 if (isNotEmpty(propertyDataDefinition.getPropertyConstraints())) {
124 setPropertyConstraints(new ArrayList<>(propertyDataDefinition.getPropertyConstraints()));
126 this.setIsDeclaredListInput(propertyDataDefinition.getIsDeclaredListInput());
130 public boolean isDefinition() {
134 public boolean getDefinition() {
138 public Boolean isRequired() {
142 public void setSchemaType(String schemaType) {
143 if (schema != null && schema.getProperty() != null) {
144 schema.getProperty().setType(schemaType);
148 public String getSchemaType() {
149 if (schema != null && schema.getProperty() != null) {
150 return schema.getProperty().getType();
155 public PropertyDataDefinition getSchemaProperty() {
156 if (schema != null) {
157 return schema.getProperty();
162 public Boolean isHidden() {
166 public Boolean isImmutable() {
170 public Boolean isMappedToComponentProperty() {
171 return mappedToComponentProperty;
174 public String getParentUniqueId() {
178 public void setParentUniqueId(String parentUniqueId) {
179 setOwnerId(parentUniqueId);
182 public List<GetPolicyValueDataDefinition> safeGetGetPolicyValues() {
183 return CollectionUtils.isEmpty(getPolicyValues) ? new ArrayList<>() : getPolicyValues;
186 public boolean typeEquals(Object obj) {
193 if (getClass() != obj.getClass()) {
196 PropertyDataDefinition other = (PropertyDataDefinition) obj;
197 if (this.getType() == null) {
198 return other.getType() == null;
200 if (!this.type.equals(other.type)) {
203 String thisSchemaType = this.getSchemaType();
204 String otherSchemaType = other.getSchemaType();
205 if (thisSchemaType == null) {
206 return otherSchemaType == null;
208 return thisSchemaType.equals(otherSchemaType);
212 public Object getToscaPresentationValue(JsonPresentationFields field) {
229 return super.getToscaPresentationValue(field);
234 public void setToscaPresentationValue(JsonPresentationFields name, Object value) {
237 setName((String) value);
240 setUniqueId((String) value);
243 setPassword((Boolean) value);
246 setType((String) value);
249 setDefinition((Boolean) value);
252 setValue((String) value);
255 setDefaultValue((String) value);
258 super.setToscaPresentationValue(name, value);
263 private <T extends ToscaDataDefinition> boolean compareSchemaType(T other) {
264 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType()
265 .equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
269 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
270 if (this.getType() != null && this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE)) && compareSchemaType(
272 other.setOwnerId(getOwnerId());
273 if (allowDefaultValueOverride && getDefaultValue() != null && !getDefaultValue().isEmpty()) {
274 other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());
281 public void convertPropertyDataToInstancePropertyData() {
283 defaultValue = value;
287 public boolean isGetInputProperty() {
288 return this.getGetInputValues() != null && !this.getGetInputValues().isEmpty();
291 public void setAnnotations(List<Annotation> newAnnotations) {
292 Set<Annotation> annotationSet = isNotEmpty(newAnnotations) ? new HashSet<>(newAnnotations) : new HashSet<>();
293 //We would to prioritize the new valid annotations over the old ones if the same one existed.
294 if (this.annotations != null) {
295 annotationSet.addAll(this.annotations);
297 this.annotations = new ArrayList<>(annotationSet);
298 setToscaPresentationValue(JsonPresentationFields.ANNOTATIONS, this.annotations);
301 public List<Annotation> getAnnotations() {
302 return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);