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.datatypes.elements.RelationshipInstDataDefinition;
27 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
29 import java.lang.reflect.Type;
30 import java.util.HashMap;
31 import java.util.List;
34 public class RelationshipTypeData extends GraphNode {
36 RelationshipInstDataDefinition relationshipTypeDataDefinition;
38 public RelationshipTypeData() {
39 super(NodeTypeEnum.RelationshipType);
40 relationshipTypeDataDefinition = new RelationshipInstDataDefinition();
43 public RelationshipTypeData(RelationshipInstDataDefinition relationshipTypeDataDefinition) {
44 super(NodeTypeEnum.RelationshipType);
45 this.relationshipTypeDataDefinition = relationshipTypeDataDefinition;
48 public RelationshipTypeData(Map<String, Object> properties) {
52 relationshipTypeDataDefinition
53 .setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
55 relationshipTypeDataDefinition.setType((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
57 relationshipTypeDataDefinition
58 .setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
60 Type listType = new TypeToken<List<String>>() {
62 List<String> validSourceTypesfromJson = getGson().fromJson(
63 (String) properties.get(GraphPropertiesDictionary.VALID_SOURCE_TYPES.getProperty()), listType);
65 relationshipTypeDataDefinition.setValidSourceTypes(validSourceTypesfromJson);
67 // relationshipTypeDataDefinition.setValidSourceTypes((List<String>)
68 // properties.get(GraphPropertiesDictionary.VALID_SOURCE_TYPES
71 relationshipTypeDataDefinition
72 .setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
74 relationshipTypeDataDefinition
75 .setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
77 // capabilityTypeDataDefinition.setVersion(version);
82 public Map<String, Object> toGraphMap() {
84 Map<String, Object> map = new HashMap<>();
86 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, relationshipTypeDataDefinition.getUniqueId());
88 addIfExists(map, GraphPropertiesDictionary.TYPE, relationshipTypeDataDefinition.getType());
90 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, relationshipTypeDataDefinition.getDescription());
92 // String validSourceTypesToJson =
93 // getGson().toJson(relationshipTypeDataDefinition.getValidSourceTypes());
95 // addIfExists(map, GraphPropertiesDictionary.VALID_SOURCE_TYPES,
96 // validSourceTypesToJson);
98 addIfExists(map, GraphPropertiesDictionary.VALID_SOURCE_TYPES,
99 relationshipTypeDataDefinition.getValidSourceTypes());
101 addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, relationshipTypeDataDefinition.getCreationTime());
103 addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE,
104 relationshipTypeDataDefinition.getModificationTime());
109 public RelationshipInstDataDefinition getRelationshipTypeDataDefinition() {
110 return relationshipTypeDataDefinition;
113 public void setRelationshipTypeDataDefinition(RelationshipInstDataDefinition relationshipTypeDataDefinition) {
114 this.relationshipTypeDataDefinition = relationshipTypeDataDefinition;
118 public String getUniqueId() {
119 return this.relationshipTypeDataDefinition.getUniqueId();
123 public String toString() {
124 return "RelationshipTypeData [relationshipTypeDataDefinition=" + relationshipTypeDataDefinition + "]";