re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / CapabilityTypeData.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.CapabilityTypeDataDefinition;
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 CapabilityTypeData extends GraphNode {
35
36         CapabilityTypeDataDefinition capabilityTypeDataDefinition;
37
38         // private List<String> constraints;
39
40         public CapabilityTypeData() {
41                 super(NodeTypeEnum.CapabilityType);
42                 capabilityTypeDataDefinition = new CapabilityTypeDataDefinition();
43         }
44
45         public CapabilityTypeData(CapabilityTypeDataDefinition capabilityTypeDataDefinition) {
46                 super(NodeTypeEnum.CapabilityType);
47                 this.capabilityTypeDataDefinition = capabilityTypeDataDefinition;
48                 // this.constraints = constraints;
49         }
50
51         public CapabilityTypeData(Map<String, Object> properties) {
52
53                 this();
54
55                 capabilityTypeDataDefinition
56                                 .setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
57
58                 capabilityTypeDataDefinition.setType((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
59
60                 capabilityTypeDataDefinition
61                                 .setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
62                 
63                 capabilityTypeDataDefinition
64                         .setVersion((String) properties.get(GraphPropertiesDictionary.VERSION.getProperty()));
65
66                 Type listType = new TypeToken<List<String>>() {
67                 }.getType();
68                 List<String> validSourceTypesfromJson = getGson().fromJson(
69                                 (String) properties.get(GraphPropertiesDictionary.VALID_SOURCE_TYPES.getProperty()), listType);
70
71                 capabilityTypeDataDefinition.setValidSourceTypes(validSourceTypesfromJson);
72
73                 // capabilityTypeDataDefinition.setValidSourceTypes((List<String>)
74                 // properties.get(GraphPropertiesDictionary.VALID_SOURCE_TYPES
75                 // .getProperty()));
76
77                 capabilityTypeDataDefinition
78                                 .setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
79
80                 capabilityTypeDataDefinition
81                                 .setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
82
83                 // capabilityTypeDataDefinition.setVersion(version);
84
85         }
86
87         @Override
88         public Map<String, Object> toGraphMap() {
89
90                 Map<String, Object> map = new HashMap<>();
91
92                 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, capabilityTypeDataDefinition.getUniqueId());
93
94                 addIfExists(map, GraphPropertiesDictionary.TYPE, capabilityTypeDataDefinition.getType());
95
96                 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, capabilityTypeDataDefinition.getDescription());
97                 
98                 addIfExists(map, GraphPropertiesDictionary.VERSION, capabilityTypeDataDefinition.getVersion());
99
100                 // String validSourceTypesToJson =
101                 // getGson().toJson(capabilityTypeDataDefinition.getValidSourceTypes());
102
103                 // addIfExists(map, GraphPropertiesDictionary.VALID_SOURCE_TYPES,
104                 // validSourceTypesToJson);
105
106                 addIfExists(map, GraphPropertiesDictionary.VALID_SOURCE_TYPES,
107                                 capabilityTypeDataDefinition.getValidSourceTypes());
108
109                 addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, capabilityTypeDataDefinition.getCreationTime());
110
111                 addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE,
112                                 capabilityTypeDataDefinition.getModificationTime());
113
114                 return map;
115         }
116
117         public CapabilityTypeDataDefinition getCapabilityTypeDataDefinition() {
118                 return capabilityTypeDataDefinition;
119         }
120
121         public void setCapabilityTypeDataDefinition(CapabilityTypeDataDefinition capabilityTypeDataDefinition) {
122                 this.capabilityTypeDataDefinition = capabilityTypeDataDefinition;
123         }
124
125         @Override
126         public String toString() {
127                 return "CapabilityTypeData [capabilityTypeDataDefinition=" + capabilityTypeDataDefinition + "]";
128         }
129
130         @Override
131         public String getUniqueId() {
132                 return this.capabilityTypeDataDefinition.getUniqueId();
133         }
134
135 }