2 * ============LICENSE_START=======================================================
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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=========================================================
21 package org.openecomp.sdc.be.dao.jsongraph;
23 import com.thinkaurelius.titan.core.TitanVertex;
24 import org.apache.commons.collections.MapUtils;
25 import org.apache.commons.lang.StringUtils;
26 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
27 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
28 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
29 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
30 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
32 import java.util.HashMap;
34 import java.util.Map.Entry;
36 public class GraphVertex {
37 private String uniqueId;
39 private TitanVertex vertex;
40 private VertexTypeEnum label;
42 private Map<String, ? extends ToscaDataDefinition> json;
43 private Map<String, Object> metadataJson;
44 private Map<GraphPropertyEnum, Object> metadataProperties;
46 public GraphVertex() {
50 public GraphVertex(VertexTypeEnum label) {
55 public String getUniqueId() {
59 public void setUniqueId(String uniqueId) {
60 this.uniqueId = uniqueId;
63 public Map<String, ? extends ToscaDataDefinition> getJson() {
67 public void setJson(Map<String, ? extends ToscaDataDefinition> json) {
71 public TitanVertex getVertex() {
75 public void setVertex(TitanVertex vertex) {
79 public VertexTypeEnum getLabel() {
83 public void setLabel(VertexTypeEnum label) {
87 public ComponentTypeEnum getType() {
88 ComponentTypeEnum type = ComponentTypeEnum.valueOf((String) getMetadataProperty(GraphPropertyEnum.COMPONENT_TYPE));
92 public void setType(ComponentTypeEnum type) {
93 addMetadataProperty(GraphPropertyEnum.COMPONENT_TYPE, type.name());
96 public void addMetadataProperty(GraphPropertyEnum propName, Object propValue) {
97 if (metadataProperties == null) {
98 metadataProperties = new HashMap<>();
100 if (propValue != null) {
101 metadataProperties.put(propName, propValue);
105 public Object getMetadataProperty(GraphPropertyEnum metadataProperty) {
106 if (metadataProperties != null) {
107 return metadataProperties.get(metadataProperty);
112 public Map<GraphPropertyEnum, Object> getMetadataProperties() {
113 return metadataProperties;
116 public void setMetadataProperties(Map<GraphPropertyEnum, Object> metadataProperties) {
117 this.metadataProperties = metadataProperties;
120 public Map<String, Object> getMetadataJson() {
124 public void setMetadataJson(Map<String, Object> metadataJson) {
125 this.metadataJson = metadataJson;
129 * used for clone vertex in case of copy on update
133 public void cloneData(GraphVertex other) {
134 // need to be deep copy???
135 json = other.getJson();
136 metadataJson = other.getMetadataJson();
137 metadataProperties = other.getMetadataProperties();
140 public void setJsonMetadataField(JsonPresentationFields field, Object value) {
141 if (metadataJson == null) {
142 metadataJson = new HashMap<>();
144 metadataJson.put(field.getPresentation(), value);
147 public Object getJsonMetadataField(JsonPresentationFields field) {
148 if (metadataJson != null) {
149 return metadataJson.get(field.getPresentation());
155 * 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
156 * a property that is not presented in metadataProperties. In such case the property will be put in metadata json.
158 public void updateMetadataJsonWithCurrentMetadataProperties() {
159 if (!MapUtils.isEmpty(metadataProperties)) {
160 if (metadataJson == null) {
161 metadataJson = new HashMap<>();
163 for (Entry<GraphPropertyEnum, Object> entry : metadataProperties.entrySet()) {
164 String propertyName = JsonPresentationFields.getPresentationByGraphProperty(entry.getKey());
165 if (StringUtils.isNotEmpty(propertyName) && entry.getValue() != null) {
166 metadataJson.put(propertyName, entry.getValue());