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(final 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 if (propertyDataDefinition.getSchema() != null) {
95 this.setSchema(new SchemaDefinition(propertyDataDefinition.getSchema()));
97 this.setPassword(propertyDataDefinition.isPassword());
98 this.setType(propertyDataDefinition.getType());
99 this.setName(propertyDataDefinition.getName());
100 this.setValue(propertyDataDefinition.getValue());
101 this.setRequired(propertyDataDefinition.isRequired());
102 this.setHidden(propertyDataDefinition.isHidden());
103 this.setLabel(propertyDataDefinition.getLabel());
104 this.setImmutable(propertyDataDefinition.isImmutable());
105 this.setMappedToComponentProperty(propertyDataDefinition.isMappedToComponentProperty());
106 this.setParentUniqueId(propertyDataDefinition.getParentUniqueId());
107 this.setOwnerId(propertyDataDefinition.getOwnerId());
108 this.setGetInputValues(propertyDataDefinition.getGetInputValues());
109 this.setGetPolicyValues(propertyDataDefinition.getGetPolicyValues());
110 this.setInputPath(propertyDataDefinition.getInputPath());
111 this.setStatus(propertyDataDefinition.getStatus());
112 this.setInputId(propertyDataDefinition.getInputId());
113 this.setInstanceUniqueId(propertyDataDefinition.getInstanceUniqueId());
114 this.setModel(propertyDataDefinition.getModel());
115 this.setPropertyId(propertyDataDefinition.getPropertyId());
116 this.setToscaGetFunctionType(propertyDataDefinition.getToscaGetFunctionType());
117 this.parentPropertyType = propertyDataDefinition.getParentPropertyType();
118 this.subPropertyInputPath = propertyDataDefinition.getSubPropertyInputPath();
119 if (isNotEmpty(propertyDataDefinition.annotations)) {
120 this.setAnnotations(propertyDataDefinition.annotations);
122 if (MapUtils.isNotEmpty(propertyDataDefinition.getMetadata())) {
123 setMetadata(new HashMap<>(propertyDataDefinition.getMetadata()));
125 if (isNotEmpty(propertyDataDefinition.getPropertyConstraints())) {
126 setPropertyConstraints(new ArrayList<>(propertyDataDefinition.getPropertyConstraints()));
128 this.setIsDeclaredListInput(propertyDataDefinition.getIsDeclaredListInput());
132 public boolean isDefinition() {
136 public boolean getDefinition() {
140 public Boolean isRequired() {
144 public void setSchemaType(String schemaType) {
145 if (schema != null && schema.getProperty() != null) {
146 schema.getProperty().setType(schemaType);
150 public String getSchemaType() {
151 if (schema != null && schema.getProperty() != null) {
152 return schema.getProperty().getType();
157 public PropertyDataDefinition getSchemaProperty() {
158 if (schema != null) {
159 return schema.getProperty();
164 public Boolean isHidden() {
168 public Boolean isImmutable() {
172 public Boolean isMappedToComponentProperty() {
173 return mappedToComponentProperty;
176 public String getParentUniqueId() {
180 public void setParentUniqueId(String parentUniqueId) {
181 setOwnerId(parentUniqueId);
184 public List<GetPolicyValueDataDefinition> safeGetGetPolicyValues() {
185 return CollectionUtils.isEmpty(getPolicyValues) ? new ArrayList<>() : getPolicyValues;
188 public boolean typeEquals(Object obj) {
195 if (getClass() != obj.getClass()) {
198 PropertyDataDefinition other = (PropertyDataDefinition) obj;
199 if (this.getType() == null) {
200 return other.getType() == null;
202 if (!this.type.equals(other.type)) {
205 String thisSchemaType = this.getSchemaType();
206 String otherSchemaType = other.getSchemaType();
207 if (thisSchemaType == null) {
208 return otherSchemaType == null;
210 return thisSchemaType.equals(otherSchemaType);
214 public Object getToscaPresentationValue(JsonPresentationFields field) {
231 return super.getToscaPresentationValue(field);
236 public void setToscaPresentationValue(JsonPresentationFields name, Object value) {
239 setName((String) value);
242 setUniqueId((String) value);
245 setPassword((Boolean) value);
248 setType((String) value);
251 setDefinition((Boolean) value);
254 setValue((String) value);
257 setDefaultValue((String) value);
260 super.setToscaPresentationValue(name, value);
265 private <T extends ToscaDataDefinition> boolean compareSchemaType(T other) {
266 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType()
267 .equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
271 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
272 if (this.getType() != null && this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE)) && compareSchemaType(
274 other.setOwnerId(getOwnerId());
275 if (allowDefaultValueOverride && getDefaultValue() != null && !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);
299 this.annotations = new ArrayList<>(annotationSet);
300 setToscaPresentationValue(JsonPresentationFields.ANNOTATIONS, this.annotations);
303 public List<Annotation> getAnnotations() {
304 return (List<Annotation>) getToscaPresentationValue(JsonPresentationFields.ANNOTATIONS);