re base code
[sdc.git] / catalog-dao / src / main / java / org / openecomp / sdc / be / resources / data / AdditionalInfoParameterData.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.AdditionalInfoParameterDataDefinition;
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.Map;
32
33 public class AdditionalInfoParameterData extends GraphNode {
34
35         AdditionalInfoParameterDataDefinition additionalInfoParameterDataDefinition;
36
37         private Map<String, String> parameters;
38
39         private Map<String, String> idToKey;
40
41         public AdditionalInfoParameterData() {
42                 super(NodeTypeEnum.AdditionalInfoParameters);
43                 additionalInfoParameterDataDefinition = new AdditionalInfoParameterDataDefinition();
44         }
45
46         public AdditionalInfoParameterData(AdditionalInfoParameterDataDefinition additionalInfoParameterDataDefinition,
47                         Map<String, String> parameters, Map<String, String> idToKey) {
48                 super(NodeTypeEnum.AdditionalInfoParameters);
49                 this.additionalInfoParameterDataDefinition = additionalInfoParameterDataDefinition;
50                 this.parameters = parameters;
51                 this.idToKey = idToKey;
52         }
53
54         public AdditionalInfoParameterData(Map<String, Object> properties) {
55
56                 this();
57
58                 additionalInfoParameterDataDefinition
59                                 .setUniqueId((String) properties.get(GraphPropertiesDictionary.UNIQUE_ID.getProperty()));
60
61                 additionalInfoParameterDataDefinition
62                                 .setCreationTime((Long) properties.get(GraphPropertiesDictionary.CREATION_DATE.getProperty()));
63
64                 additionalInfoParameterDataDefinition
65                                 .setModificationTime((Long) properties.get(GraphPropertiesDictionary.LAST_UPDATE_DATE.getProperty()));
66
67                 additionalInfoParameterDataDefinition.setLastCreatedCounter(
68                                 (Integer) properties.get(GraphPropertiesDictionary.PROPERTY_COUNTER.getProperty()));
69                 Type mapType = new TypeToken<HashMap<String, String>>() {
70                 }.getType();
71                 HashMap<String, String> prametersfromJson = getGson().fromJson(
72                                 (String) properties.get(GraphPropertiesDictionary.ADDITIONAL_INFO_PARAMS.getProperty()), mapType);
73
74                 this.setParameters(prametersfromJson);
75
76                 // this.setParameters((HashMap<String, String>) properties
77                 // .get(GraphPropertiesDictionary.ADDITIONAL_INFO_PARAMS
78                 // .getProperty()));
79
80                 HashMap<String, String> idToKeyfromJson = getGson().fromJson(
81                                 (String) properties.get(GraphPropertiesDictionary.ADDITIONAL_INFO_ID_TO_KEY.getProperty()), mapType);
82
83                 this.setIdToKey(idToKeyfromJson);
84                 // this.setIdToKey((HashMap<String, String>) properties
85                 // .get(GraphPropertiesDictionary.ADDITIONAL_INFO_ID_TO_KEY
86                 // .getProperty()));
87         }
88
89         @Override
90         public Map<String, Object> toGraphMap() {
91
92                 Map<String, Object> map = new HashMap<>();
93
94                 addIfExists(map, GraphPropertiesDictionary.UNIQUE_ID, additionalInfoParameterDataDefinition.getUniqueId());
95
96                 // String parametersToJson = getGson().toJson(getParameters());
97
98                 // addIfExists(map, GraphPropertiesDictionary.ADDITIONAL_INFO_PARAMS,
99                 // parametersToJson);
100                 addIfExists(map, GraphPropertiesDictionary.ADDITIONAL_INFO_PARAMS, getParameters());
101
102                 // String idToKeyToJson = getGson().toJson(getIdToKey());
103                 // addIfExists(map, GraphPropertiesDictionary.ADDITIONAL_INFO_ID_TO_KEY,
104                 // idToKeyToJson);
105                 addIfExists(map, GraphPropertiesDictionary.ADDITIONAL_INFO_ID_TO_KEY, getIdToKey());
106
107                 addIfExists(map, GraphPropertiesDictionary.CREATION_DATE,
108                                 additionalInfoParameterDataDefinition.getCreationTime());
109
110                 addIfExists(map, GraphPropertiesDictionary.LAST_UPDATE_DATE,
111                                 additionalInfoParameterDataDefinition.getModificationTime());
112
113                 addIfExists(map, GraphPropertiesDictionary.PROPERTY_COUNTER,
114                                 additionalInfoParameterDataDefinition.getLastCreatedCounter());
115
116                 return map;
117         }
118
119         @Override
120         public String getUniqueId() {
121                 return additionalInfoParameterDataDefinition.getUniqueId();
122         }
123
124         public AdditionalInfoParameterDataDefinition getAdditionalInfoParameterDataDefinition() {
125                 return additionalInfoParameterDataDefinition;
126         }
127
128         public void setAdditionalInfoParameterDataDefinition(
129                         AdditionalInfoParameterDataDefinition additionalInfoParameterDataDefinition) {
130                 this.additionalInfoParameterDataDefinition = additionalInfoParameterDataDefinition;
131         }
132
133         public Map<String, String> getParameters() {
134                 return parameters;
135         }
136
137         public void setParameters(Map<String, String> parameters) {
138                 this.parameters = parameters;
139         }
140
141         public Map<String, String> getIdToKey() {
142                 return idToKey;
143         }
144
145         public void setIdToKey(Map<String, String> idToKey) {
146                 this.idToKey = idToKey;
147         }
148
149         @Override
150         public String toString() {
151                 return "PropertyData [parameters= " + parameters + " idToKey= " + idToKey
152                                 + ", additionalInfoParameterDataDefinition=" + additionalInfoParameterDataDefinition + "]";
153         }
154 }