re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / PolicyTypeData.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 com.google.gson.reflect.TypeToken;
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.PolicyTypeDataDefinition;
27 import org.openecomp.sdc.be.datatypes.enums.NodeTypeEnum;
28
29 import java.lang.reflect.Type;
30 import java.util.HashMap;
31 import java.util.List;
32 import java.util.Map;
33
34 public class PolicyTypeData extends GraphNode {
35
36     private PolicyTypeDataDefinition policyTypeDataDefinition;
37     private static final Type mapType = new TypeToken<HashMap<String, String>>() {
38     }.getType();
39     private static final Type listType = new TypeToken<List<String>>() {
40     }.getType();
41
42     public PolicyTypeData() {
43         super(NodeTypeEnum.PolicyType);
44         policyTypeDataDefinition = new PolicyTypeDataDefinition();
45     }
46
47     public PolicyTypeData(PolicyTypeDataDefinition policyTypeDataDefinition) {
48         super(NodeTypeEnum.PolicyType);
49         this.policyTypeDataDefinition = policyTypeDataDefinition;
50     }
51
52     public PolicyTypeData(Map<String, Object> properties) {
53
54         this();
55
56         policyTypeDataDefinition
57                 .setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
58
59         HashMap<String, String> metatdata = getGson()
60                 .fromJson((String) properties.get(GraphPropertiesDictionary.METADATA.getProperty()), mapType);
61         policyTypeDataDefinition.setMetadata(metatdata);
62
63         List<String> members = getGson()
64                 .fromJson((String) properties.get(GraphPropertiesDictionary.TARGETS.getProperty()), listType);
65         policyTypeDataDefinition.setTargets(members);
66         policyTypeDataDefinition.setType((String) properties.get(GraphPropertiesDictionary.TYPE.getProperty()));
67         policyTypeDataDefinition.setName((String) properties.get(GraphPropertiesDictionary.NAME.getProperty()));
68         policyTypeDataDefinition.setIcon((String) properties.get(GraphPropertiesDictionary.ICON.getProperty()));
69         policyTypeDataDefinition
70                 .setDescription((String) properties.get(GraphPropertiesDictionary.DESCRIPTION.getProperty()));
71
72         if (properties.get(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty()) != null) {
73                 policyTypeDataDefinition.setHighestVersion(
74                                 (boolean) properties.get(GraphPropertiesDictionary.IS_HIGHEST_VERSION.getProperty()));
75                 }
76
77         policyTypeDataDefinition.setVersion((String) properties.get(GraphPropertiesDictionary.VERSION.getProperty()));
78
79         policyTypeDataDefinition
80                 .setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
81
82         policyTypeDataDefinition
83                 .setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
84
85     }
86
87     @Override
88     public Map<String, Object> toGraphMap() {
89
90         Map<String, Object> map = new HashMap<>();
91
92         addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, policyTypeDataDefinition.getUniqueId());
93
94         addIfExists(map, GraphPropertiesDictionary.TYPE, policyTypeDataDefinition.getType());
95
96         addIfExists(map, GraphPropertiesDictionary.NAME, policyTypeDataDefinition.getName());
97
98         addIfExists(map, GraphPropertiesDictionary.ICON, policyTypeDataDefinition.getIcon());
99
100         addIfExists(map, GraphPropertiesDictionary.VERSION, policyTypeDataDefinition.getVersion());
101
102         addIfExists(map, GraphPropertiesDictionary.IS_HIGHEST_VERSION, policyTypeDataDefinition.isHighestVersion());
103
104         addIfExists(map, GraphPropertiesDictionary.DESCRIPTION, policyTypeDataDefinition.getDescription());
105
106         addIfExists(map, GraphPropertiesDictionary.METADATA, policyTypeDataDefinition.getMetadata());
107
108         addIfExists(map, GraphPropertiesDictionary.TARGETS, policyTypeDataDefinition.getTargets());
109
110         addIfExists(map, GraphPropertiesDictionary.CREATION_DATE, policyTypeDataDefinition.getCreationTime());
111
112         addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE, policyTypeDataDefinition.getModificationTime());
113
114         return map;
115     }
116
117     @Override
118     public String toString() {
119         return "PolicyTypeData [policyTypeDataDefinition=" + policyTypeDataDefinition + "]";
120     }
121
122     @Override
123     public String getUniqueId() {
124         return this.policyTypeDataDefinition.getUniqueId();
125     }
126
127     public PolicyTypeDataDefinition getPolicyTypeDataDefinition() {
128         return policyTypeDataDefinition;
129     }
130
131
132 }