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 java.util.HashMap;
25 import java.util.Map.Entry;
27 import org.apache.commons.collections.MapUtils;
28 import org.apache.commons.lang.StringUtils;
29 import org.openecomp.sdc.be.dao.jsongraph.types.VertexTypeEnum;
30 import org.openecomp.sdc.be.datatypes.enums.ComponentTypeEnum;
31 import org.openecomp.sdc.be.datatypes.enums.GraphPropertyEnum;
32 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
33 import org.openecomp.sdc.be.datatypes.enums.ResourceTypeEnum;
34 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
36 import com.thinkaurelius.titan.core.TitanVertex;
38 public class GraphVertex {
39 private String uniqueId;
41 private TitanVertex vertex;
42 private VertexTypeEnum label;
44 private Map<String, ? extends ToscaDataDefinition> json;
45 private Map<String, Object> metadataJson;
46 private Map<GraphPropertyEnum, Object> metadataProperties;
48 public GraphVertex() {
52 public GraphVertex(VertexTypeEnum label) {
57 public String getUniqueId() {
61 public void setUniqueId(String uniqueId) {
62 this.uniqueId = uniqueId;
65 public Map<String, ? extends ToscaDataDefinition> getJson() {
69 public void setJson(Map<String, ? extends ToscaDataDefinition> json) {
73 public TitanVertex getVertex() {
77 public void setVertex(TitanVertex vertex) {
81 public VertexTypeEnum getLabel() {
85 public void setLabel(VertexTypeEnum label) {
89 public ComponentTypeEnum getType() {
90 ComponentTypeEnum type = ComponentTypeEnum.valueOf((String) getMetadataProperty(GraphPropertyEnum.COMPONENT_TYPE));
94 public void setType(ComponentTypeEnum type) {
95 addMetadataProperty(GraphPropertyEnum.COMPONENT_TYPE, type.name());
98 public void addMetadataProperty(GraphPropertyEnum propName, Object propValue) {
99 if (metadataProperties == null) {
100 metadataProperties = new HashMap<>();
102 if (propValue != null) {
103 metadataProperties.put(propName, propValue);
107 public Object getMetadataProperty(GraphPropertyEnum metadataProperty) {
108 if (metadataProperties != null) {
109 return metadataProperties.get(metadataProperty);
114 public Map<GraphPropertyEnum, Object> getMetadataProperties() {
115 return metadataProperties;
118 public void setMetadataProperties(Map<GraphPropertyEnum, Object> metadataProperties) {
119 this.metadataProperties = metadataProperties;
122 public Map<String, Object> getMetadataJson() {
126 public void setMetadataJson(Map<String, Object> metadataJson) {
127 this.metadataJson = metadataJson;
131 * used for clone vertex in case of copy on update
135 public void cloneData(GraphVertex other) {
136 // need to be deep copy???
137 json = other.getJson();
138 metadataJson = other.getMetadataJson();
139 metadataProperties = other.getMetadataProperties();
142 public void setJsonMetadataField(JsonPresentationFields field, Object value) {
143 if (metadataJson == null) {
144 metadataJson = new HashMap<>();
146 metadataJson.put(field.getPresentation(), value);
149 public Object getJsonMetadataField(JsonPresentationFields field) {
150 if (metadataJson != null) {
151 return metadataJson.get(field.getPresentation());
157 * 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
158 * a property that is not presented in metadataProperties. In such case the property will be put in metadata json.
160 public void updateMetadataJsonWithCurrentMetadataProperties() {
161 if (!MapUtils.isEmpty(metadataProperties)) {
162 if (metadataJson == null) {
163 metadataJson = new HashMap<>();
165 for (Entry<GraphPropertyEnum, Object> entry : metadataProperties.entrySet()) {
166 String propertyName = JsonPresentationFields.getPresentationByGraphProperty(entry.getKey());
167 if (StringUtils.isNotEmpty(propertyName) && entry.getValue() != null) {
168 metadataJson.put(propertyName, entry.getValue());