re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / GroupData.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;
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.elements.GroupDataDefinition;
26 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
27
28 import java.util.HashMap;
29 import java.util.Map;
30
31 public class GroupData extends GraphNode {
32
33         GroupDataDefinition groupDataDefinition;
34
35         public GroupData() {
36                 super(NodeTypeEnum.Group);
37                 groupDataDefinition = new GroupDataDefinition();
38         }
39
40         public GroupData(GroupDataDefinition groupDataDefinition) {
41                 super(NodeTypeEnum.Group);
42                 this.groupDataDefinition = groupDataDefinition;
43         }
44
45         public GroupData(Map<String, Object> properties) {
46
47                 super(NodeTypeEnum.Group);
48
49                 groupDataDefinition = new GroupDataDefinition();
50
51                 groupDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
52                 groupDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
53                 groupDataDefinition.setType((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
54                 groupDataDefinition.setVersion((String) properties.get(GraphPropertiesDictionary.VERSION.getProperty()));
55                 groupDataDefinition
56                                 .setInvariantUUID((String) properties.get(GraphPropertiesDictionary.INVARIANT_UUID.getProperty()));
57                 groupDataDefinition.setGroupUUID((String) properties.get(GraphPropertiesDictionary.GROUP_UUID.getProperty()));
58                 groupDataDefinition
59                                 .setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
60                 groupDataDefinition.setPropertyValueCounter(
61                                 (Integer) properties.get(GraphPropertiesDictionary.PROPERTY_COUNTER.getProperty()));
62
63         }
64
65         @Override
66         public String getUniqueId() {
67                 return groupDataDefinition.getUniqueId();
68         }
69
70         @Override
71         public Map<String, Object> toGraphMap() {
72                 Map<String, Object> map = new HashMap<>();
73                 addIfExists(map, GraphPropertiesDictionary.NAME, groupDataDefinition.getName());
74                 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, groupDataDefinition.getUniqueId());
75                 addIfExists(map, GraphPropertiesDictionary.TYPE, groupDataDefinition.getType());
76                 addIfExists(map, GraphPropertiesDictionary.VERSION, groupDataDefinition.getVersion());
77                 addIfExists(map, GraphPropertiesDictionary.INVARIANT_UUID, groupDataDefinition.getInvariantUUID());
78                 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, groupDataDefinition.getDescription());
79                 addIfExists(map, GraphPropertiesDictionary.PROPERTY_COUNTER, groupDataDefinition.getPropertyValueCounter());
80                 addIfExists(map, GraphPropertiesDictionary.GROUP_UUID, groupDataDefinition.getGroupUUID());
81
82                 return map;
83         }
84
85         public GroupDataDefinition getGroupDataDefinition() {
86                 return groupDataDefinition;
87         }
88
89         public void setGroupDataDefinition(GroupDataDefinition groupDataDefinition) {
90                 this.groupDataDefinition = groupDataDefinition;
91         }
92
93         @Override
94         public String toString() {
95                 return "GroupData [ " + groupDataDefinition.toString() + "]";
96         }
97 }