re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / category / GroupingData.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 org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
24 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
25 import org.openecomp.sdc.be.datatypes.category.GroupingDataDefinition;
26 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
27
28 import java.util.HashMap;
29 import java.util.Map;
30
31 public class GroupingData extends GraphNode {
32
33         private GroupingDataDefinition groupingDataDefinition;
34
35         public GroupingData(NodeTypeEnum label) {
36                 super(label);
37                 groupingDataDefinition = new GroupingDataDefinition();
38         }
39
40         public GroupingData(NodeTypeEnum label, GroupingDataDefinition groupingDataDefinition) {
41                 super(label);
42                 this.groupingDataDefinition = groupingDataDefinition;
43         }
44
45         public GroupingData(Map<String, Object> properties) {
46                 this(NodeTypeEnum.getByName((String) properties.get(GraphPropertiesDictionary.LABEL.getProperty())));
47
48                 groupingDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
49                 groupingDataDefinition
50                                 .setNormalizedName((String) properties.get(GraphPropertiesDictionary.NORMALIZED_NAME.getProperty()));
51                 groupingDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
52         }
53
54         public GroupingDataDefinition getGroupingDataDefinition() {
55                 return groupingDataDefinition;
56         }
57
58         @Override
59         public String getUniqueId() {
60                 return groupingDataDefinition.getUniqueId();
61         }
62
63         @Override
64         public Map<String, Object> toGraphMap() {
65                 Map<String, Object> map = new HashMap<>();
66
67                 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, groupingDataDefinition.getUniqueId());
68                 addIfExists(map, GraphPropertiesDictionary.NAME, groupingDataDefinition.getName());
69                 addIfExists(map, GraphPropertiesDictionary.NORMALIZED_NAME, groupingDataDefinition.getNormalizedName());
70                 return map;
71         }
72
73 }