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 org.janusgraph.core.JanusGraphVertex;
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.InstantiationTypes;
30 import org.openecomp.sdc.be.datatypes.enums.JsonPresentationFields;
31 import org.openecomp.sdc.be.datatypes.tosca.ToscaDataDefinition;
33 import java.util.HashMap;
35 import java.util.Map.Entry;
37 public class GraphVertex {
38 private String uniqueId;
40 private JanusGraphVertex vertex;
41 private VertexTypeEnum label;
43 private Map<String, ? extends ToscaDataDefinition> json;
44 private Map<String, Object> metadataJson;
45 private Map<GraphPropertyEnum, Object> metadataProperties;
47 public GraphVertex() {
51 public GraphVertex(VertexTypeEnum label) {
56 public String getUniqueId() {
60 public void setUniqueId(String uniqueId) {
61 this.uniqueId = uniqueId;
62 addMetadataProperty(GraphPropertyEnum.UNIQUE_ID, uniqueId);
65 public Map<String, ? extends ToscaDataDefinition> getJson() {
69 public void setJson(Map<String, ? extends ToscaDataDefinition> json) {
73 public JanusGraphVertex getVertex() {
77 public void setVertex(JanusGraphVertex vertex) {
81 public VertexTypeEnum getLabel() {
85 public void setLabel(VertexTypeEnum label) {
89 public ComponentTypeEnum getType() {
90 return ComponentTypeEnum.valueOf((String) getMetadataProperty(GraphPropertyEnum.COMPONENT_TYPE));
93 public void setType(ComponentTypeEnum type) {
94 addMetadataProperty(GraphPropertyEnum.COMPONENT_TYPE, type.name());
97 public void addMetadataProperty(GraphPropertyEnum propName, Object propValue) {
98 if (metadataProperties == null) {
99 metadataProperties = new HashMap<>();
101 if (propValue != null) {
102 metadataProperties.put(propName, propValue);
106 public Object getMetadataProperty(GraphPropertyEnum metadataProperty) {
107 if (metadataProperties != null) {
108 return metadataProperties.get(metadataProperty);
113 public Map<GraphPropertyEnum, Object> getMetadataProperties() {
114 return metadataProperties;
117 public void setMetadataProperties(Map<GraphPropertyEnum, Object> metadataProperties) {
118 this.metadataProperties = metadataProperties;
121 public void getOrSetDefaultInstantiationTypeForToscaElementJson(){
122 String toscaVertexJsonInstantiationType;
123 toscaVertexJsonInstantiationType = (String)(this.getJsonMetadataField(JsonPresentationFields.INSTANTIATION_TYPE));
124 if (toscaVertexJsonInstantiationType == StringUtils.EMPTY || toscaVertexJsonInstantiationType == null){
125 this.setJsonMetadataField(JsonPresentationFields.INSTANTIATION_TYPE, InstantiationTypes.A_LA_CARTE.getValue());
129 public Map<String, Object> getMetadataJson() {
133 public void setMetadataJson(Map<String, Object> metadataJson) {
134 this.metadataJson = metadataJson;
138 * used for clone vertex in case of copy on update
142 public void cloneData(GraphVertex other) {
143 // need to be deep copy???
144 json = other.getJson();
145 metadataJson = other.getMetadataJson();
146 metadataProperties = other.getMetadataProperties();
149 public void setJsonMetadataField(JsonPresentationFields field, Object value) {
150 if (metadataJson == null) {
151 metadataJson = new HashMap<>();
153 metadataJson.put(field.getPresentation(), value);
156 public Object getJsonMetadataField(JsonPresentationFields field) {
157 if (metadataJson != null) {
158 return metadataJson.get(field.getPresentation());
164 * 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
165 * a property that is not presented in metadataProperties. In such case the property will be put in metadata json.
167 public void updateMetadataJsonWithCurrentMetadataProperties() {
168 if (!MapUtils.isEmpty(metadataProperties)) {
169 if (metadataJson == null) {
170 metadataJson = new HashMap<>();
172 for (Entry<GraphPropertyEnum, Object> entry : metadataProperties.entrySet()) {
173 String propertyName = JsonPresentationFields.getPresentationByGraphProperty(entry.getKey());
174 if (StringUtils.isNotEmpty(propertyName) && entry.getValue() != null) {
175 metadataJson.put(propertyName, entry.getValue());