re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / CategoryData.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.enums.NodeTypeEnum;
26
27 import java.util.HashMap;
28 import java.util.Map;
29
30 public abstract class CategoryData extends GraphNode {
31
32         private String name;
33         private String normalizedName;
34         private String uniqueId;
35
36         protected abstract void createUniqueId();
37
38         protected CategoryData(NodeTypeEnum label) {
39                 super(label);
40         }
41
42         protected CategoryData(String name, String normalizedName, NodeTypeEnum label) {
43                 super(label);
44                 this.name = name;
45                 this.normalizedName = normalizedName;
46         }
47
48         protected CategoryData(Map<String, Object> properties, NodeTypeEnum label) {
49                 super(label);
50                 setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
51                 setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
52                 setNormalizedName((String) properties.get(GraphPropertiesDictionary.NORMALIZED_NAME.getProperty()));
53         }
54
55         @Override
56         public Map<String, Object> toGraphMap() {
57                 Map<String, Object> map = new HashMap<>();
58                 addIfExists(map, GraphPropertiesDictionary.NAME, name);
59                 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, uniqueId);
60                 addIfExists(map, GraphPropertiesDictionary.NORMALIZED_NAME, normalizedName);
61                 return map;
62         }
63
64         public String getName() {
65                 return name;
66         }
67
68         public void setName(String name) {
69                 this.name = name;
70         }
71
72         public String getNormalizedName() {
73                 return normalizedName;
74         }
75
76         public void setNormalizedName(String normalizedName) {
77                 this.normalizedName = normalizedName;
78         }
79
80         public void setUniqueId(String uniqueId) {
81                 this.uniqueId = uniqueId;
82         }
83
84         @Override
85         public String toString() {
86                 return "CategoryData [name=" + name + ", normalizedName=" + normalizedName + "uniqueId=" + uniqueId + "]";
87         }
88
89         /*
90          * @Override public int hashCode() { final int prime = 31; int result = 1;
91          * result = prime * result + ((name == null) ? 0 : name.hashCode()); result
92          * = prime * result + ((uniqueId == null) ? 0 : uniqueId.hashCode()); return
93          * result; }
94          * 
95          * @Override public boolean equals(Object obj) { if (this == obj) return
96          * true; if (obj == null) return false; if (getClass() != obj.getClass())
97          * return false; CategoryData other = (CategoryData) obj; if (name == null)
98          * { if (other.name != null) return false; } else if
99          * (!name.equals(other.name)) return false; if (uniqueId == null) { if
100          * (other.uniqueId != null) return false; } else if
101          * (!uniqueId.equals(other.uniqueId)) return false; return true; }
102          */
103
104         @Override
105         public String getUniqueIdKey() {
106                 return GraphPropertiesDictionary.UNIQUE_ID.getProperty();
107         }
108
109         @Override
110         public String getUniqueId() {
111                 return uniqueId;
112         }
113
114 }