re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / GroupTypeData.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.datatypes.elements.GroupTypeDataDefinition;
27 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
28
29 import java.lang.reflect.Type;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33
34 public class GroupTypeData extends GraphNode {
35
36         private static Type listType = new TypeToken<List<String>>() {
37         }.getType();
38         private static Type mapType = new TypeToken<HashMap<String, String>>() {
39         }.getType();
40
41         private GroupTypeDataDefinition groupTypeDataDefinition;
42
43         private GroupTypeData() {
44                 super(NodeTypeEnum.GroupType);
45                 groupTypeDataDefinition = new GroupTypeDataDefinition();
46         }
47
48         public GroupTypeData(GroupTypeDataDefinition groupTypeDataDefinition) {
49                 super(NodeTypeEnum.GroupType);
50                 this.groupTypeDataDefinition = groupTypeDataDefinition;
51         }
52
53         public GroupTypeData(Map<String, Object> properties) {
54
55                 this();
56                 groupTypeDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
57                 groupTypeDataDefinition.setIcon((String) properties.get(GraphPropertiesDictionary.ICON.getProperty()));
58                 groupTypeDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
59
60                 groupTypeDataDefinition.setType((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
61
62                 groupTypeDataDefinition.setVersion((String) properties.get(GraphPropertiesDictionary.VERSION.getProperty()));
63                 
64                 if (properties.get(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty()) != null) {
65                         groupTypeDataDefinition.setHighestVersion(
66                                         (boolean) properties.get(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty()));
67                 }
68
69                 groupTypeDataDefinition
70                                 .setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
71
72                 List<String> members = getGson()
73                                 .fromJson((String) properties.get(GraphPropertiesDictionary.MEMBERS.getProperty()), listType);
74                 groupTypeDataDefinition.setMembers(members);
75
76                 HashMap<String, String> metatdata = getGson()
77                                 .fromJson((String) properties.get(GraphPropertiesDictionary.METADATA.getProperty()), mapType);
78                 groupTypeDataDefinition.setMetadata(metatdata);
79
80                 groupTypeDataDefinition
81                                 .setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
82
83                 groupTypeDataDefinition
84                                 .setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
85
86         }
87
88         @Override
89         public Map<String, Object> toGraphMap() {
90
91                 Map<String, Object> map = new HashMap<>();
92
93                 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, groupTypeDataDefinition.getUniqueId());
94
95                 addIfExists(map, GraphPropertiesDictionary.TYPE, groupTypeDataDefinition.getType());
96
97                 addIfExists(map, GraphPropertiesDictionary.NAME, groupTypeDataDefinition.getName());
98
99                 addIfExists(map, GraphPropertiesDictionary.ICON, groupTypeDataDefinition.getIcon());
100
101                 addIfExists(map, GraphPropertiesDictionary.VERSION, groupTypeDataDefinition.getVersion());
102
103                 addIfExists(map, GraphPropertiesDictionary.IS_HIGHEST_VERSION, groupTypeDataDefinition.isHighestVersion());
104
105                 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, groupTypeDataDefinition.getDescription());
106
107                 addIfExists(map, GraphPropertiesDictionary.METADATA, groupTypeDataDefinition.getMetadata());
108
109                 addIfExists(map, GraphPropertiesDictionary.MEMBERS, groupTypeDataDefinition.getMembers());
110
111                 addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, groupTypeDataDefinition.getCreationTime());
112
113                 addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE, groupTypeDataDefinition.getModificationTime());
114
115                 return map;
116         }
117
118         public GroupTypeDataDefinition getGroupTypeDataDefinition() {
119                 return groupTypeDataDefinition;
120         }
121
122         public void setGroupTypeDataDefinition(GroupTypeDataDefinition groupTypeDataDefinition) {
123                 this.groupTypeDataDefinition = groupTypeDataDefinition;
124         }
125
126         @Override
127         public String toString() {
128                 return "GroupTypeData [groupTypeDataDefinition=" + groupTypeDataDefinition + "]";
129         }
130
131         @Override
132         public String getUniqueId() {
133                 return this.groupTypeDataDefinition.getUniqueId();
134         }
135
136 }