Catalog alignment
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / dao / graph / datatype / GraphNode.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.dao.graph.datatype;
22
23 import com.google.gson.Gson;
24 import java.util.List;
25 import java.util.Map;
26 import org.apache.commons.lang3.tuple.ImmutablePair;
27 import org.openecomp.sdc.be.dao.jsongraph.heal.HealConstants;
28 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
29 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
30 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
31
32 public abstract class GraphNode extends GraphElement {
33
34         private static final Gson gson = new Gson();
35
36         private NodeTypeEnum label;
37
38         protected Gson getGson() {
39                 return gson;
40         }
41
42         protected GraphNode(NodeTypeEnum label) {
43                 super(GraphElementTypeEnum.Node);
44
45                 this.label = label;
46         }
47
48         public String getLabel() {
49                 return label.getName();
50         }
51
52         public ImmutablePair<String, Object> getKeyValueId() {
53         return new ImmutablePair<>(getUniqueIdKey(), getUniqueId());
54         }
55
56
57         public ImmutablePair<String, Object> getKeyValueIdForLog() {
58                 return getKeyValueId();
59         }
60
61         protected void addIfExists(Map<String, Object> map, GraphPropertiesDictionary property, Object value) {
62                 if (value != null) {
63                         if (value instanceof List || value instanceof Map) {
64                                 value = getGson().toJson(value);
65                         }
66                         map.put(property.getProperty(), value);
67                 }
68         }
69
70
71
72         public abstract String getUniqueId();
73
74
75         public String getUniqueIdKey() {
76                 return GraphPropertiesDictionary.UNIQUE_ID.getProperty();
77         }
78
79         public String getHealingVersionKey() {
80                 return GraphPropertyEnum.HEALING_VERSION.getProperty();
81         }
82
83         /**
84          * Must be overridden in implelemting classes
85          * @return current heal version. Default heal version if function not implemented.
86          */
87         public Integer getHealingVersion(){
88                 return HealConstants.DEFAULT_HEAL_VERSION;
89         }
90
91         /**
92          * Must be overriden in implementing classes
93          * @param version healing version number
94          */
95         public void setHealingVersion(Integer version){
96
97         }
98
99         @Override
100         public String toString() {
101                 return "GraphNode [label=" + label + ", parent: " + super.toString() + "]";
102         }
103
104
105 }