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.List;
26 import java.util.stream.Collectors;
28 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
29 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
31 import fj.data.Either;
34 public class PropertyDataDefinition extends ToscaDataDefinition implements Serializable {
39 private static final long serialVersionUID = 5798685557528432389L;
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 private Boolean hidden = Boolean.FALSE;;
64 private Boolean immutable = Boolean.FALSE;
66 private String inputPath;
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());
110 public String getInputPath() {
114 public void setInputPath(String inputPath) {
115 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 toString() {
243 return "PropertyDataDefinition [uniqueId=" + uniqueId + ", type=" + type + ", required=" + required + ", defaultValue=" + defaultValue + ", description=" + description + ", entrySchema=" + schema + ", parentUniqueId=" + parentUniqueId + ", password=" + password + "]";
247 public int hashCode() {
248 final int prime = 31;
250 result = prime * result + ((defaultValue == null) ? 0 : defaultValue.hashCode());
251 result = prime * result + (definition ? 1231 : 1237);
252 result = prime * result + ((description == null) ? 0 : description.hashCode());
253 result = prime * result + (password ? 1231 : 1237);
254 result = prime * result + ((required == null) ? 0 : required.hashCode());
255 result = prime * result + ((schema == null) ? 0 : schema.hashCode());
256 result = prime * result + ((type == null) ? 0 : type.hashCode());
257 result = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode());
258 result = prime * result + ((parentUniqueId == null) ? 0 : parentUniqueId.hashCode());
263 public boolean equals(Object obj) {
268 if (getClass() != obj.getClass())
270 PropertyDataDefinition other = (PropertyDataDefinition) obj;
271 if (defaultValue == null) {
272 if (other.defaultValue != null)
274 } else if (!defaultValue.equals(other.defaultValue))
276 if (definition != other.definition)
278 if (description == null) {
279 if (other.description != null)
281 } else if (!description.equals(other.description))
283 if (password != other.password)
285 if (required == null) {
286 if (other.required != null)
288 } else if (!required.equals(other.required))
290 if (schema == null) {
291 if (other.schema != null)
293 } else if (!schema.equals(other.schema))
296 if (other.type != null)
298 } else if (!type.equals(other.type))
300 if (parentUniqueId == null) {
301 if (other.parentUniqueId != null)
303 } else if (!parentUniqueId.equals(other.parentUniqueId))
305 if (uniqueId == null) {
306 if (other.uniqueId != null)
308 } else if (!uniqueId.equals(other.uniqueId))
314 public Object getToscaPresentationValue(JsonPresentationFields field) {
331 return super.getToscaPresentationValue(field);
335 protected <T extends PropertyDataDefinition> T overrideDataDefinition(T other, boolean allowDefaultValueOverride){
336 if(this.getType().equals(other.getType())){
337 other.setOwnerId(getOwnerId());
338 if(allowDefaultValueOverride)
339 other.setDefaultValue(getDefaultValue());
346 //return Either.right(propertyName) if an illegal merge was attempted (overriding data type is forbidden)
347 public static <T extends PropertyDataDefinition> Either<Map<String, T>, String> mergeProperties(Map<String, T> derivedProps, Map<String, T> importedProps, boolean allowDefaultValueOverride){
348 for(T property : importedProps.values()){
349 derivedProps.merge(property.getName(), property, (derivedProp, importedProp) -> derivedProp.overrideDataDefinition(importedProp, allowDefaultValueOverride));
350 //validate merge success
351 if(!derivedProps.containsKey(property.getName()))
352 return Either.right(property.getName());
354 return Either.left(derivedProps);
359 public static <T extends PropertyDataDefinition> Map<String, T> listToMapByName(List<T> propertiesList) {
360 return propertiesList.stream()
361 .collect(Collectors.toMap(p -> p.getName(), p -> p));