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 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;
29 import java.lang.reflect.Type;
30 import java.util.HashMap;
31 import java.util.List;
34 public class GroupTypeData extends GraphNode {
36 private static Type listType = new TypeToken<List<String>>() {
38 private static Type mapType = new TypeToken<HashMap<String, String>>() {
41 private GroupTypeDataDefinition groupTypeDataDefinition;
43 private GroupTypeData() {
44 super(NodeTypeEnum.GroupType);
45 groupTypeDataDefinition = new GroupTypeDataDefinition();
48 public GroupTypeData(GroupTypeDataDefinition groupTypeDataDefinition) {
49 super(NodeTypeEnum.GroupType);
50 this.groupTypeDataDefinition = groupTypeDataDefinition;
53 public GroupTypeData(Map<String, Object> properties) {
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()));
60 groupTypeDataDefinition.setType((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
62 groupTypeDataDefinition.setVersion((String) properties.get(GraphPropertiesDictionary.VERSION.getProperty()));
64 if (properties.get(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty()) != null) {
65 groupTypeDataDefinition.setHighestVersion(
66 (boolean) properties.get(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty()));
69 groupTypeDataDefinition
70 .setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
72 List<String> members = getGson()
73 .fromJson((String) properties.get(GraphPropertiesDictionary.MEMBERS.getProperty()), listType);
74 groupTypeDataDefinition.setMembers(members);
76 HashMap<String, String> metatdata = getGson()
77 .fromJson((String) properties.get(GraphPropertiesDictionary.METADATA.getProperty()), mapType);
78 groupTypeDataDefinition.setMetadata(metatdata);
80 groupTypeDataDefinition
81 .setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
83 groupTypeDataDefinition
84 .setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
89 public Map<String, Object> toGraphMap() {
91 Map<String, Object> map = new HashMap<>();
93 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, groupTypeDataDefinition.getUniqueId());
95 addIfExists(map, GraphPropertiesDictionary.TYPE, groupTypeDataDefinition.getType());
97 addIfExists(map, GraphPropertiesDictionary.NAME, groupTypeDataDefinition.getName());
99 addIfExists(map, GraphPropertiesDictionary.ICON, groupTypeDataDefinition.getIcon());
101 addIfExists(map, GraphPropertiesDictionary.VERSION, groupTypeDataDefinition.getVersion());
103 addIfExists(map, GraphPropertiesDictionary.IS_HIGHEST_VERSION, groupTypeDataDefinition.isHighestVersion());
105 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, groupTypeDataDefinition.getDescription());
107 addIfExists(map, GraphPropertiesDictionary.METADATA, groupTypeDataDefinition.getMetadata());
109 addIfExists(map, GraphPropertiesDictionary.MEMBERS, groupTypeDataDefinition.getMembers());
111 addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, groupTypeDataDefinition.getCreationTime());
113 addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE, groupTypeDataDefinition.getModificationTime());
118 public GroupTypeDataDefinition getGroupTypeDataDefinition() {
119 return groupTypeDataDefinition;
122 public void setGroupTypeDataDefinition(GroupTypeDataDefinition groupTypeDataDefinition) {
123 this.groupTypeDataDefinition = groupTypeDataDefinition;
127 public String toString() {
128 return "GroupTypeData [groupTypeDataDefinition=" + groupTypeDataDefinition + "]";
132 public String getUniqueId() {
133 return this.groupTypeDataDefinition.getUniqueId();