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.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
24 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
26 import java.io.Serializable;
27 import java.util.List;
30 public class PropertyDataDefinition extends ToscaDataDefinition implements Serializable {
35 private static final long serialVersionUID = 5798685557528432389L;
37 private String uniqueId;
39 // "boolean", "string", "float", "integer", "version" })
42 private Boolean required = Boolean.FALSE;
44 protected boolean definition = false;
46 private String defaultValue;
48 private String description;
50 private SchemaDefinition schema;
52 private boolean password;
59 protected Boolean hidden = Boolean.FALSE;
60 private Boolean immutable = Boolean.FALSE;
62 private String inputPath;
63 private String status;
64 private String inputId;
65 private String instanceUniqueId;
66 private String propertyId;
68 * The resource id which this property belongs to
70 private String parentUniqueId;
72 private List<GetInputValueDataDefinition> getInputValues;
74 public PropertyDataDefinition() {
78 public PropertyDataDefinition(Map<String, Object> pr) {
83 public PropertyDataDefinition(PropertyDataDefinition p) {
85 this.setUniqueId(p.getUniqueId());
86 this.setRequired(p.isRequired());
87 this.setDefaultValue(p.getDefaultValue());
88 this.setDescription(p.getDescription());
89 this.setSchema(p.getSchema());
90 this.setPassword(p.isPassword());
91 this.setType(p.getType());
92 this.setName(p.getName());
93 this.setValue(p.getValue());
94 this.setRequired(p.isRequired());
95 this.setHidden(p.isHidden());
96 this.setLabel(p.getLabel());
97 this.setImmutable(p.isImmutable());
98 this.setParentUniqueId(p.getParentUniqueId());
99 this.setOwnerId(p.getOwnerId());
100 this.setGetInputValues(p.getInputValues);
101 this.setInputPath(p.getInputPath());
102 this.setStatus(p.getStatus());
103 this.setInputId(p.getInputId());
104 this.setInstanceUniqueId(p.getInstanceUniqueId());
105 this.setPropertyId(p.getPropertyId());
108 public String getInputPath() {
112 public void setInputPath(String inputPath) {
113 this.inputPath = inputPath;
116 public String getName() {
120 public void setName(String name) {
124 public String getValue() {
128 public void setValue(String value) {
133 public boolean isDefinition() {
137 public void setDefinition(boolean definition) {
138 this.definition = definition;
141 public String getType() {
145 public String getDefaultValue() {
149 public void setDefaultValue(String defaultValue) {
150 this.defaultValue = defaultValue;
153 public void setType(String type) {
157 public Boolean isRequired() {
161 public void setRequired(Boolean required) {
162 this.required = required;
165 public String getDescription() {
169 public void setDescription(String description) {
170 this.description = description;
173 public boolean isPassword() {
177 public void setPassword(boolean password) {
178 this.password = password;
181 public String getUniqueId() {
185 public void setUniqueId(String uniqueId) {
186 this.uniqueId = uniqueId;
189 public SchemaDefinition getSchema() {
193 public void setSchema(SchemaDefinition entrySchema) {
194 this.schema = entrySchema;
197 public String getSchemaType() {
198 if (schema != null && schema.getProperty() != null) {
199 return schema.getProperty().getType();
204 public String getLabel() {
208 public void setLabel(String label) {
212 public Boolean isHidden() {
216 public void setHidden(Boolean hidden) {
217 this.hidden = hidden;
220 public Boolean isImmutable() {
224 public void setImmutable(Boolean immutable) {
225 this.immutable = immutable;
228 public String getParentUniqueId() {
232 public void setParentUniqueId(String parentUniqueId) {
233 setOwnerId(parentUniqueId);
236 public List<GetInputValueDataDefinition> getGetInputValues() {
237 return getInputValues;
240 public void setGetInputValues(List<GetInputValueDataDefinition> getInputValues) {
241 this.getInputValues = getInputValues;
244 public String getStatus() {
248 public void setStatus(String status) {
249 this.status = status;
252 public String getInputId() {
256 public void setInputId(String inputId) {
257 this.inputId = inputId;
260 public String getInstanceUniqueId() {
261 return instanceUniqueId;
264 public void setInstanceUniqueId(String instanceUniqueId) {
265 this.instanceUniqueId = instanceUniqueId;
268 public String getPropertyId() {
272 public void setPropertyId(String propertyId) {
273 this.propertyId = propertyId;
277 public String toString() {
278 return "PropertyDataDefinition [uniqueId=" + uniqueId + ", type=" + type + ", required=" + required + ", definition=" + definition + ", defaultValue=" + defaultValue + ", description=" + description + ", schema=" + schema + ", password="
279 + password + ", name=" + name + ", value=" + value + ", label=" + label + ", hidden=" + hidden + ", immutable=" + immutable + ", inputPath=" + inputPath + ", status=" + status + ", inputId=" + inputId + ", instanceUniqueId="
280 + instanceUniqueId + ", propertyId=" + propertyId + ", parentUniqueId=" + parentUniqueId + ", getInputValues=" + getInputValues + "]";
284 public int hashCode() {
285 final int prime = 31;
287 result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
288 result = prime * result + (definition ? 1231 : 1237);
289 result = prime * result + ((description == null) ? 0 : description.hashCode());
290 result = prime * result + (password ? 1231 : 1237);
291 result = prime * result + ((required == null) ? 0 : required.hashCode());
292 result = prime * result + ((schema == null) ? 0 : schema.hashCode());
293 result = prime * result + ((type == null) ? 0 : type.hashCode());
294 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
295 result = prime * result + ((parentUniqueId == null) ? 0 : parentUniqueId.hashCode());
296 result = prime * result + ((status == null) ? 0 : status.hashCode());
300 public boolean typeEquals(Object obj) {
305 if (getClass() != obj.getClass())
307 PropertyDataDefinition other = (PropertyDataDefinition) obj;
308 if (this.getType() == null)
309 return other.getType() == null;
310 if (!this.type.equals(other.type)) {
313 String thisSchemaType = this.getSchemaType();
314 String otherSchemaType = other.getSchemaType();
315 if (thisSchemaType == null) {
316 return otherSchemaType == null;
318 return thisSchemaType.equals(otherSchemaType);
322 public boolean equals(Object obj) {
327 if (getClass() != obj.getClass())
329 PropertyDataDefinition other = (PropertyDataDefinition) obj;
330 if (defaultValue == null) {
331 if (other.defaultValue != null)
333 } else if (!defaultValue.equals(other.defaultValue))
335 if (definition != other.definition)
337 if (description == null) {
338 if (other.description != null)
340 } else if (!description.equals(other.description))
342 if (password != other.password)
344 if (required == null) {
345 if (other.required != null)
347 } else if (!required.equals(other.required))
349 if (schema == null) {
350 if (other.schema != null)
352 } else if (!schema.equals(other.schema))
355 if (other.type != null)
357 } else if (!type.equals(other.type))
359 if (parentUniqueId == null) {
360 if (other.parentUniqueId != null)
362 } else if (!parentUniqueId.equals(other.parentUniqueId))
364 if (uniqueId == null) {
365 if (other.uniqueId != null)
367 } else if (!uniqueId.equals(other.uniqueId))
369 if (status == null) {
370 if (other.status != null)
372 } else if (!status.equals(other.status))
378 public Object getToscaPresentationValue(JsonPresentationFields field) {
395 return super.getToscaPresentationValue(field);
399 private <T extends ToscaDataDefinition> boolean compareSchemaType(T other) {
400 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType().equals(((PropertyDataDefinition) other).getSchema().getProperty().getType());
404 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride) {
405 if (this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE)) && compareSchemaType(other)) {
406 other.setOwnerId(getOwnerId());
407 if (allowDefaultValueOverride) {
408 if (getDefaultValue() != null && !getDefaultValue().isEmpty()) {
409 other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());
417 public void convertPropertyDataToInstancePropertyData() {
419 defaultValue = value;
422 public boolean isGetInputProperty() {
423 return this.getGetInputValues() != null && !this.getGetInputValues().isEmpty();