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=========================================================
20 package org.openecomp.sdc.be.resources.data.category;
22 import com.google.gson.reflect.TypeToken;
23 import java.lang.reflect.Type;
24 import java.util.HashMap;
25 import java.util.List;
27 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
28 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
29 import org.openecomp.sdc.be.datatypes.category.MetadataKeyDataDefinition;
30 import org.openecomp.sdc.be.datatypes.category.SubCategoryDataDefinition;
31 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
33 public class SubCategoryData extends GraphNode {
35 private SubCategoryDataDefinition subCategoryDataDefinition;
37 public SubCategoryData(NodeTypeEnum label) {
39 subCategoryDataDefinition = new SubCategoryDataDefinition();
42 public SubCategoryData(NodeTypeEnum label, SubCategoryDataDefinition subCategoryDataDefinition) {
44 this.subCategoryDataDefinition = subCategoryDataDefinition;
47 public SubCategoryData(Map<String, Object> properties) {
48 this(NodeTypeEnum.getByName((String) properties.get(GraphPropertiesDictionary.LABEL.getProperty())));
49 subCategoryDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
50 subCategoryDataDefinition.setNormalizedName((String) properties.get(GraphPropertiesDictionary.NORMALIZED_NAME.getProperty()));
51 subCategoryDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
52 Type listType = new TypeToken<List<String>>() {
54 List<String> iconsfromJson = getGson().fromJson((String) properties.get(GraphPropertiesDictionary.ICONS.getProperty()), listType);
55 subCategoryDataDefinition.setIcons(iconsfromJson);
56 final Type metadataKeylistType = new TypeToken<List<MetadataKeyDataDefinition>>() {
58 final List<MetadataKeyDataDefinition> metadataKeysfromJson = getGson()
59 .fromJson((String) properties.get(GraphPropertiesDictionary.METADATA_KEYS.getProperty()), metadataKeylistType);
60 subCategoryDataDefinition.setMetadataKeys(metadataKeysfromJson);
63 public SubCategoryDataDefinition getSubCategoryDataDefinition() {
64 return subCategoryDataDefinition;
68 public String getUniqueId() {
69 return subCategoryDataDefinition.getUniqueId();
73 public Map<String, Object> toGraphMap() {
74 Map<String, Object> map = new HashMap<>();
75 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, subCategoryDataDefinition.getUniqueId());
76 addIfExists(map, GraphPropertiesDictionary.NAME, subCategoryDataDefinition.getName());
77 addIfExists(map, GraphPropertiesDictionary.NORMALIZED_NAME, subCategoryDataDefinition.getNormalizedName());
78 // String icons=getGson().toJson(subCategoryDataDefinition.getIcons());
80 // addIfExists(map, GraphPropertiesDictionary.ICONS, icons);
81 addIfExists(map, GraphPropertiesDictionary.ICONS, subCategoryDataDefinition.getIcons());
82 addIfExists(map, GraphPropertiesDictionary.METADATA_KEYS, subCategoryDataDefinition.getMetadataKeys());