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 org.apache.commons.collections.CollectionUtils;
24 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
25 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
27 import java.util.ArrayList;
28 import java.util.HashSet;
29 import java.util.List;
33 import lombok.EqualsAndHashCode;
35 import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
37 @EqualsAndHashCode(callSuper = false)
39 public class PropertyDataDefinition extends ToscaDataDefinition {
41 private String uniqueId;
43 // "boolean", "string", "float", "integer", "version" })
46 private Boolean required = Boolean.FALSE;
48 protected boolean definition = false;
50 private String defaultValue;
52 private String description;
54 private SchemaDefinition schema;
56 private boolean password;
63 protected Boolean hidden = Boolean.FALSE;
64 private Boolean immutable = Boolean.FALSE;
66 private String inputPath;
67 private String status;
68 private String inputId;
69 private String instanceUniqueId;
70 private String propertyId;
71 private String parentPropertyType;
72 private String subPropertyInputPath;
74 private List<Annotation> annotations;
76 * The resource id which this property belongs to
78 private String parentUniqueId;
80 private List<GetInputValueDataDefinition> getInputValues;
82 private Boolean isDeclaredListInput = Boolean.FALSE;
84 private List<GetPolicyValueDataDefinition> getPolicyValues;
86 private List<String> propertyConstraints;
88 public PropertyDataDefinition() {
92 public PropertyDataDefinition(Map<String, Object> pr) {
96 public PropertyDataDefinition(PropertyDataDefinition propertyDataDefinition) {
98 this.setUniqueId(propertyDataDefinition.getUniqueId());
99 this.setRequired(propertyDataDefinition.isRequired());
100 this.setDefaultValue(propertyDataDefinition.getDefaultValue());
101 this.setDefinition(propertyDataDefinition.getDefinition());
102 this.setDescription(propertyDataDefinition.getDescription());
103 this.setSchema(propertyDataDefinition.getSchema());
104 this.setPassword(propertyDataDefinition.isPassword());
105 this.setType(propertyDataDefinition.getType());
106 this.setName(propertyDataDefinition.getName());
107 this.setValue(propertyDataDefinition.getValue());
108 this.setRequired(propertyDataDefinition.isRequired());
109 this.setHidden(propertyDataDefinition.isHidden());
110 this.setLabel(propertyDataDefinition.getLabel());
111 this.setImmutable(propertyDataDefinition.isImmutable());
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.setPropertyId(propertyDataDefinition.getPropertyId());
121 this.parentPropertyType = propertyDataDefinition.getParentPropertyType();
122 this.subPropertyInputPath = propertyDataDefinition.getSubPropertyInputPath();
123 if (isNotEmpty(propertyDataDefinition.annotations)) {
124 this.setAnnotations(propertyDataDefinition.annotations);
126 if(isNotEmpty(propertyDataDefinition.getPropertyConstraints())){
127 setPropertyConstraints(new ArrayList<>(propertyDataDefinition.getPropertyConstraints()));
129 this.setIsDeclaredListInput(propertyDataDefinition.getIsDeclaredListInput());
133 public boolean isDefinition() {
137 public boolean getDefinition() {
141 public Boolean isRequired() {
145 public void setSchemaType(String schemaType) {
146 if (schema != null && schema.getProperty() != null) {
147 schema.getProperty().setType(schemaType);
151 public String getSchemaType() {
152 if (schema != null && schema.getProperty() != null) {
153 return schema.getProperty().getType();
158 public PropertyDataDefinition getSchemaProperty() {
159 if (schema != null) {
160 return schema.getProperty();
166 public Boolean isHidden() {
170 public Boolean isImmutable() {
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().equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
268 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
269 if (this.getType() != null
270 && this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE))
271 && compareSchemaType(other)) {
272 other.setOwnerId(getOwnerId());
273 if (allowDefaultValueOverride
274 && getDefaultValue() != null
275 && !getDefaultValue().isEmpty()) {
276 other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());
283 public void convertPropertyDataToInstancePropertyData() {
285 defaultValue = value;
289 public boolean isGetInputProperty() {
290 return this.getGetInputValues() != null && !this.getGetInputValues().isEmpty();
293 public void setAnnotations(List<Annotation> newAnnotations) {
294 Set<Annotation> annotationSet = isNotEmpty(newAnnotations) ? new HashSet<>(newAnnotations) : new HashSet<>();
295 //We would to prioritize the new valid annotations over the old ones if the same one existed.
296 if (this.annotations != null) {
297 annotationSet.addAll(this.annotations);
300 this.annotations = new ArrayList<>(annotationSet);
301 setToscaPresentationValue(JsonPresentationFields.ANNOTATIONS, this.annotations);
304 public List<Annotation> getAnnotations() {
305 return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);