Upgrade sonar plugin
[vid.git] / vid-app-common / src / main / java / org / openecomp / vid / model / VfModule.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 import org.openecomp.vid.asdc.beans.tosca.Group;\r
30 \r
31 import org.openecomp.portalsdk.core.logging.logic.EELFLoggerDelegate;\r
32 \r
33 /**\r
34  * The Class VfModule.\r
35  */\r
36 public class VfModule {\r
37 \r
38         /** The Constant LOG. */\r
39         private static final EELFLoggerDelegate LOG = EELFLoggerDelegate.getLogger(VfModule.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 customization uuid. */\r
51         private String customizationUuid;\r
52         \r
53         /** The description. */\r
54         private String description;\r
55         \r
56         /** The name. */\r
57         private String name;\r
58         \r
59         /** The version. */\r
60         private String version;\r
61         \r
62         /** The volume group allowed. */\r
63         private boolean volumeGroupAllowed;\r
64         \r
65         /** The get_input or other constructs for VF Module. */\r
66         private Map<String, CommandProperty> commands;\r
67         \r
68         /** The model customization name. */\r
69         private String modelCustomizationName;\r
70         \r
71         /**\r
72          * Instantiates a new vf module.\r
73          */\r
74         public VfModule() {\r
75                 commands = new HashMap<String, CommandProperty>();\r
76         }\r
77         /**\r
78          * Gets the model customization name.\r
79          *\r
80          * @return the model customization name\r
81          */\r
82         public String getModelCustomizationName() {\r
83                 return modelCustomizationName;\r
84         }\r
85         /**\r
86          * Gets the uuid.\r
87          *\r
88          * @return the uuid\r
89          */\r
90         public String getUuid() {\r
91                 return uuid;\r
92         }\r
93 \r
94         /**\r
95          * Gets the invariant uuid.\r
96          *\r
97          * @return the invariant uuid\r
98          */\r
99         public String getInvariantUuid() {\r
100                 return invariantUuid;\r
101         }\r
102         /**\r
103          * Gets the customization uuid.\r
104          *\r
105          * @return the invariant uuid\r
106          */\r
107         public String getCustomizationUuid() {\r
108                 return customizationUuid;\r
109         }\r
110         /**\r
111          * Gets the description.\r
112          *\r
113          * @return the description\r
114          */\r
115         public String getDescription() {\r
116                 return description;\r
117         }\r
118         /**\r
119          * Gets the commands.\r
120          *\r
121          * @return the commands\r
122          */\r
123         public Map<String, CommandProperty> getCommands() {\r
124                 return commands;\r
125         }\r
126         /**\r
127          * Gets the name.\r
128          *\r
129          * @return the name\r
130          */\r
131         public String getName() {\r
132                 return name;\r
133         }\r
134 \r
135         /**\r
136          * Gets the version.\r
137          *\r
138          * @return the version\r
139          */\r
140         public String getVersion() {\r
141                 return version;\r
142         }\r
143 \r
144         /**\r
145          * Checks if is volume group allowed.\r
146          *\r
147          * @return true, if is volume group allowed\r
148          */\r
149         public boolean isVolumeGroupAllowed() {\r
150                 return volumeGroupAllowed;\r
151         }\r
152         \r
153         /**\r
154          * Sets the uuid.\r
155          *\r
156          * @param uuid the new uuid\r
157          */\r
158         public void setUuid(String uuid) {\r
159                 this.uuid = uuid;\r
160         }\r
161 \r
162         /**\r
163          * Sets the invariant uuid.\r
164          *\r
165          * @param invariantUuid the new invariant uuid\r
166          */\r
167         public void setInvariantUuid(String invariantUuid) {\r
168                 this.invariantUuid = invariantUuid;\r
169         }\r
170         /**\r
171          * Sets the customization uuid.\r
172          *\r
173          * @param customizationUuid the new customization uuid\r
174          */\r
175         public void setCustomizationUuid(String customizationUuid) {\r
176                 this.customizationUuid = customizationUuid;\r
177         }\r
178         /**\r
179          * Sets the description.\r
180          *\r
181          * @param description the new description\r
182          */\r
183         public void setDescription(String description) {\r
184                 this.description = description;\r
185         }\r
186 \r
187         /**\r
188          * Sets the name.\r
189          *\r
190          * @param name the new name\r
191          */\r
192         public void setName(String name) {\r
193                 this.name = name;\r
194         }\r
195 \r
196         /**\r
197          * Sets the version.\r
198          *\r
199          * @param version the new version\r
200          */\r
201         public void setVersion(String version) {\r
202                 this.version = version;\r
203         }\r
204 \r
205         /**\r
206          * Sets the volume group allowed.\r
207          *\r
208          * @param volumeGroupAllowed the new volume group allowed\r
209          */\r
210         public void setVolumeGroupAllowed(boolean volumeGroupAllowed) {\r
211                 this.volumeGroupAllowed = volumeGroupAllowed;\r
212         }\r
213         /**\r
214          * Sets the commands.\r
215          *\r
216          * @param m the commands\r
217          */\r
218         public void setCommands( Map<String, CommandProperty>m ) {\r
219                 commands = m;\r
220         }\r
221         /**\r
222          * Sets the model customization name.\r
223          *\r
224          * @param modelCustomizationName the new model customization name\r
225          */\r
226         public void setModelCustomizationName(String modelCustomizationName) {\r
227                 this.modelCustomizationName = modelCustomizationName;\r
228         }\r
229         /**\r
230          * Extract vf module.\r
231          *\r
232          * @param group the group\r
233          * @return the vf module\r
234          */\r
235         public static  VfModule extractVfModule(String modelCustomizationName, Group group) {\r
236                 \r
237                 String methodName = "extractVfModule";\r
238 \r
239                 final VfModule vfModule = new VfModule();\r
240                 \r
241                 try {\r
242                         vfModule.setUuid(group.getMetadata().getVfModuleModelUUID());\r
243                         vfModule.setInvariantUuid(group.getMetadata().getVfModuleModelInvariantUUID());\r
244                         vfModule.setDescription(group.getMetadata().getDescription());\r
245                         vfModule.setName(group.getMetadata().getVfModuleModelName());\r
246                         vfModule.setVersion(group.getMetadata().getVfModuleModelVersion());\r
247                         vfModule.setCustomizationUuid(group.getMetadata().getVfModuleModelCustomizationUUID());\r
248                         vfModule.setModelCustomizationName (modelCustomizationName);\r
249                         \r
250                         if (group.getProperties().containsKey("volume_group")) {\r
251                                 if (group.getProperties().get("volume_group") != null) {\r
252                                 \r
253                                         Class<?> c = group.getProperties().get("volume_group").getClass();\r
254                                         LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " class name=" + \r
255                                                         c.getName());\r
256                                         \r
257                                         if ( c.getName().equalsIgnoreCase(Boolean.class.getName()) ) {\r
258                                                 Boolean b = (Boolean)group.getProperties().get("volume_group");\r
259                                                 vfModule.setVolumeGroupAllowed( b.booleanValue() );\r
260                                         }\r
261                                 }\r
262                         } else {\r
263                                 vfModule.setVolumeGroupAllowed(false);\r
264                         }\r
265                 }\r
266                 catch ( Exception e ) {\r
267                         LOG.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + " Unable to parse VF Module from group: e=" + \r
268                                         e.toString());\r
269                 }\r
270                 /* Not extracting other types of properties for 1702\r
271                  try {\r
272                         \r
273                         for (Entry<String, Object> e : group.getProperties().entrySet()) {\r
274                                 \r
275                                 String k = e.getKey();\r
276                                 if ( e.getValue() != null ) {\r
277                                         LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " property: " + \r
278                                                         k + "=" + e.getValue());\r
279                                         LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " V class name: " +\r
280                                                          e.getValue().getClass().getName());\r
281                                          Class<?>[] interfaces = e.getValue().getClass().getInterfaces();\r
282                                          \r
283                                          for(Class<?> ifc: interfaces ){\r
284                                                  LOG.debug(EELFLoggerDelegate.debugLogger, dateFormat.format(new Date()) + methodName + " ifc name: " +\r
285                                                                  ifc.getName());\r
286                                      }\r
287                                          \r
288                                         // only extract get_input for now\r
289                                         for (Entry<String, String> entry : v.entrySet()) {\r
290                                                 // only include get_input for now\r
291                                                 if ( ModelConstants.GET_INPUT_TAG.equalsIgnoreCase ( entry.getKey() ) ) {\r
292                                                         CommandProperty cp = new CommandProperty();\r
293                                                         cp.setDisplayName(entry.getValue());\r
294                                                         cp.setCommand(entry.getKey());\r
295                                                         cp.setInputName(k);\r
296                                                         (vfModule.getCommands()).put(k,cp);\r
297                                                 }\r
298                                         } \r
299                                 }\r
300                         }\r
301                 }\r
302                 catch ( Exception e ) {\r
303                         LOG.error(EELFLoggerDelegate.errorLogger, dateFormat.format(new Date()) + methodName + " Unable to parse VF Module properties: e=" + \r
304                                         e.toString());\r
305                 }*/\r
306                 return vfModule;\r
307         }\r
308 }\r