aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-dao/src/main/java/org/openecomp/sdc/be/dao/jsongraph/GraphVertex.java
blob: 67cbd258f49eeee31676a124522ab4cd929d1fdb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package org.openecomp.sdc.be.dao.jsongraph;

import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang.StringUtils;
import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;

import com.thinkaurelius.titan.core.TitanVertex;

public class GraphVertex {
	private String uniqueId;

	private TitanVertex vertex;
	private VertexTypeEnum label;

	private Map<String, ? extends ToscaDataDefinition> json;
	private Map<String, Object> metadataJson;
	private Map<GraphPropertyEnum, Object> metadataProperties;

	public GraphVertex() {

	}

	public GraphVertex(VertexTypeEnum label) {
		super();
		this.label = label;
	}

	public String getUniqueId() {
		return uniqueId;
	}

	public void setUniqueId(String uniqueId) {
		this.uniqueId = uniqueId;
	}

	public Map<String, ? extends ToscaDataDefinition> getJson() {
		return json;
	}

	public void setJson(Map<String, ? extends ToscaDataDefinition> json) {
		this.json = json;
	}

	public TitanVertex getVertex() {
		return vertex;
	}

	public void setVertex(TitanVertex vertex) {
		this.vertex = vertex;
	}

	public VertexTypeEnum getLabel() {
		return label;
	}

	public void setLabel(VertexTypeEnum label) {
		this.label = label;
	}

	public ComponentTypeEnum getType() {
		ComponentTypeEnum type = ComponentTypeEnum.valueOf((String) getMetadataProperty(GraphPropertyEnum.COMPONENT_TYPE));
		return type;
	}

	public void setType(ComponentTypeEnum type) {
		addMetadataProperty(GraphPropertyEnum.COMPONENT_TYPE, type.name());
	}

	public void addMetadataProperty(GraphPropertyEnum propName, Object propValue) {
		if (metadataProperties == null) {
			metadataProperties = new HashMap<>();
		}
		if (propValue != null) {
			metadataProperties.put(propName, propValue);
		}
	}

	public Object getMetadataProperty(GraphPropertyEnum metadataProperty) {
		if (metadataProperties != null) {
			return metadataProperties.get(metadataProperty);
		}
		return null;
	}

	public Map<GraphPropertyEnum, Object> getMetadataProperties() {
		return metadataProperties;
	}

	public void setMetadataProperties(Map<GraphPropertyEnum, Object> metadataProperties) {
		this.metadataProperties = metadataProperties;
	}

	public Map<String, Object> getMetadataJson() {
		return metadataJson;
	}

	public void setMetadataJson(Map<String, Object> metadataJson) {
		this.metadataJson = metadataJson;
	}

	/**
	 * used for clone vertex in case of copy on update
	 * 
	 * @param other
	 */
	public void cloneData(GraphVertex other) {
		// need to be deep copy???
		json = other.getJson();
		metadataJson = other.getMetadataJson();
		metadataProperties = other.getMetadataProperties();
	}

	public void setJsonMetadataField(JsonPresentationFields field, Object value) {
		if (metadataJson == null) {
			metadataJson = new HashMap<>();
		}
		metadataJson.put(field.getPresentation(), value);
	}

	public Object getJsonMetadataField(JsonPresentationFields field) {
		if (metadataJson != null) {
			return metadataJson.get(field.getPresentation());
		}
		return null;
	}

	/**
	 * Updates metadata json with current metadataProperties. Note that already existing property containing in metadata json can be overrided by new value if metadataProperties contains the same property (by key). Note that metadata json can contain
	 * a property that is not presented in metadataProperties. In such case the property will be put in metadata json.
	 */
	public void updateMetadataJsonWithCurrentMetadataProperties() {
		if (!MapUtils.isEmpty(metadataProperties)) {
			if (metadataJson == null) {
				metadataJson = new HashMap<>();
			}
			for (Entry<GraphPropertyEnum, Object> entry : metadataProperties.entrySet()) {
				String propertyName = JsonPresentationFields.getPresentationByGraphProperty(entry.getKey());
				if (StringUtils.isNotEmpty(propertyName) && entry.getValue() != null) {
					metadataJson.put(propertyName, entry.getValue());
				}
			}
		}
	}
}