re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / category / SubCategoryData.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.category;
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.category.SubCategoryDataDefinition;
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 SubCategoryData extends GraphNode {
35
36         private SubCategoryDataDefinition subCategoryDataDefinition;
37
38         public SubCategoryData(NodeTypeEnum label) {
39                 super(label);
40                 subCategoryDataDefinition = new SubCategoryDataDefinition();
41         }
42
43         public SubCategoryData(NodeTypeEnum label, SubCategoryDataDefinition subCategoryDataDefinition) {
44                 super(label);
45                 this.subCategoryDataDefinition = subCategoryDataDefinition;
46         }
47
48         public SubCategoryData(Map<String, Object> properties) {
49                 this(NodeTypeEnum.getByName((String) properties.get(GraphPropertiesDictionary.LABEL.getProperty())));
50
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()));
56
57                 Type listType = new TypeToken<List<String>>() {
58                 }.getType();
59                 List<String> iconsfromJson = getGson()
60                                 .fromJson((String) properties.get(GraphPropertiesDictionary.ICONS.getProperty()), listType);
61                 subCategoryDataDefinition.setIcons(iconsfromJson);
62         }
63
64         public SubCategoryDataDefinition getSubCategoryDataDefinition() {
65                 return subCategoryDataDefinition;
66         }
67
68         @Override
69         public String getUniqueId() {
70                 return subCategoryDataDefinition.getUniqueId();
71         }
72
73         @Override
74         public Map<String, Object> toGraphMap() {
75                 Map<String, Object> map = new HashMap<>();
76
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());
83                 return map;
84         }
85 }