bf13331dd140af55586166410ad4ff19c33dc0ca
[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         final Object normativeProperty = properties.get(GraphPropertiesDictionary.NORMATIVE.getProperty());
54         final boolean normative = normativeProperty != null && (boolean) normativeProperty;
55         dataTypeDataDefinition.setNormative(normative);        
56     }
57
58     @Override
59     public Map<String, Object> toGraphMap() {
60         Map<String, Object> map = new HashMap<>();
61         addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, dataTypeDataDefinition.getUniqueId());
62         addIfExists(map, GraphPropertiesDictionary.NAME, dataTypeDataDefinition.getName());
63         addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, dataTypeDataDefinition.getDescription());
64         addIfExists(map, GraphPropertiesDictionary.DERIVED_FROM, dataTypeDataDefinition.getDerivedFromName());
65         addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, dataTypeDataDefinition.getCreationTime());
66         addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE, dataTypeDataDefinition.getModificationTime());
67         addIfExists(map, GraphPropertiesDictionary.MODEL, dataTypeDataDefinition.getModel());
68         addIfExists(map, GraphPropertiesDictionary.NORMATIVE, dataTypeDataDefinition.isNormative());
69         return map;
70     }
71
72     public DataTypeDataDefinition getDataTypeDataDefinition() {
73         return dataTypeDataDefinition;
74     }
75
76     public void setDataTypeDataDefinition(DataTypeDataDefinition dataTypeDataDefinition) {
77         this.dataTypeDataDefinition = dataTypeDataDefinition;
78     }
79
80     @Override
81     public String toString() {
82         return "DataTypeData [dataTypeDataDefinition=" + dataTypeDataDefinition + "]";
83     }
84
85     @Override
86     public String getUniqueId() {
87         return this.dataTypeDataDefinition.getUniqueId();
88     }
89 }