re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / PropertyValueData.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 com.google.gson.reflect.TypeToken;
24 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
25 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
26 import org.openecomp.sdc.be.dao.utils.Constants;
27 import org.openecomp.sdc.be.datatypes.elements.PropertyRule;
28 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
29
30 import java.lang.reflect.Type;
31 import java.util.HashMap;
32 import java.util.List;
33 import java.util.Map;
34
35 public class PropertyValueData extends GraphNode {
36
37         public PropertyValueData() {
38                 super(NodeTypeEnum.PropertyValue);
39         }
40
41         public PropertyValueData(Map<String, Object> properties) {
42                 this();
43
44                 this.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
45
46                 String updatedValue = (String) properties.get(GraphPropertiesDictionary.VALUE.getProperty());
47                 if (Constants.GRAPH_EMPTY_VALUE.equals(updatedValue)) {
48                         this.setValue(null);
49                 } else {
50                         this.setValue(updatedValue);
51                 }
52
53                 this.setType((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
54
55                 this.setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
56
57                 this.setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
58
59                 Type mapType = new TypeToken<List<PropertyRule>>() {
60                 }.getType();
61                 List<PropertyRule> propertyRules = getGson().fromJson(
62                                 (String) properties.get(GraphPropertiesDictionary.PROPERTY_VALUE_RULES.getProperty()), mapType);
63                 this.setRules(propertyRules);
64
65         }
66
67         private String uniqueId;
68
69         private String value;
70
71         private String type;
72
73         private Long creationTime;
74
75         private Long modificationTime;
76
77         private List<PropertyRule> rules;
78
79         @Override
80         public String getUniqueId() {
81                 return uniqueId;
82         }
83
84         public void setUniqueId(String uniqueId) {
85                 this.uniqueId = uniqueId;
86         }
87
88         public String getType() {
89                 return type;
90         }
91
92         public void setType(String type) {
93                 this.type = type;
94         }
95
96         public Long getCreationTime() {
97                 return creationTime;
98         }
99
100         public void setCreationTime(Long creationTime) {
101                 this.creationTime = creationTime;
102         }
103
104         public Long getModificationTime() {
105                 return modificationTime;
106         }
107
108         public void setModificationTime(Long modificationTime) {
109                 this.modificationTime = modificationTime;
110         }
111
112         public String getValue() {
113                 return value;
114         }
115
116         public void setValue(String value) {
117                 this.value = value;
118         }
119
120         public List<PropertyRule> getRules() {
121                 return rules;
122         }
123
124         public void setRules(List<PropertyRule> rules) {
125                 this.rules = rules;
126         }
127
128         @Override
129         public Map<String, Object> toGraphMap() {
130
131                 Map<String, Object> map = new HashMap<>();
132
133                 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, uniqueId);
134
135                 String updatedValue = value;
136                 if (updatedValue == null) {
137                         updatedValue = Constants.GRAPH_EMPTY_VALUE;
138                 }
139                 addIfExists(map, GraphPropertiesDictionary.VALUE, updatedValue);
140
141                 addIfExists(map, GraphPropertiesDictionary.TYPE, type);
142
143                 addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, creationTime);
144
145                 addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE, modificationTime);
146
147                 addIfExists(map, GraphPropertiesDictionary.PROPERTY_VALUE_RULES, rules);
148
149                 return map;
150         }
151
152         @Override
153         public String toString() {
154                 return "PropertyValueData [uniqueId=" + uniqueId + ", value=" + value + ", type=" + type + ", creationTime="
155                                 + creationTime + ", modificationTime=" + modificationTime + ", rules=" + rules + "]";
156         }
157
158 }