Support for delete of non normative interface types
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / InterfaceData.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 java.util.HashMap;
24 import java.util.Map;
25 import org.openecomp.sdc.be.dao.graph.datatype.GraphNode;
26 import org.openecomp.sdc.be.dao.neo4j.GraphPropertiesDictionary;
27 import org.openecomp.sdc.be.datatypes.elements.InterfaceDataDefinition;
28 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
29
30 public class InterfaceData extends GraphNode {
31
32     private InterfaceDataDefinition interfaceDataDefinition;
33
34     public InterfaceData() {
35         super(NodeTypeEnum.Interface);
36         interfaceDataDefinition = new InterfaceDataDefinition();
37     }
38
39     public InterfaceData(InterfaceData p) {
40         super(NodeTypeEnum.Interface);
41         interfaceDataDefinition = p.getInterfaceDataDefinition();
42     }
43
44     public InterfaceData(InterfaceDataDefinition interfaceDataDefinition) {
45         super(NodeTypeEnum.Interface);
46         this.interfaceDataDefinition = interfaceDataDefinition;
47     }
48
49     public InterfaceData(Map<String, Object> properties) {
50         this();
51         interfaceDataDefinition.setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
52         interfaceDataDefinition.setType((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
53         interfaceDataDefinition.setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
54         interfaceDataDefinition.setCreationDate((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
55         interfaceDataDefinition.setLastUpdateDate((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
56         final Object normativeProperty = properties.get(GraphPropertiesDictionary.NORMATIVE.getProperty());
57         interfaceDataDefinition.setUserCreated(!(normativeProperty instanceof Boolean && (Boolean) normativeProperty));
58     }
59
60     public InterfaceDataDefinition getInterfaceDataDefinition() {
61         return interfaceDataDefinition;
62     }
63
64     public void setInterfaceDataDefinition(InterfaceDataDefinition interfaceDataDefinition) {
65         this.interfaceDataDefinition = interfaceDataDefinition;
66     }
67
68     @Override
69     public String getUniqueId() {
70         return interfaceDataDefinition.getUniqueId();
71     }
72
73     @Override
74     public Map<String, Object> toGraphMap() {
75         Map<String, Object> map = new HashMap<>();
76         addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, interfaceDataDefinition.getUniqueId());
77         addIfExists(map, GraphPropertiesDictionary.TYPE, interfaceDataDefinition.getType());
78         addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, interfaceDataDefinition.getCreationDate());
79         addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE, interfaceDataDefinition.getLastUpdateDate());
80         addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, interfaceDataDefinition.getDescription());
81         addIfExists(map, GraphPropertiesDictionary.NORMATIVE, !interfaceDataDefinition.isUserCreated());
82         return map;
83     }
84 }