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.category;
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.category.CategoryDataDefinition;
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 CategoryData extends GraphNode {
35 private CategoryDataDefinition categoryDataDefinition;
37 public CategoryData(NodeTypeEnum label) {
39 categoryDataDefinition = new CategoryDataDefinition();
42 public CategoryData(NodeTypeEnum label, CategoryDataDefinition categoryDataDefinition) {
44 this.categoryDataDefinition = categoryDataDefinition;
47 public CategoryData(Map<String, Object> properties) {
48 this(NodeTypeEnum.getByName((String) properties.get(GraphPropertiesDictionary.LABEL.getProperty())));
50 categoryDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
51 categoryDataDefinition
52 .setNormalizedName((String) properties.get(GraphPropertiesDictionary.NORMALIZED_NAME.getProperty()));
53 categoryDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
55 Type listType = new TypeToken<List<String>>() {
57 List<String> iconsfromJson = getGson()
58 .fromJson((String) properties.get(GraphPropertiesDictionary.ICONS.getProperty()), listType);
59 categoryDataDefinition.setIcons(iconsfromJson);
63 public String getUniqueId() {
64 return categoryDataDefinition.getUniqueId();
67 public CategoryDataDefinition getCategoryDataDefinition() {
68 return categoryDataDefinition;
72 public Map<String, Object> toGraphMap() {
73 Map<String, Object> map = new HashMap<String, Object>();
75 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, categoryDataDefinition.getUniqueId());
76 addIfExists(map, GraphPropertiesDictionary.NAME, categoryDataDefinition.getName());
77 addIfExists(map, GraphPropertiesDictionary.NORMALIZED_NAME, categoryDataDefinition.getNormalizedName());
78 // String icons=getGson().toJson(categoryDataDefinition.getIcons());
79 // addIfExists(map, GraphPropertiesDictionary.ICONS, icons);
80 addIfExists(map, GraphPropertiesDictionary.ICONS, categoryDataDefinition.getIcons());
85 public String toString() {
86 return "CategoryData [categoryDataDefinition=" + categoryDataDefinition + "]";