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.resources.data;
23 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
24 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
25 import org.openecomp.sdc.be.dao.utils.Constants;
26 import org.openecomp.sdc.be.datatypes.elements.HeatParameterDataDefinition;
27 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
29 import java.math.BigDecimal;
30 import java.util.HashMap;
33 public class HeatParameterData extends GraphNode {
35 private HeatParameterDataDefinition heatDataDefinition;
37 public HeatParameterData() {
38 super(NodeTypeEnum.HeatParameter);
39 heatDataDefinition = new HeatParameterDataDefinition();
42 public HeatParameterData(HeatParameterDataDefinition heatDataDef) {
43 super(NodeTypeEnum.HeatParameter);
44 this.heatDataDefinition = heatDataDef;
47 public HeatParameterData(Map<String, Object> properties) {
50 heatDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
51 heatDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
52 String type = (String) properties.get(GraphPropertiesDictionary.TYPE.getProperty());
53 heatDataDefinition.setType(type);
55 String description = (String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty());
56 if (Constants.GRAPH_EMPTY_VALUE.equals(description)) {
57 heatDataDefinition.setDescription(null);
59 heatDataDefinition.setDescription(description);
62 String defaultValue = (String) properties.get(GraphPropertiesDictionary.DEFAULT_VALUE.getProperty());
63 if (Constants.GRAPH_EMPTY_VALUE.equals(defaultValue)) {
64 heatDataDefinition.setDefaultValue(null);
66 heatDataDefinition.setDefaultValue(getValue(type, defaultValue));
69 String value = (String) properties.get(GraphPropertiesDictionary.VALUE.getProperty());
70 if (Constants.GRAPH_EMPTY_VALUE.equals(value)) {
71 heatDataDefinition.setCurrentValue(null);
73 heatDataDefinition.setCurrentValue(getValue(type, value));
78 private String getValue(String type, String value) {
79 if (Constants.GRAPH_EMPTY_VALUE.equals(value)) {
82 if ("number".equals(type)) {
83 return new BigDecimal(value).toPlainString();
88 public HeatParameterDataDefinition getHeatDataDefinition() {
89 return heatDataDefinition;
92 public void setHeatDataDefinition(HeatParameterDataDefinition heatDataDefinition) {
93 this.heatDataDefinition = heatDataDefinition;
96 public String getName() {
97 return heatDataDefinition.getName();
100 public void setName(String name) {
101 heatDataDefinition.setName(name);
104 public String getType() {
105 return heatDataDefinition.getType();
108 public void setType(String type) {
109 heatDataDefinition.setType(type);
112 public String getDescription() {
113 return heatDataDefinition.getDescription();
116 public void setDescription(String description) {
117 heatDataDefinition.setDescription(description);
120 public String getCurrentValue() {
121 return heatDataDefinition.getCurrentValue();
124 public void setCurrentValue(String currentValue) {
125 heatDataDefinition.setCurrentValue(currentValue);
128 public String getDefaultValue() {
129 return heatDataDefinition.getDefaultValue();
132 public void setDefaultValue(String defaultValue) {
133 heatDataDefinition.setDefaultValue(defaultValue);
137 public String getUniqueId() {
138 return heatDataDefinition.getUniqueId();
142 public Map<String, Object> toGraphMap() {
143 Map<String, Object> map = new HashMap<>();
145 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, getUniqueId());
147 addIfExists(map, GraphPropertiesDictionary.NAME, getName());
149 addIfExists(map, GraphPropertiesDictionary.TYPE, getType());
151 String description = getDescription();
152 if (description == null) {
153 description = Constants.GRAPH_EMPTY_VALUE;
155 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, description);
157 String defaultVal = getDefaultValue();
158 if (defaultVal == null) {
159 defaultVal = Constants.GRAPH_EMPTY_VALUE;
161 addIfExists(map, GraphPropertiesDictionary.DEFAULT_VALUE, getValue(getType(), defaultVal));
163 String currentVal = getCurrentValue();
164 if (currentVal == null) {
165 currentVal = Constants.GRAPH_EMPTY_VALUE;
168 addIfExists(map, GraphPropertiesDictionary.VALUE, getValue(getType(), currentVal));