e482fb55b6135bf5174d3ad2599657d92e337600
[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 package org.openecomp.sdc.be.resources.data;
21
22 import java.util.HashMap;
23 import java.util.Map;
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.DataTypeDataDefinition;
27 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
28
29 public class DataTypeData extends GraphNode {
30
31     DataTypeDataDefinition dataTypeDataDefinition;
32
33     public DataTypeData() {
34         super(NodeTypeEnum.DataType);
35         dataTypeDataDefinition = new DataTypeDataDefinition();
36     }
37
38     public DataTypeData(DataTypeDataDefinition dataTypeDataDefinition) {
39         super(NodeTypeEnum.DataType);
40         this.dataTypeDataDefinition = dataTypeDataDefinition;
41         // this.constraints = constraints;
42     }
43
44     public DataTypeData(Map<String, Object> properties) {
45         this();
46         dataTypeDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
47         dataTypeDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
48         dataTypeDataDefinition.setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
49         dataTypeDataDefinition.setDerivedFromName((String) properties.get(GraphPropertiesDictionary.DERIVED_FROM.getProperty()));
50         dataTypeDataDefinition.setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
51         dataTypeDataDefinition.setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
52         dataTypeDataDefinition.setModel((String) properties.get(GraphPropertiesDictionary.MODEL.getProperty()));
53     }
54
55     @Override
56     public Map<String, Object> toGraphMap() {
57         Map<String, Object> map = new HashMap<>();
58         addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, dataTypeDataDefinition.getUniqueId());
59         addIfExists(map, GraphPropertiesDictionary.NAME, dataTypeDataDefinition.getName());
60         addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, dataTypeDataDefinition.getDescription());
61         addIfExists(map, GraphPropertiesDictionary.DERIVED_FROM, dataTypeDataDefinition.getDerivedFromName());
62         addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, dataTypeDataDefinition.getCreationTime());
63         addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE, dataTypeDataDefinition.getModificationTime());
64         addIfExists(map, GraphPropertiesDictionary.MODEL, dataTypeDataDefinition.getModel());
65         return map;
66     }
67
68     public DataTypeDataDefinition getDataTypeDataDefinition() {
69         return dataTypeDataDefinition;
70     }
71
72     public void setDataTypeDataDefinition(DataTypeDataDefinition dataTypeDataDefinition) {
73         this.dataTypeDataDefinition = dataTypeDataDefinition;
74     }
75
76     @Override
77     public String toString() {
78         return "DataTypeData [dataTypeDataDefinition=" + dataTypeDataDefinition + "]";
79     }
80
81     @Override
82     public String getUniqueId() {
83         return this.dataTypeDataDefinition.getUniqueId();
84     }
85 }