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.resources.data;
23 import com.google.gson.reflect.TypeToken;
24 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
25 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
26 import org.openecomp.sdc.be.dao.utils.Constants;
27 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
28 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
29 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
31 import java.lang.reflect.Type;
32 import java.util.HashMap;
35 public class AttributeData extends GraphNode {
36 PropertyDataDefinition attributeDataDefinition;
38 public AttributeData() {
39 super(NodeTypeEnum.Attribute);
40 attributeDataDefinition = new PropertyDataDefinition();
43 public AttributeData(PropertyDataDefinition attributeDataDefinition) {
44 super(NodeTypeEnum.Attribute);
45 this.attributeDataDefinition = attributeDataDefinition;
49 public String toString() {
50 return "AttributeData [attributeDataDefinition=" + attributeDataDefinition + "]";
54 public String getUniqueId() {
55 return attributeDataDefinition.getUniqueId();
58 public PropertyDataDefinition getAttributeDataDefinition() {
59 return attributeDataDefinition;
62 public void setAttributeDataDefinition(PropertyDataDefinition attributeDataDefinition) {
63 this.attributeDataDefinition = attributeDataDefinition;
66 public AttributeData(Map<String, Object> properties) {
70 attributeDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
72 attributeDataDefinition.setType((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
74 attributeDataDefinition
75 .setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
77 String defaultValue = (String) properties.get(GraphPropertiesDictionary.DEFAULT_VALUE.getProperty());
78 if (Constants.GRAPH_EMPTY_VALUE.equals(defaultValue)) {
79 attributeDataDefinition.setDefaultValue(null);
81 attributeDataDefinition.setDefaultValue(defaultValue);
84 attributeDataDefinition.setStatus((String) properties.get(GraphPropertiesDictionary.STATUS.getProperty()));
86 attributeDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
88 attributeDataDefinition.setValue((String) properties.get(GraphPropertiesDictionary.VALUE.getProperty()));
90 Type schemaType = new TypeToken<SchemaDefinition>() {
92 SchemaDefinition schema = getGson()
93 .fromJson((String) properties.get(GraphPropertiesDictionary.ENTRY_SCHEMA.getProperty()), schemaType);
94 attributeDataDefinition.setSchema(schema);
98 public Map<String, Object> toGraphMap() {
100 Map<String, Object> map = new HashMap<>();
102 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, attributeDataDefinition.getUniqueId());
104 addIfExists(map, GraphPropertiesDictionary.TYPE, attributeDataDefinition.getType());
106 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, attributeDataDefinition.getDescription());
108 String defaultValue = attributeDataDefinition.getDefaultValue();
109 if (defaultValue == null) {
110 defaultValue = Constants.GRAPH_EMPTY_VALUE;
113 addIfExists(map, GraphPropertiesDictionary.DEFAULT_VALUE, defaultValue);
115 addIfExists(map, GraphPropertiesDictionary.STATUS, attributeDataDefinition.getStatus());
117 addIfExists(map, GraphPropertiesDictionary.NAME, attributeDataDefinition.getName());
119 addIfExists(map, GraphPropertiesDictionary.VALUE, attributeDataDefinition.getValue());
121 SchemaDefinition entrySchema = attributeDataDefinition.getSchema();
122 if (entrySchema != null) {
123 String entrySchemaStr = getGson().toJson(entrySchema);
124 addIfExists(map, GraphPropertiesDictionary.ENTRY_SCHEMA, entrySchemaStr);