Upgrade sonar plugin
[vid.git] / vid-app-common / src / main / java / org / openecomp / vid / model / Node.java
1 /*-\r
2  * ============LICENSE_START=======================================================\r
3  * VID\r
4  * ================================================================================\r
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.\r
6  * ================================================================================\r
7  * Licensed under the Apache License, Version 2.0 (the "License");\r
8  * you may not use this file except in compliance with the License.\r
9  * You may obtain a copy of the License at\r
10  * \r
11  *      http://www.apache.org/licenses/LICENSE-2.0\r
12  * \r
13  * Unless required by applicable law or agreed to in writing, software\r
14  * distributed under the License is distributed on an "AS IS" BASIS,\r
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
16  * See the License for the specific language governing permissions and\r
17  * limitations under the License.\r
18  * ============LICENSE_END=========================================================\r
19  */\r
20 \r
21 package org.openecomp.vid.model;\r
22 \r
23 import java.text.DateFormat;\r
24 import java.text.SimpleDateFormat;\r
25 import java.util.Date;\r
26 import java.util.HashMap;\r
27 import java.util.Map;\r
28 import java.util.Map.Entry;\r
29 \r
30 import org.openecomp.vid.asdc.beans.tosca.Input;\r
31 import org.openecomp.vid.asdc.beans.tosca.NodeTemplate;\r
32 \r
33 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
34 /**\r
35  * The Class Node.\r
36  */\r
37 public class Node {\r
38         /** The Constant LOG. */\r
39         private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(Node.class);\r
40         \r
41         /** The Constant dateFormat. */\r
42         final static DateFormat dateFormat = new SimpleDateFormat("HH:mm:ss:SSSS");\r
43 \r
44         /** The uuid. */\r
45         private String uuid;\r
46         \r
47         /** The invariant uuid. */\r
48         private String invariantUuid;\r
49         \r
50         /** The description. */\r
51         private String description;\r
52         \r
53         /** The name. */\r
54         private String name;\r
55         \r
56         /** The version. */\r
57         private String version;\r
58         \r
59         /** The model customization uuid. */\r
60         private String customizationUuid;\r
61         \r
62         /** The inputs. */\r
63         private Map<String, Input> inputs;\r
64         \r
65         /** The get_input or other constructs from node template properties. */\r
66         private Map<String, CommandProperty> commands;\r
67         \r
68         /** The get_input or other constructs from node template properties. */\r
69         private Map<String, String> properties;\r
70         /**\r
71          * Instantiates a new node.\r
72          */\r
73         public Node() {\r
74                 this.commands = new HashMap<String, CommandProperty>();\r
75                 this.properties = new HashMap<String, String>();\r
76         }\r
77         \r
78         /**\r
79          * Gets the uuid.\r
80          *\r
81          * @return the uuid\r
82          */\r
83         public String getUuid() {\r
84                 return uuid;\r
85         }\r
86 \r
87         /**\r
88          * Gets the invariant uuid.\r
89          *\r
90          * @return the invariant uuid\r
91          */\r
92         public String getInvariantUuid() {\r
93                 return invariantUuid;\r
94         }\r
95 \r
96         /**\r
97          * Gets the description.\r
98          *\r
99          * @return the description\r
100          */\r
101         public String getDescription() {\r
102                 return description;\r
103         }\r
104 \r
105         /**\r
106          * Gets the name.\r
107          *\r
108          * @return the name\r
109          */\r
110         public String getName() {\r
111                 return name;\r
112         }\r
113 \r
114         /**\r
115          * Gets the version.\r
116          *\r
117          * @return the version\r
118          */\r
119         public String getVersion() {\r
120                 return version;\r
121         }\r
122         \r
123         /**\r
124          * Gets the customization uuid.\r
125          *\r
126          * @return the model customization uuid\r
127          */\r
128         public String getCustomizationUuid() {\r
129                 return customizationUuid;\r
130         }\r
131         /**\r
132          * Gets the inputs.\r
133          *\r
134          * @return the inputs\r
135          */\r
136         public Map<String, Input> getInputs() {\r
137                 return inputs;\r
138         }\r
139         /**\r
140          * Gets the commands.\r
141          *\r
142          * @return the commands\r
143          */\r
144         public Map<String, CommandProperty> getCommands() {\r
145                 return commands;\r
146         }\r
147         /**\r
148          * Gets the properties.\r
149          *\r
150          * @return the properties\r
151          */\r
152         public Map<String, String> getProperties() {\r
153                 return properties;\r
154         }\r
155         /**\r
156          * Sets the uuid.\r
157          *\r
158          * @param uuid the new uuid\r
159          */\r
160         public void setUuid(String uuid) {\r
161                 this.uuid = uuid;\r
162         }\r
163 \r
164         /**\r
165          * Sets the invariant uuid.\r
166          *\r
167          * @param invariantUuid the new invariant uuid\r
168          */\r
169         public void setInvariantUuid(String invariantUuid) {\r
170                 this.invariantUuid = invariantUuid;\r
171         }\r
172 \r
173         /**\r
174          * Sets the description.\r
175          *\r
176          * @param description the new description\r
177          */\r
178         public void setDescription(String description) {\r
179                 this.description = description;\r
180         }\r
181 \r
182         /**\r
183          * Sets the name.\r
184          *\r
185          * @param name the new name\r
186          */\r
187         public void setName(String name) {\r
188                 this.name = name;\r
189         }\r
190 \r
191         /**\r
192          * Sets the version.\r
193          *\r
194          * @param version the new version\r
195          */\r
196         public void setVersion(String version) {\r
197                 this.version = version;\r
198         }\r
199         /**\r
200          * Sets the customization uuid.\r
201          *\r
202          * @param u the new customization uuid\r
203          */\r
204         public void setCustomizationUuid(String u) {\r
205                 this.customizationUuid = u;\r
206         }\r
207 \r
208         /**\r
209          * Sets the inputs.\r
210          *\r
211          * @param inputs the inputs\r
212          */\r
213         public void setInputs(Map<String, Input> inputs) {\r
214                 this.inputs = inputs;\r
215         }\r
216         /**\r
217          * Sets the commands.\r
218          *\r
219          * @param m the commands\r
220          */\r
221         public void setCommands( Map<String, CommandProperty>m ) {\r
222                 commands = m;\r
223         }\r
224         /**\r
225          * Sets the properties.\r
226          *\r
227          * @param p the properties\r
228          */\r
229         public void setProperties( Map<String, String>p) {\r
230                 properties = p;\r
231         }\r
232         /**\r
233          * Extract node.\r
234          *\r
235          * @param modelCustomizationName the model customization name\r
236          * @param nodeTemplate the node template\r
237          * @return the node\r
238          */\r
239         public void extractNode (NodeTemplate nodeTemplate) {\r
240                 \r
241                 String methodName = "extractNode";\r
242                 \r
243                 setUuid(nodeTemplate.getMetadata().getUUID());\r
244                 setInvariantUuid(nodeTemplate.getMetadata().getInvariantUUID());\r
245                 setDescription(nodeTemplate.getMetadata().getDescription());\r
246                 setName(nodeTemplate.getMetadata().getName());\r
247                 setVersion(nodeTemplate.getMetadata().getVersion());\r
248                 // add customizationUUID\r
249                 setCustomizationUuid(nodeTemplate.getMetadata().getCustomizationUUID());\r
250 \r
251                 try {\r
252                         // nodeTemplate.getProperties() map of String->Object\r
253                         for (Entry<String, Object> e : nodeTemplate.getProperties().entrySet()) {\r
254                                 \r
255                                 String k = e.getKey();\r
256                                 \r
257                                 LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " node template property: " + k );\r
258                                 \r
259                                 if ( e.getValue() != null ) {\r
260                                         LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + "  property: " + \r
261                                                         k + "=" + e.getValue());\r
262                                         //LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " V class name: " +\r
263                                         //       e.getValue().getClass().getName());\r
264                                         Class<?> c = e.getValue().getClass();\r
265                                         if ( c.getName().equalsIgnoreCase(java.lang.String.class.getName())) {\r
266                                                 getProperties().put (k, (String)e.getValue());\r
267                                         }\r
268                                         else {\r
269                                                 Class<?>[] interfaces = e.getValue().getClass().getInterfaces();\r
270 \r
271                                                 for(Class<?> ifc: interfaces ) {\r
272                                                         //LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " ifc name: " +\r
273                                                         //       ifc.getName());\r
274                                                         if ( ifc.getName().equalsIgnoreCase(java.util.Map.class.getName()) ) {\r
275                                                                 // only extract get_input for now\r
276                                                                 @SuppressWarnings("unchecked")\r
277                                                                 HashMap<String,String> v = (HashMap<String,String>)e.getValue();\r
278                                                                 for (Entry<String, String> entry : v.entrySet()) {\r
279                                                                         // only include get_input for now\r
280                                                                         if ( ModelConstants.GET_INPUT_TAG.equalsIgnoreCase ( entry.getKey() ) ) {\r
281                                                                                 CommandProperty cp = new CommandProperty();\r
282                                                                                 cp.setCommand(entry.getKey());\r
283                                                                                 cp.setInputName(entry.getValue());\r
284                                                                                 cp.setDisplayName(k);\r
285                                                                                 getCommands().put(k,cp);\r
286                                                                         }\r
287                                                                 }\r
288                                                         }\r
289                                                 }\r
290 \r
291                                         }\r
292                                 }\r
293                         }\r
294                 }\r
295                 catch ( Exception e ) {\r
296                         LOG.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + " Unable to parse node properties: e=" + \r
297                                         e.toString());\r
298                 }\r
299         }\r
300 \r
301 }\r