re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / HeatParameterData.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.resources.data;
22
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;
28
29 import java.math.BigDecimal;
30 import java.util.HashMap;
31 import java.util.Map;
32
33 public class HeatParameterData extends GraphNode {
34
35         private HeatParameterDataDefinition heatDataDefinition;
36
37         public HeatParameterData() {
38                 super(NodeTypeEnum.HeatParameter);
39                 heatDataDefinition = new HeatParameterDataDefinition();
40         }
41
42         public HeatParameterData(HeatParameterDataDefinition heatDataDef) {
43                 super(NodeTypeEnum.HeatParameter);
44                 this.heatDataDefinition = heatDataDef;
45         }
46
47         public HeatParameterData(Map<String, Object> properties) {
48                 this();
49
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);
54
55                 String description = (String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty());
56                 if (Constants.GRAPH_EMPTY_VALUE.equals(description)) {
57                         heatDataDefinition.setDescription(null);
58                 } else {
59                         heatDataDefinition.setDescription(description);
60                 }
61
62                 String defaultValue = (String) properties.get(GraphPropertiesDictionary.DEFAULT_VALUE.getProperty());
63                 if (Constants.GRAPH_EMPTY_VALUE.equals(defaultValue)) {
64                         heatDataDefinition.setDefaultValue(null);
65                 } else {
66                         heatDataDefinition.setDefaultValue(getValue(type, defaultValue));
67                 }
68
69                 String value = (String) properties.get(GraphPropertiesDictionary.VALUE.getProperty());
70                 if (Constants.GRAPH_EMPTY_VALUE.equals(value)) {
71                         heatDataDefinition.setCurrentValue(null);
72                 } else {
73                         heatDataDefinition.setCurrentValue(getValue(type, value));
74                 }
75
76         }
77
78         private String getValue(String type, String value) {
79                 if (Constants.GRAPH_EMPTY_VALUE.equals(value)) {
80                         return value;
81                 }
82                 if ("number".equals(type)) {
83                         return new BigDecimal(value).toPlainString();
84                 }
85                 return value;
86         }
87
88         public HeatParameterDataDefinition getHeatDataDefinition() {
89                 return heatDataDefinition;
90         }
91
92         public void setHeatDataDefinition(HeatParameterDataDefinition heatDataDefinition) {
93                 this.heatDataDefinition = heatDataDefinition;
94         }
95
96         public String getName() {
97                 return heatDataDefinition.getName();
98         }
99
100         public void setName(String name) {
101                 heatDataDefinition.setName(name);
102         }
103
104         public String getType() {
105                 return heatDataDefinition.getType();
106         }
107
108         public void setType(String type) {
109                 heatDataDefinition.setType(type);
110         }
111
112         public String getDescription() {
113                 return heatDataDefinition.getDescription();
114         }
115
116         public void setDescription(String description) {
117                 heatDataDefinition.setDescription(description);
118         }
119
120         public String getCurrentValue() {
121                 return heatDataDefinition.getCurrentValue();
122         }
123
124         public void setCurrentValue(String currentValue) {
125                 heatDataDefinition.setCurrentValue(currentValue);
126         }
127
128         public String getDefaultValue() {
129                 return heatDataDefinition.getDefaultValue();
130         }
131
132         public void setDefaultValue(String defaultValue) {
133                 heatDataDefinition.setDefaultValue(defaultValue);
134         }
135
136         @Override
137         public String getUniqueId() {
138                 return heatDataDefinition.getUniqueId();
139         }
140
141         @Override
142         public Map<String, Object> toGraphMap() {
143                 Map<String, Object> map = new HashMap<>();
144
145                 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, getUniqueId());
146
147                 addIfExists(map, GraphPropertiesDictionary.NAME, getName());
148
149                 addIfExists(map, GraphPropertiesDictionary.TYPE, getType());
150
151                 String description = getDescription();
152                 if (description == null) {
153                         description = Constants.GRAPH_EMPTY_VALUE;
154                 }
155                 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, description);
156
157                 String defaultVal = getDefaultValue();
158                 if (defaultVal == null) {
159                         defaultVal = Constants.GRAPH_EMPTY_VALUE;
160                 }
161                 addIfExists(map, GraphPropertiesDictionary.DEFAULT_VALUE, getValue(getType(), defaultVal));
162
163                 String currentVal = getCurrentValue();
164                 if (currentVal == null) {
165                         currentVal = Constants.GRAPH_EMPTY_VALUE;
166                 }
167
168                 addIfExists(map, GraphPropertiesDictionary.VALUE, getValue(getType(), currentVal));
169                 return map;
170         }
171
172 }