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=========================================================
20 package org.openecomp.sdc.be.datatypes.elements;
22 import static org.apache.commons.collections.CollectionUtils.isNotEmpty;
24 import java.util.ArrayList;
25 import java.util.HashMap;
26 import java.util.HashSet;
27 import java.util.List;
31 import lombok.EqualsAndHashCode;
32 import org.apache.commons.collections.CollectionUtils;
33 import org.apache.commons.collections.MapUtils;
34 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
35 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
37 @EqualsAndHashCode(callSuper = false)
39 public class PropertyDataDefinition extends ToscaDataDefinition {
41 protected boolean definition = false;
42 protected Boolean hidden = Boolean.FALSE;
43 private String uniqueId;
44 // "boolean", "string", "float", "integer", "version" })
46 private Boolean required = Boolean.FALSE;
47 private String defaultValue;
48 private String description;
49 private SchemaDefinition schema;
50 private boolean password;
54 private Boolean immutable = Boolean.FALSE;
55 private Boolean mappedToComponentProperty = Boolean.TRUE;
56 private String inputPath;
57 private String status;
58 private String inputId;
59 private String instanceUniqueId;
60 private String propertyId;
61 private String parentPropertyType;
62 private String subPropertyInputPath;
63 private List<Annotation> annotations;
65 * The resource id which this property belongs to
67 private String parentUniqueId;
68 private List<GetInputValueDataDefinition> getInputValues;
69 private Boolean isDeclaredListInput = Boolean.FALSE;
70 private List<GetPolicyValueDataDefinition> getPolicyValues;
71 private List<String> propertyConstraints;
72 private Map<String, String> metadata;
74 public PropertyDataDefinition() {
78 public PropertyDataDefinition(Map<String, Object> pr) {
82 public PropertyDataDefinition(PropertyDataDefinition propertyDataDefinition) {
84 this.setUniqueId(propertyDataDefinition.getUniqueId());
85 this.setRequired(propertyDataDefinition.isRequired());
86 this.setDefaultValue(propertyDataDefinition.getDefaultValue());
87 this.setDefinition(propertyDataDefinition.getDefinition());
88 this.setDescription(propertyDataDefinition.getDescription());
89 this.setSchema(propertyDataDefinition.getSchema());
90 this.setPassword(propertyDataDefinition.isPassword());
91 this.setType(propertyDataDefinition.getType());
92 this.setName(propertyDataDefinition.getName());
93 this.setValue(propertyDataDefinition.getValue());
94 this.setRequired(propertyDataDefinition.isRequired());
95 this.setHidden(propertyDataDefinition.isHidden());
96 this.setLabel(propertyDataDefinition.getLabel());
97 this.setImmutable(propertyDataDefinition.isImmutable());
98 this.setMappedToComponentProperty(propertyDataDefinition.isMappedToComponentProperty());
99 this.setParentUniqueId(propertyDataDefinition.getParentUniqueId());
100 this.setOwnerId(propertyDataDefinition.getOwnerId());
101 this.setGetInputValues(propertyDataDefinition.getGetInputValues());
102 this.setGetPolicyValues(propertyDataDefinition.getGetPolicyValues());
103 this.setInputPath(propertyDataDefinition.getInputPath());
104 this.setStatus(propertyDataDefinition.getStatus());
105 this.setInputId(propertyDataDefinition.getInputId());
106 this.setInstanceUniqueId(propertyDataDefinition.getInstanceUniqueId());
107 this.setPropertyId(propertyDataDefinition.getPropertyId());
108 this.parentPropertyType = propertyDataDefinition.getParentPropertyType();
109 this.subPropertyInputPath = propertyDataDefinition.getSubPropertyInputPath();
110 if (isNotEmpty(propertyDataDefinition.annotations)) {
111 this.setAnnotations(propertyDataDefinition.annotations);
113 if (MapUtils.isNotEmpty(propertyDataDefinition.getMetadata())) {
114 setMetadata(new HashMap<>(propertyDataDefinition.getMetadata()));
116 if (isNotEmpty(propertyDataDefinition.getPropertyConstraints())) {
117 setPropertyConstraints(new ArrayList<>(propertyDataDefinition.getPropertyConstraints()));
119 this.setIsDeclaredListInput(propertyDataDefinition.getIsDeclaredListInput());
123 public boolean isDefinition() {
127 public boolean getDefinition() {
131 public Boolean isRequired() {
135 public String getSchemaType() {
136 if (schema != null && schema.getProperty() != null) {
137 return schema.getProperty().getType();
142 public void setSchemaType(String schemaType) {
143 if (schema != null && schema.getProperty() != null) {
144 schema.getProperty().setType(schemaType);
148 public PropertyDataDefinition getSchemaProperty() {
149 if (schema != null) {
150 return schema.getProperty();
155 public Boolean isHidden() {
159 public Boolean isImmutable() {
163 public Boolean isMappedToComponentProperty() {
164 return mappedToComponentProperty;
167 public String getParentUniqueId() {
171 public void setParentUniqueId(String parentUniqueId) {
172 setOwnerId(parentUniqueId);
175 public List<GetPolicyValueDataDefinition> safeGetGetPolicyValues() {
176 return CollectionUtils.isEmpty(getPolicyValues) ? new ArrayList<>() : getPolicyValues;
179 public boolean typeEquals(Object obj) {
186 if (getClass() != obj.getClass()) {
189 PropertyDataDefinition other = (PropertyDataDefinition) obj;
190 if (this.getType() == null) {
191 return other.getType() == null;
193 if (!this.type.equals(other.type)) {
196 String thisSchemaType = this.getSchemaType();
197 String otherSchemaType = other.getSchemaType();
198 if (thisSchemaType == null) {
199 return otherSchemaType == null;
201 return thisSchemaType.equals(otherSchemaType);
205 public Object getToscaPresentationValue(JsonPresentationFields field) {
222 return super.getToscaPresentationValue(field);
227 public void setToscaPresentationValue(JsonPresentationFields name, Object value) {
230 setName((String) value);
233 setUniqueId((String) value);
236 setPassword((Boolean) value);
239 setType((String) value);
242 setDefinition((Boolean) value);
245 setValue((String) value);
248 setDefaultValue((String) value);
251 super.setToscaPresentationValue(name, value);
256 private <T extends ToscaDataDefinition> boolean compareSchemaType(T other) {
257 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType()
258 .equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
262 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
263 if (this.getType() != null && this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE)) && compareSchemaType(
265 other.setOwnerId(getOwnerId());
266 if (allowDefaultValueOverride && getDefaultValue() != null && !getDefaultValue().isEmpty()) {
267 other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());
274 public void convertPropertyDataToInstancePropertyData() {
276 defaultValue = value;
280 public boolean isGetInputProperty() {
281 return this.getGetInputValues() != null && !this.getGetInputValues().isEmpty();
284 public List<Annotation> getAnnotations() {
285 return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);
288 public void setAnnotations(List<Annotation> newAnnotations) {
289 Set<Annotation> annotationSet = isNotEmpty(newAnnotations) ? new HashSet<>(newAnnotations) : new HashSet<>();
290 //We would to prioritize the new valid annotations over the old ones if the same one existed.
291 if (this.annotations != null) {
292 annotationSet.addAll(this.annotations);
294 this.annotations = new ArrayList<>(annotationSet);
295 setToscaPresentationValue(JsonPresentationFields.ANNOTATIONS, this.annotations);