re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / RelationshipTypeData.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  * 
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  * 
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=========================================================
19  */
20
21 package org.openecomp.sdc.be.resources.data;
22
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;
28
29 import java.lang.reflect.Type;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33
34 public class RelationshipTypeData extends GraphNode {
35
36         RelationshipInstDataDefinition relationshipTypeDataDefinition;
37
38         public RelationshipTypeData() {
39                 super(NodeTypeEnum.RelationshipType);
40                 relationshipTypeDataDefinition = new RelationshipInstDataDefinition();
41         }
42
43         public RelationshipTypeData(RelationshipInstDataDefinition relationshipTypeDataDefinition) {
44                 super(NodeTypeEnum.RelationshipType);
45                 this.relationshipTypeDataDefinition = relationshipTypeDataDefinition;
46         }
47
48         public RelationshipTypeData(Map<String, Object> properties) {
49
50                 this();
51
52                 relationshipTypeDataDefinition
53                                 .setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
54
55                 relationshipTypeDataDefinition.setType((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
56
57                 relationshipTypeDataDefinition
58                                 .setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
59
60                 Type listType = new TypeToken<List<String>>() {
61                 }.getType();
62                 List<String> validSourceTypesfromJson = getGson().fromJson(
63                                 (String) properties.get(GraphPropertiesDictionary.VALID_SOURCE_TYPES.getProperty()), listType);
64
65                 relationshipTypeDataDefinition.setValidSourceTypes(validSourceTypesfromJson);
66
67                 // relationshipTypeDataDefinition.setValidSourceTypes((List<String>)
68                 // properties.get(GraphPropertiesDictionary.VALID_SOURCE_TYPES
69                 // .getProperty()));
70
71                 relationshipTypeDataDefinition
72                                 .setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
73
74                 relationshipTypeDataDefinition
75                                 .setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
76
77                 // capabilityTypeDataDefinition.setVersion(version);
78
79         }
80
81         @Override
82         public Map<String, Object> toGraphMap() {
83
84                 Map<String, Object> map = new HashMap<>();
85
86                 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, relationshipTypeDataDefinition.getUniqueId());
87
88                 addIfExists(map, GraphPropertiesDictionary.TYPE, relationshipTypeDataDefinition.getType());
89
90                 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, relationshipTypeDataDefinition.getDescription());
91
92                 // String validSourceTypesToJson =
93                 // getGson().toJson(relationshipTypeDataDefinition.getValidSourceTypes());
94
95                 // addIfExists(map, GraphPropertiesDictionary.VALID_SOURCE_TYPES,
96                 // validSourceTypesToJson);
97
98                 addIfExists(map, GraphPropertiesDictionary.VALID_SOURCE_TYPES,
99                                 relationshipTypeDataDefinition.getValidSourceTypes());
100
101                 addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, relationshipTypeDataDefinition.getCreationTime());
102
103                 addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE,
104                                 relationshipTypeDataDefinition.getModificationTime());
105
106                 return map;
107         }
108
109         public RelationshipInstDataDefinition getRelationshipTypeDataDefinition() {
110                 return relationshipTypeDataDefinition;
111         }
112
113         public void setRelationshipTypeDataDefinition(RelationshipInstDataDefinition relationshipTypeDataDefinition) {
114                 this.relationshipTypeDataDefinition = relationshipTypeDataDefinition;
115         }
116
117         @Override
118         public String getUniqueId() {
119                 return this.relationshipTypeDataDefinition.getUniqueId();
120         }
121
122         @Override
123         public String toString() {
124                 return "RelationshipTypeData [relationshipTypeDataDefinition=" + relationshipTypeDataDefinition + "]";
125         }
126
127 }