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.SubCategoryDataDefinition;
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 SubCategoryData extends GraphNode {
36 private SubCategoryDataDefinition subCategoryDataDefinition;
38 public SubCategoryData(NodeTypeEnum label) {
40 subCategoryDataDefinition = new SubCategoryDataDefinition();
43 public SubCategoryData(NodeTypeEnum label, SubCategoryDataDefinition subCategoryDataDefinition) {
45 this.subCategoryDataDefinition = subCategoryDataDefinition;
48 public SubCategoryData(Map<String, Object> properties) {
49 this(NodeTypeEnum.getByName((String) properties.get(GraphPropertiesDictionary.LABEL.getProperty())));
51 subCategoryDataDefinition
52 .setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
53 subCategoryDataDefinition
54 .setNormalizedName((String) properties.get(GraphPropertiesDictionary.NORMALIZED_NAME.getProperty()));
55 subCategoryDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
57 Type listType = new TypeToken<List<String>>() {
59 List<String> iconsfromJson = getGson()
60 .fromJson((String) properties.get(GraphPropertiesDictionary.ICONS.getProperty()), listType);
61 subCategoryDataDefinition.setIcons(iconsfromJson);
64 public SubCategoryDataDefinition getSubCategoryDataDefinition() {
65 return subCategoryDataDefinition;
69 public String getUniqueId() {
70 return subCategoryDataDefinition.getUniqueId();
74 public Map<String, Object> toGraphMap() {
75 Map<String, Object> map = new HashMap<>();
77 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, subCategoryDataDefinition.getUniqueId());
78 addIfExists(map, GraphPropertiesDictionary.NAME, subCategoryDataDefinition.getName());
79 addIfExists(map, GraphPropertiesDictionary.NORMALIZED_NAME, subCategoryDataDefinition.getNormalizedName());
80 // String icons=getGson().toJson(subCategoryDataDefinition.getIcons());
81 // addIfExists(map, GraphPropertiesDictionary.ICONS, icons);
82 addIfExists(map, GraphPropertiesDictionary.ICONS, subCategoryDataDefinition.getIcons());