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 java.lang.reflect.Type;
24 import java.util.HashMap;
27 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
28 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
29 import org.openecomp.sdc.be.dao.utils.Constants;
30 import org.openecomp.sdc.be.datatypes.elements.PropertyDataDefinition;
31 import org.openecomp.sdc.be.datatypes.elements.SchemaDefinition;
32 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
34 import com.google.gson.reflect.TypeToken;
36 public class AttributeData extends GraphNode {
37 PropertyDataDefinition attributeDataDefinition;
39 public AttributeData() {
40 super(NodeTypeEnum.Attribute);
41 attributeDataDefinition = new PropertyDataDefinition();
44 public AttributeData(PropertyDataDefinition attributeDataDefinition) {
45 super(NodeTypeEnum.Attribute);
46 this.attributeDataDefinition = attributeDataDefinition;
50 public String toString() {
51 return "AttributeData [attributeDataDefinition=" + attributeDataDefinition + "]";
55 public String getUniqueId() {
56 return attributeDataDefinition.getUniqueId();
59 public PropertyDataDefinition getAttributeDataDefinition() {
60 return attributeDataDefinition;
63 public void setAttributeDataDefinition(PropertyDataDefinition attributeDataDefinition) {
64 this.attributeDataDefinition = attributeDataDefinition;
67 public AttributeData(Map<String, Object> properties) {
71 attributeDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
73 attributeDataDefinition.setType((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
75 attributeDataDefinition
76 .setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
78 String defaultValue = (String) properties.get(GraphPropertiesDictionary.DEFAULT_VALUE.getProperty());
79 if (Constants.GRAPH_EMPTY_VALUE.equals(defaultValue)) {
80 attributeDataDefinition.setDefaultValue(null);
82 attributeDataDefinition.setDefaultValue(defaultValue);
85 attributeDataDefinition.setStatus((String) properties.get(GraphPropertiesDictionary.STATUS.getProperty()));
87 attributeDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
89 attributeDataDefinition.setValue((String) properties.get(GraphPropertiesDictionary.VALUE.getProperty()));
91 Type schemaType = new TypeToken<SchemaDefinition>() {
93 SchemaDefinition schema = getGson()
94 .fromJson((String) properties.get(GraphPropertiesDictionary.ENTRY_SCHEMA.getProperty()), schemaType);
95 attributeDataDefinition.setSchema(schema);
99 public Map<String, Object> toGraphMap() {
101 Map<String, Object> map = new HashMap<String, Object>();
103 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, attributeDataDefinition.getUniqueId());
105 addIfExists(map, GraphPropertiesDictionary.TYPE, attributeDataDefinition.getType());
107 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, attributeDataDefinition.getDescription());
109 String defaultValue = attributeDataDefinition.getDefaultValue();
110 if (defaultValue == null) {
111 defaultValue = Constants.GRAPH_EMPTY_VALUE;
114 addIfExists(map, GraphPropertiesDictionary.DEFAULT_VALUE, defaultValue);
116 addIfExists(map, GraphPropertiesDictionary.STATUS, attributeDataDefinition.getStatus());
118 addIfExists(map, GraphPropertiesDictionary.NAME, attributeDataDefinition.getName());
120 addIfExists(map, GraphPropertiesDictionary.VALUE, attributeDataDefinition.getValue());
122 SchemaDefinition entrySchema = attributeDataDefinition.getSchema();
123 if (entrySchema != null) {
124 String entrySchemaStr = getGson().toJson(entrySchema);
125 addIfExists(map, GraphPropertiesDictionary.ENTRY_SCHEMA, entrySchemaStr);