re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / DataTypeData.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 org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
24 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
25 import org.openecomp.sdc.be.datatypes.elements.DataTypeDataDefinition;
26 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
27
28 import java.util.HashMap;
29 import java.util.Map;
30
31 public class DataTypeData extends GraphNode {
32
33         DataTypeDataDefinition dataTypeDataDefinition;
34
35         public DataTypeData() {
36                 super(NodeTypeEnum.DataType);
37                 dataTypeDataDefinition = new DataTypeDataDefinition();
38         }
39
40         public DataTypeData(DataTypeDataDefinition dataTypeDataDefinition) {
41                 super(NodeTypeEnum.DataType);
42                 this.dataTypeDataDefinition = dataTypeDataDefinition;
43                 // this.constraints = constraints;
44         }
45
46         public DataTypeData(Map<String, Object> properties) {
47
48                 this();
49
50                 dataTypeDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
51
52                 dataTypeDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
53
54                 dataTypeDataDefinition
55                                 .setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
56
57                 dataTypeDataDefinition
58                                 .setDerivedFromName((String) properties.get(GraphPropertiesDictionary.DERIVED_FROM.getProperty()));
59
60                 dataTypeDataDefinition
61                                 .setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
62
63                 dataTypeDataDefinition
64                                 .setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
65
66         }
67
68         @Override
69         public Map<String, Object> toGraphMap() {
70
71                 Map<String, Object> map = new HashMap<>();
72
73                 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, dataTypeDataDefinition.getUniqueId());
74
75                 addIfExists(map, GraphPropertiesDictionary.NAME, dataTypeDataDefinition.getName());
76
77                 addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, dataTypeDataDefinition.getDescription());
78
79                 addIfExists(map, GraphPropertiesDictionary.DERIVED_FROM, dataTypeDataDefinition.getDerivedFromName());
80
81                 addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, dataTypeDataDefinition.getCreationTime());
82
83                 addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE, dataTypeDataDefinition.getModificationTime());
84
85                 return map;
86         }
87
88         public DataTypeDataDefinition getDataTypeDataDefinition() {
89                 return dataTypeDataDefinition;
90         }
91
92         public void setDataTypeDataDefinition(DataTypeDataDefinition dataTypeDataDefinition) {
93                 this.dataTypeDataDefinition = dataTypeDataDefinition;
94         }
95
96         @Override
97         public String toString() {
98                 return "DataTypeData [dataTypeDataDefinition=" + dataTypeDataDefinition + "]";
99         }
100
101         @Override
102         public String getUniqueId() {
103                 return this.dataTypeDataDefinition.getUniqueId();
104         }
105
106 }