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=========================================================
20 package org.openecomp.sdc.be.resources.data;
22 import com.google.gson.reflect.TypeToken;
23 import java.lang.reflect.Type;
24 import java.util.HashMap;
25 import java.util.List;
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 public class InputsData extends GraphNode {
36 PropertyDataDefinition propertyDataDefinition;
37 private List<String> constraints;
40 super(NodeTypeEnum.Input);
41 propertyDataDefinition = new PropertyDataDefinition();
44 public InputsData(PropertyDataDefinition propertyDataDefinition, List<String> constraints) {
45 super(NodeTypeEnum.Input);
46 this.propertyDataDefinition = propertyDataDefinition;
47 this.constraints = constraints;
50 public InputsData(Map<String, Object> properties) {
52 propertyDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
53 propertyDataDefinition.setType((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
54 propertyDataDefinition.setRequired((Boolean) properties.get(GraphPropertiesDictionary.REQUIRED.getProperty()));
55 String defaultValue = (String) properties.get(GraphPropertiesDictionary.DEFAULT_VALUE.getProperty());
56 if (Constants.GRAPH_EMPTY_VALUE.equals(defaultValue)) {
57 propertyDataDefinition.setDefaultValue(null);
59 propertyDataDefinition.setDefaultValue(defaultValue);
61 propertyDataDefinition.setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
62 Type listType = new TypeToken<List<String>>() {
64 List<String> constraintsfromJson = getGson().fromJson((String) properties.get(GraphPropertiesDictionary.CONSTRAINTS.getProperty()), listType);
65 setConstraints(constraintsfromJson);
66 // setConstraints((List<String>)
68 // properties.get(GraphPropertiesDictionary.CONSTRAINTS.getProperty()));
69 Type schemaType = new TypeToken<SchemaDefinition>() {
71 SchemaDefinition schema = getGson().fromJson((String) properties.get(GraphPropertiesDictionary.ENTRY_SCHEMA.getProperty()), schemaType);
72 propertyDataDefinition.setSchema(schema);
76 public Map<String, Object> toGraphMap() {
77 Map<String, Object> map = new HashMap<>();
78 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, propertyDataDefinition.getUniqueId());
79 addIfExists(map, GraphPropertiesDictionary.TYPE, propertyDataDefinition.getType());
80 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, propertyDataDefinition.getDescription());
81 String defaultValue = propertyDataDefinition.getDefaultValue();
82 if (defaultValue == null) {
83 defaultValue = Constants.GRAPH_EMPTY_VALUE;
85 addIfExists(map, GraphPropertiesDictionary.DEFAULT_VALUE, defaultValue);
86 addIfExists(map, GraphPropertiesDictionary.REQUIRED, propertyDataDefinition.isRequired());
87 addIfExists(map, GraphPropertiesDictionary.CONSTRAINTS, getConstraints());
88 SchemaDefinition entrySchema = propertyDataDefinition.getSchema();
89 if (entrySchema != null) {
90 String entrySchemaStr = getGson().toJson(entrySchema);
91 addIfExists(map, GraphPropertiesDictionary.ENTRY_SCHEMA, entrySchemaStr);
93 // String constraintsAsJson = getGson().toJson(getConstraints());
95 // addIfExists(map, GraphPropertiesDictionary.CONSTRAINTS,
97 // constraintsAsJson);
101 public List<String> getConstraints() {
105 public void setConstraints(List<String> constraints) {
106 this.constraints = constraints;
110 public String getUniqueId() {
111 return propertyDataDefinition.getUniqueId();
114 public PropertyDataDefinition getPropertyDataDefinition() {
115 return propertyDataDefinition;
118 public void setPropertyDataDefinition(PropertyDataDefinition propertyDataDefinition) {
119 this.propertyDataDefinition = propertyDataDefinition;
123 public String toString() {
124 return "PropertyData [propertyDataDefinition=" + propertyDataDefinition + ", constraints=" + constraints + "]";