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 java.io.Serializable;
24 import java.util.HashMap;
25 import java.util.List;
27 import java.util.stream.Collectors;
29 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
30 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
32 import fj.data.Either;
35 public class PropertyDataDefinition extends ToscaDataDefinition implements Serializable {
40 private static final long serialVersionUID = 5798685557528432389L;
42 private String uniqueId;
44 // "boolean", "string", "float", "integer", "version" })
47 private Boolean required = Boolean.FALSE;
49 protected boolean definition = false;
51 private String defaultValue;
53 private String description;
55 private SchemaDefinition schema;
57 private boolean password;
64 protected Boolean hidden = Boolean.FALSE;
65 private Boolean immutable = Boolean.FALSE;
67 private String inputPath;
68 private String status;
71 * The resource id which this property belongs to
73 private String parentUniqueId;
76 private List<GetInputValueDataDefinition> getInputValues;
78 public PropertyDataDefinition() {
82 public PropertyDataDefinition(Map<String, Object> pr) {
87 public PropertyDataDefinition(PropertyDataDefinition p) {
90 this.setUniqueId(p.getUniqueId());
91 this.setRequired(p.isRequired());
92 this.setDefaultValue(p.getDefaultValue());
93 this.setDescription(p.getDescription());
94 this.setSchema(p.getSchema());
95 this.setPassword(p.isPassword());
96 this.setType(p.getType());
97 this.setName(p.getName());
98 this.setValue(p.getValue());
99 this.setRequired(p.isRequired());
100 this.setHidden(p.isHidden());
101 this.setLabel(p.getLabel());
102 this.setImmutable(p.isImmutable());
103 this.setParentUniqueId(p.getParentUniqueId());
104 this.setOwnerId(p.getOwnerId());
105 this.setGetInputValues(p.getInputValues);
106 this.setInputPath(p.getInputPath());
107 this.setStatus(p.getStatus());
111 public String getInputPath() {
115 public void setInputPath(String inputPath) {
116 this.inputPath = inputPath;
119 public String getName() {
123 public void setName(String name) {
127 public String getValue() {
131 public void setValue(String value) {
136 public boolean isDefinition() {
140 public void setDefinition(boolean definition) {
141 this.definition = definition;
144 public String getType() {
148 public String getDefaultValue() {
152 public void setDefaultValue(String defaultValue) {
153 this.defaultValue = defaultValue;
156 public void setType(String type) {
160 public Boolean isRequired() {
164 public void setRequired(Boolean required) {
165 this.required = required;
168 public String getDescription() {
172 public void setDescription(String description) {
173 this.description = description;
176 public boolean isPassword() {
180 public void setPassword(boolean password) {
181 this.password = password;
184 public String getUniqueId() {
188 public void setUniqueId(String uniqueId) {
189 this.uniqueId = uniqueId;
192 public SchemaDefinition getSchema() {
196 public void setSchema(SchemaDefinition entrySchema) {
197 this.schema = entrySchema;
200 public String getLabel() {
204 public void setLabel(String label) {
208 public Boolean isHidden() {
212 public void setHidden(Boolean hidden) {
213 this.hidden = hidden;
216 public Boolean isImmutable() {
220 public void setImmutable(Boolean immutable) {
221 this.immutable = immutable;
225 public String getParentUniqueId() {
229 public void setParentUniqueId(String parentUniqueId) {
230 setOwnerId(parentUniqueId);
234 public List<GetInputValueDataDefinition> getGetInputValues() {
235 return getInputValues;
238 public void setGetInputValues(List<GetInputValueDataDefinition> getInputValues) {
239 this.getInputValues = getInputValues;
242 public String getStatus() {
246 public void setStatus(String status) {
247 this.status = status;
251 public String toString() {
252 return "PropertyDataDefinition [uniqueId=" + uniqueId + ", type=" + type + ", required=" + required + ", defaultValue=" + defaultValue + ", description=" + description + ", entrySchema=" + schema + ", parentUniqueId=" + parentUniqueId + ", password=" + password + "]";
256 public int hashCode() {
257 final int prime = 31;
259 result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
260 result = prime * result + (definition ? 1231 : 1237);
261 result = prime * result + ((description == null) ? 0 : description.hashCode());
262 result = prime * result + (password ? 1231 : 1237);
263 result = prime * result + ((required == null) ? 0 : required.hashCode());
264 result = prime * result + ((schema == null) ? 0 : schema.hashCode());
265 result = prime * result + ((type == null) ? 0 : type.hashCode());
266 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
267 result = prime * result + ((parentUniqueId == null) ? 0 : parentUniqueId.hashCode());
268 result = prime * result + ((status == null) ? 0 : status.hashCode());
273 public boolean equals(Object obj) {
278 if (getClass() != obj.getClass())
280 PropertyDataDefinition other = (PropertyDataDefinition) obj;
281 if (defaultValue == null) {
282 if (other.defaultValue != null)
284 } else if (!defaultValue.equals(other.defaultValue))
286 if (definition != other.definition)
288 if (description == null) {
289 if (other.description != null)
291 } else if (!description.equals(other.description))
293 if (password != other.password)
295 if (required == null) {
296 if (other.required != null)
298 } else if (!required.equals(other.required))
300 if (schema == null) {
301 if (other.schema != null)
303 } else if (!schema.equals(other.schema))
306 if (other.type != null)
308 } else if (!type.equals(other.type))
310 if (parentUniqueId == null) {
311 if (other.parentUniqueId != null)
313 } else if (!parentUniqueId.equals(other.parentUniqueId))
315 if (uniqueId == null) {
316 if (other.uniqueId != null)
318 } else if (!uniqueId.equals(other.uniqueId))
320 if (status == null) {
321 if (other.status != null)
323 } else if (!status.equals(other.status))
329 public Object getToscaPresentationValue(JsonPresentationFields field) {
346 return super.getToscaPresentationValue(field);
350 private <T extends ToscaDataDefinition> boolean compareSchemaType(T other){
351 return !"list".equals(type) && !"map".equals(type) || this.getSchema().getProperty().getType().equals(((PropertyDataDefinition)other).getSchema().getProperty().getType());
356 public <T extends ToscaDataDefinition> T mergeFunction(T other, boolean allowDefaultValueOverride){
357 if(this.getType().equals(other.getToscaPresentationValue(JsonPresentationFields.TYPE)) && compareSchemaType(other)){
358 other.setOwnerId(getOwnerId());
359 if(allowDefaultValueOverride)
360 other.setToscaPresentationValue(JsonPresentationFields.DEFAULT_VALUE, getDefaultValue());