Added oparent to sdc main
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / AnnotationTypeData.java
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
4  * ================================================================================
5  * Copyright (C) 2019 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.AnnotationTypeDataDefinition;
26 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
27
28 import java.util.HashMap;
29 import java.util.Map;
30
31 public class AnnotationTypeData extends GraphNode {
32
33     private AnnotationTypeDataDefinition annotationTypeDataDefinition;
34
35     public AnnotationTypeData() {
36         super(NodeTypeEnum.AnnotationType);
37         annotationTypeDataDefinition = new AnnotationTypeDataDefinition();
38     }
39
40     public AnnotationTypeData(AnnotationTypeDataDefinition annotationTypeDataDefinition) {
41         super(NodeTypeEnum.AnnotationType);
42         this.annotationTypeDataDefinition = annotationTypeDataDefinition;
43     }
44
45     public AnnotationTypeData(Map<String, Object> properties) {
46         this();
47         annotationTypeDataDefinition
48                 .setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
49         annotationTypeDataDefinition.setType((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
50         annotationTypeDataDefinition
51                 .setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
52         annotationTypeDataDefinition.setHighestVersion(
53                 (boolean) properties.get(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty()));
54         annotationTypeDataDefinition.setVersion((String) properties.get(GraphPropertiesDictionary.VERSION.getProperty()));
55         annotationTypeDataDefinition
56                 .setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
57         annotationTypeDataDefinition
58                 .setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
59     }
60
61     @Override
62     public String getUniqueId() {
63         return annotationTypeDataDefinition.getUniqueId();
64     }
65
66     @Override
67     public Map<String, Object> toGraphMap() {
68         Map<String, Object> map = new HashMap<>();
69         addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, annotationTypeDataDefinition.getUniqueId());
70         addIfExists(map, GraphPropertiesDictionary.TYPE, annotationTypeDataDefinition.getType());
71         addIfExists(map, GraphPropertiesDictionary.VERSION, annotationTypeDataDefinition.getVersion());
72         addIfExists(map, GraphPropertiesDictionary.IS_HIGHEST_VERSION, annotationTypeDataDefinition.isHighestVersion());
73         addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, annotationTypeDataDefinition.getDescription());
74         addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, annotationTypeDataDefinition.getCreationTime());
75         addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE, annotationTypeDataDefinition.getModificationTime());
76         return map;
77     }
78
79     public void setInitialCreationProperties(String uniqueId) {
80         annotationTypeDataDefinition.setUniqueId(uniqueId);
81         Long creationDate = annotationTypeDataDefinition.getCreationTime();
82         if (creationDate == null) {
83             creationDate = System.currentTimeMillis();
84         }
85         annotationTypeDataDefinition.setCreationTime(creationDate);
86         annotationTypeDataDefinition.setModificationTime(creationDate);
87     }
88
89     public void setUpdateProperties(AnnotationTypeDataDefinition originalDefinition) {
90         annotationTypeDataDefinition.setUniqueId(originalDefinition.getUniqueId());
91         annotationTypeDataDefinition.setCreationTime(originalDefinition.getCreationTime());
92         annotationTypeDataDefinition.setModificationTime(System.currentTimeMillis());
93     }
94
95     public AnnotationTypeDataDefinition getAnnotationTypeDataDefinition() {
96         return annotationTypeDataDefinition;
97     }
98
99     @Override
100     public String toString() {
101         return "AnnotationTypeData [annotationTypeDataDefinition=" + annotationTypeDataDefinition + "]";
102     }
103
104 }