re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / CapabilityInstData.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.enums.NodeTypeEnum;
27
28 import java.lang.reflect.Type;
29 import java.util.HashMap;
30 import java.util.List;
31 import java.util.Map;
32
33 public class CapabilityInstData extends GraphNode {
34
35         public CapabilityInstData() {
36                 super(NodeTypeEnum.CapabilityInst);
37         }
38
39         public CapabilityInstData(Map<String, Object> properties) {
40                 this();
41
42                 this.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
43
44                 Type listType = new TypeToken<List<String>>() {
45                 }.getType();
46                 List<String> propertiesfromJson = getGson()
47                                 .fromJson((String) properties.get(GraphPropertiesDictionary.PROPERTIES.getProperty()), listType);
48
49                 this.setProperties(propertiesfromJson);
50
51                 // this.setProperties((ArrayList<String>) properties
52                 // .get(GraphPropertiesDictionary.PROPERTIES.getProperty()));
53
54                 this.setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
55
56                 this.setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
57         }
58
59         private String uniqueId;
60
61         private List<String> properties;
62
63         private Long creationTime;
64
65         private Long modificationTime;
66
67         @Override
68         public String getUniqueId() {
69                 return uniqueId;
70         }
71
72         public void setUniqueId(String uniqueId) {
73                 this.uniqueId = uniqueId;
74         }
75
76         public Long getCreationTime() {
77                 return creationTime;
78         }
79
80         public void setCreationTime(Long creationTime) {
81                 this.creationTime = creationTime;
82         }
83
84         public Long getModificationTime() {
85                 return modificationTime;
86         }
87
88         public void setModificationTime(Long modificationTime) {
89                 this.modificationTime = modificationTime;
90         }
91
92         public List<String> getProperties() {
93                 return properties;
94         }
95
96         public void setProperties(List<String> properties) {
97                 this.properties = properties;
98         }
99
100         @Override
101         public Map<String, Object> toGraphMap() {
102
103                 Map<String, Object> map = new HashMap<>();
104
105                 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, uniqueId);
106
107                 // String propertiesToJson = getGson().toJson(properties);
108
109                 // addIfExists(map, GraphPropertiesDictionary.PROPERTIES,
110                 // propertiesToJson);
111
112                 addIfExists(map, GraphPropertiesDictionary.PROPERTIES, properties);
113
114                 addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, creationTime);
115
116                 addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE, modificationTime);
117
118                 return map;
119         }
120
121         @Override
122         public String toString() {
123                 return "CapabilityInstData [uniqueId=" + uniqueId + ", properties=" + properties + ", creationTime="
124                                 + creationTime + ", modificationTime=" + modificationTime + "]";
125         }
126
127 }